Fix AttributeError: 'DataParallel' object has no attribute 'scheduler'#705
Closed
Fix AttributeError: 'DataParallel' object has no attribute 'scheduler'#705
Conversation
…allel scheduler - Use scheduler local variable instead of model.scheduler in scheduler_step handler - Add unwrapped_model variable for _learning_rates_history attribute access - Add test_scheduler_with_data_parallel to validate fix works with DataParallel wrapper Fixes issue where model.scheduler is accessed on DataParallel/DistributedDataParallel wrappers which don't forward custom attributes, causing AttributeError during training.
Copilot
AI
changed the title
[WIP] Fix AttributeError in scheduler step for DataParallel model
Fix AttributeError: 'DataParallel' object has no attribute 'scheduler'
Feb 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an AttributeError crash during training when models are wrapped in DataParallel or DistributedDataParallel by the distributed training infrastructure. The bug was introduced in PR #652 when learning rate scheduler support was added.
Changes:
- Fixed scheduler access in
scheduler_stephandler to use pre-extracted scheduler variable instead of accessing it through the DataParallel wrapper - Added unwrapped model reference to properly access
_learning_rates_historyattribute - Added comprehensive test to validate the fix works with DataParallel-wrapped models
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/hyrax/pytorch_ignite.py | Extracts unwrapped_model reference and uses it along with the pre-extracted scheduler variable in the scheduler_step handler to avoid AttributeError when model is wrapped by DataParallel/DistributedDataParallel |
| tests/hyrax/test_train.py | Adds test_scheduler_with_data_parallel that mocks idist.auto_model to wrap the model in DataParallel and validates scheduler functionality works correctly |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #705 +/- ##
=======================================
Coverage 64.17% 64.17%
=======================================
Files 61 61
Lines 5892 5893 +1
=======================================
+ Hits 3781 3782 +1
Misses 2111 2111 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
Click here to view all benchmarks. |
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.
Change Description
Training crashes with
AttributeError: 'DataParallel' object has no attribute 'scheduler'whenidist.auto_model()wraps the model inDataParallelorDistributedDataParallel.Solution Description
Root cause: The
scheduler_stephandler accessesmodel.schedulerdirectly on the wrapper. PyTorch wrappers don't forward custom attributes.Fix: Use already-extracted local variables that properly unwrap the model via
extract_model_method():Changes:
src/hyrax/pytorch_ignite.py: Extractunwrapped_modeland use it for_learning_rates_historyattribute access (lines 660-663, 735-745)tests/hyrax/test_train.py: Addtest_scheduler_with_data_parallelthat mocks wrapper to validate fixScope: Other similar patterns (
model.final_training_metrics,model.log_epoch_metrics()) remain for follow-up.Code Quality
Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.