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

Add verify_backward to enable testing bacward ops #1383

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ndrakulicTT
Copy link
Contributor

Ticket

Fixes #1356

Problem description

There was no way to in one place verify gradients from backward pass

What's changed

Added verify_backward:

  • check input parameters
  • runs backward on compile model
  • saves gradients from compiled model
  • runs bacward on framework model
  • saves gradients from framework model
  • Checks the gradients

Checklist

  • New/Existing tests provide coverage for changes

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@184b44a). Learn more about missing BASE report.

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

☔ 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 Tests642 ran499 passed143 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests701 ran563 passed138 skipped0 failed
TestResult
No test annotations available

Copy link

github-actions bot commented Mar 6, 2025

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

Copy link

github-actions bot commented Mar 6, 2025

TestsPassed ✅Skipped ⚠️Failed
TT-Forge-FE Tests701 ran563 passed138 skipped0 failed
TestResult
No test annotations available

Comment on lines +332 to +333
if not isinstance(framework_model, torch.nn.Module):
raise TypeError(f"Framework model must be of type {torch.nn.Module}, but got {type(framework_model)}")
Copy link
Member

Choose a reason for hiding this comment

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

So for now we just support backward verification for torch?

compiled_output: torch.Tensor,
framework_model: torch.nn.Module,
compiled_model: CompiledModel,
original_model: torch.nn.Module = None,
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need original_model?

Comment on lines +387 to +388
fw = _squeeze_tensor(fw)
co = _squeeze_tensor(co)
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use regular squeeze instead?

VerifyConfig,
VerifyTensorMetadata,
should_waive_gradient,
AutomaticValueChecker,
Copy link
Member

Choose a reason for hiding this comment

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

Please just remove import AutomaticValueChecker if we don't use it here?

Comment on lines +172 to +176
# NOTE: We probably need two framework models with the same state_dict to compare the outputs
# But for now it works without that for some reason?
# model_for_compile = Matmul()
# model_for_compile.eval() if not training else model_for_compile.train()
# model_for_compile.load_state_dict(framework_model.state_dict())
Copy link
Member

Choose a reason for hiding this comment

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

Discussed offline, we probably don't need 2 framework models.

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.

Add verification for backward pass into verify function
3 participants