🐛 Fix multi-gpu error (AttributeError) for kongnet and nucleus_detector#1074
Open
gozdeg wants to merge 2 commits into
Open
🐛 Fix multi-gpu error (AttributeError) for kongnet and nucleus_detector#1074gozdeg wants to merge 2 commits into
kongnet and nucleus_detector#1074gozdeg wants to merge 2 commits into
Conversation
shaneahmed
reviewed
Jun 4, 2026
kongnet and nucleus_detector
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a multi-GPU crash in TIAToolbox nucleus detection paths by ensuring model attributes are read safely when the model is wrapped by nn.DataParallel / DistributedDataParallel.
Changes:
- Update
NucleusDetector.post_process_wsito readmin_distanceandtile_shapevia_get_model_attr()instead of directly fromself.model. - Update
KongNet.infer_batchto resolvetarget_channelswhenmodelis wrapped, avoidingAttributeErrorunder multi-GPU wrappers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tiatoolbox/models/engine/nucleus_detector.py |
Uses the existing unwrapping helper to access model attributes under DP/DDP. |
tiatoolbox/models/architecture/kongnet.py |
Adds wrapper-aware access to target_channels so inference works under DP/DDP. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1074 +/- ##
===========================================
- Coverage 99.88% 99.87% -0.02%
===========================================
Files 85 85
Lines 11626 11630 +4
Branches 1524 1524
===========================================
+ Hits 11613 11615 +2
- Misses 7 9 +2
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Follow-up to the earlier multi-GPU fix. kongnet and nucleus_detector were missed and still crash on multi-GPU machines with:
AttributeError: 'DataParallel' object has no attribute 'target_channels'
When multi-gpu, the model is wrapped in
nn.DataParallel/DistributedDataParallel, so these need to go through the_get_model_attr()wrapper helper function (or a similar approach) which unwraps the module before reading the attribute.Changes
nucleus_detector.py: readmin_distance/tile_shapevia the_get_model_attrhelper instead of directly offself.model.kongnet.py: unwrap the module before readingtarget_channelsininfer_batch. This can't reach the helper function, so it applies the same unwrap inline.engine_abc.py: simplify _get_model_attr to a single getattr-based unwrap and clarify its docstring.