Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the execution phase and stage recording issue and replace compare_with_golden with verify function #1358

Merged

Conversation

chandrasekaranpradeep
Copy link
Contributor

@chandrasekaranpradeep chandrasekaranpradeep commented Mar 4, 2025

Problem Description

The execution phase and stage are recorded incorrectly whenever test cases contain post-processing code that reruns the compiled model.

Example:

Test Cases Execution Phase Execution Stage
forge/test/models/pytorch/vision/resnet/test_resnet.py::test_resnet_hf[microsoft/resnet-50] EXECUTED_TTNN EXECUTED_TTNN
forge/test/models/pytorch/vision/resnet/test_resnet.py::test_resnet_timm PASSED VERIFICATION

In the table above, both test cases passed verification, but the execution phase and stage for the forge/test/models/pytorch/vision/resnet/test_resnet.py::test_resnet_hf[microsoft/resnet-50] test case are incorrect. The execution phase should be PASSED, and the execution stage should be VERIFICATION.

This occurs because the test case contains a post-processing function (run_and_print_results) that reruns the compiled model, which updates the execution phase from PASSED to EXECUTED_TTNN and the execution stage from VERIFICATION to EXECUTED_TTNN.

On the other hand, another ResNet test case, forge/test/models/pytorch/vision/resnet/test_resnet.py::test_resnet_timm, does not contain post-processing, so the execution phase and stage remain unchanged.

Issue Origin

Execution depth (EXECUTED_TTNN) is recorded inside the CompiledModel class in forge/forge/compiled_graph_state.py, specifically in the call method, at this line.

Whenever the compiled model is rerun, it updates the execution depth again.

Reason for Current Implementation

Some test cases still use the compare_with_golden function for verification instead of verify. Test cases using compare_with_golden may run the compiled model anywhere inside the test function. To ensure execution depth tracking, EXECUTED_TTNN was recorded inside the call method of the CompiledModel class.

Proposed Fix

To prevent incorrect updates of execution phase and stage due to post-processing:

  1. Record execution depth (EXECUTED_TTNN) inside the verify function rather than inside the call method in the CompiledModel class.
  2. Replace compare_with_golden with verify in test cases.

Benefits of This Change

  1. Prevents Depth Changes During Post-Processing

    • Currently, execution depth can change from PASSED → EXECUTED_TTNN if post-processing code calls the compiled model.
    • By recording EXECUTED_TTNN within verify, execution depth remains correct.
  2. Ensures Proper Depth Handling Across Loops (e.g., Epochs)

    • If compare_with_golden is replaced with verify in forge/test/mlir/mnist/training/test_training.py, consider this scenario:
      • Epoch 1: Verification passes, setting execution depth to PASSED.
      • Epoch 2: Data mismatch occurs. By recording EXECUTED_TTNN inside verify, execution depth is tracked correctly per epoch, allowing proper rollback if mismatches occur later.

Note:

@vkovinicTT replaced the compare_with_golden with verify function for the forge/test/mlir/mnist/training/test_training.py in this PR. So I haven't replaced it for forge/test/mlir/mnist/training/test_training.py file

Llama Decode with cache:

The to_pt_tensors function was modified to accept the List/tuple of tensor in this commit but in the llama decode with cache test will pass the List[input_ids, attention_mask, postion_ids, past_key_values] as input, here the past_key_values is list of tuple of tensor, so modified the llama decode with cache test to accept as list of tensor and update the llama decode implementation to process past key values as list of tensor, not as list of tuple of tensors.

Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests624 ran483 passed141 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests683 ran538 passed145 skipped0 failed
TestResult
No test annotations available

1 similar comment
Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests683 ran538 passed145 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests624 ran483 passed141 skipped0 failed
TestResult
No test annotations available

@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 9a885b6 to 86c3e5b Compare March 4, 2025 12:48
Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests624 ran483 passed141 skipped0 failed
TestResult
No test annotations available

1 similar comment
Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests624 ran483 passed141 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests683 ran538 passed145 skipped0 failed
TestResult
No test annotations available

1 similar comment
Copy link

github-actions bot commented Mar 4, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests683 ran538 passed145 skipped0 failed
TestResult
No test annotations available

@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 86c3e5b to fda39e1 Compare March 6, 2025 07:14
@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.40%. Comparing base (754b717) to head (d2b1f0d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1358   +/-   ##
=======================================
  Coverage   43.40%   43.40%           
=======================================
  Files          48       48           
  Lines        7860     7860           
=======================================
  Hits         3412     3412           
  Misses       4448     4448           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests684 ran541 passed143 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests626 ran483 passed143 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests684 ran541 passed143 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests626 ran483 passed143 skipped0 failed
TestResult
No test annotations available

@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from fda39e1 to 6288878 Compare March 6, 2025 15:26
@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 6288878 to e771e4a Compare March 6, 2025 15:32
Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests634 ran489 passed145 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests693 ran553 passed140 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests634 ran489 passed145 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests693 ran553 passed140 skipped0 failed
TestResult
No test annotations available

@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from e771e4a to 1a23cc9 Compare March 7, 2025 12:35
Copy link
Contributor

@ashokkumarkannan1 ashokkumarkannan1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!

@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 1a23cc9 to 898dd24 Compare March 7, 2025 12:46
@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 898dd24 to 6ae6015 Compare March 7, 2025 13:26
@chandrasekaranpradeep chandrasekaranpradeep force-pushed the pchandrasekaran/fix_execution_depth_recording branch from 6ae6015 to d2b1f0d Compare March 7, 2025 13:34
Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ❌️SkippedFailed
TT-Forge-FE Tests0 ran0 passed0 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests634 ran490 passed144 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests693 ran554 passed139 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ☑️Skipped ⚠️Failed ❌️
TT-Forge-FE Tests693 ran552 passed139 skipped2 failed
TestResult
TT-Forge-FE Tests
pytest
test_mobilenet_v2.test_mobilenetv2_basic❌ failure
test_resnext.test_resnext_101_torchhub_pytorch[resnext101_32x8d]❌ failure

Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests634 ran490 passed144 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 7, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests693 ran554 passed139 skipped0 failed
TestResult
No test annotations available

@chandrasekaranpradeep chandrasekaranpradeep merged commit c80672e into main Mar 7, 2025
11 checks passed
@chandrasekaranpradeep chandrasekaranpradeep deleted the pchandrasekaran/fix_execution_depth_recording branch March 7, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants