Fixing up model wrapping and tracking of metrics code, learning scheduler#707
Open
Fixing up model wrapping and tracking of metrics code, learning scheduler#707
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in model wrapping for distributed training in Hyrax. The issue stems from PyTorch Ignite's idist.auto_model() which wraps models for distributed execution, but the previous code was accessing optimizer, scheduler, and storing state on the wrapped model instead of the unwrapped model. This caused failures in GPU/distributed scenarios.
Changes:
- Introduced explicit
wrapped_modelandmodelvariables in all engine creation functions to distinguish between wrapped (for execution) and unwrapped (for state access) models - Changed optimizer and scheduler access from local variables to direct attribute access on the unwrapped model (
model.optimizer,model.scheduler) - Ensured all model state modifications (metrics, learning rate history) are performed on the unwrapped model
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #707 +/- ##
==========================================
- Coverage 64.17% 64.15% -0.02%
==========================================
Files 61 61
Lines 5892 5890 -2
==========================================
- Hits 3781 3779 -2
Misses 2111 2111 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…model actually end up on the wrapped model
4 tasks
Click here to view all benchmarks. |
drewoldag
approved these changes
Feb 19, 2026
Collaborator
drewoldag
left a comment
There was a problem hiding this comment.
This looks good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow-up on #706 which was a targeted fix for the bug reported in dirac slack: https://uw-dirac.slack.com/archives/C08F5FLEY5A/p1771350453909469
This is the more complete/thorough fix.
To avoid putting data/calling functions on the wrong model, the create_* methods now have two local variables "model" and "wrapped_model" In the case where there is no wrapping done by idist.auto_model() these are the same. I've tried to update the relevant accesses, but I want both @drewoldag and @SamSandwich07 to sign off before I merge.
I've also removed local variables of scheduler and optimizer in favor of model.scheduler and model.optimizer which are always on the inner model.
This has also exposed a larger issue that our CI doesn't have real GPUs, and we would have caught the original bug, and perhaps several other issues where we memoize data onto the model if we had CI with even an old and cheap GPU.