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 pytorch recorder adapt_linear when using autodiff backend #1576

Merged
merged 2 commits into from Apr 4, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Apr 4, 2024

Stumbled upon this issue when trying to load a record with PyTorchFileRecorder for a model using the autodiff backend.

Checklist

  • Confirmed that run-checks all script has been executed.

Changes

The line below would panic with Can't convert a non leaf tensor into a tracked tensor when using the autodiff backend.

Param::from_tensor(weight.val().transpose());

That's simply because the parameter is being created from a tensor that is being transposed, an operation that is tracked by autodiff.

Solution: set require grad to false when creating the parameter from the tensor transpose.

Testing

Added autodiff unit test for complex model that includes a linear layer.

@laggui laggui requested a review from antimora April 4, 2024 15:35
Copy link

codecov bot commented Apr 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.33%. Comparing base (6522276) to head (79ab0ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1576   +/-   ##
=======================================
  Coverage   86.32%   86.33%           
=======================================
  Files         686      686           
  Lines       78440    78451   +11     
=======================================
+ Hits        67714    67728   +14     
+ Misses      10726    10723    -3     

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

Copy link
Collaborator

@antimora antimora left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for catching it and fixing it.

@laggui laggui merged commit ce898ff into main Apr 4, 2024
15 checks passed
@laggui laggui deleted the fix/pytorch-recorder/linear-autodiff branch April 4, 2024 16:29
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.

None yet

2 participants