fix: DINOv3 layer path and hardcoded .cuda() device hardening - #178
Open
adwaitm1301 wants to merge 1 commit into
Open
fix: DINOv3 layer path and hardcoded .cuda() device hardening#178adwaitm1301 wants to merge 1 commit into
adwaitm1301 wants to merge 1 commit into
Conversation
Three interconnected bugs fixed across 5 files.
1. DINOv3 layer path (modules + trainers image_feature_extractor)
- self.model.layer -> fallback chain to support all transformers versions
- The trainers copy was missed by every existing DINOv3 PR
2. Hardcoded .cuda() calls in both image_feature_extractor files
- Replaced .cuda() with .to(self.device) for CPU and multi-GPU support
- Added device property to both extractor classes
3. Device type consistency + renderer hardening
- _device = 'cpu' -> torch.device('cpu') in both pipeline files
- latlong_to_cubemap: device='cuda' -> latlong_map.device
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.
Three fixes dug up from reading issue #161 and cross-referencing against existing PRs.
1. DINOv3 layer path (both copies) — Closes #161
The extract_features method hardcodes self.model.layer, but DINOv3ViTModel from HuggingFace transformers moved the encoder to self.model.model.layer (v5.0+) and later to self.model.encoder.layer (v5.8+). The fix uses a fallback chain that tries all three paths and raises a clear AttributeError if none match.
Two copies of this code exist — modules/image_feature_extractor.py AND rainers/.../image_conditioned.py. All existing PRs (#144, #148, #156) only fixed the modules copy. This PR fixes both.
2. Hardcoded .cuda() calls (both copies)
Every orch.stack(image).cuda() and self.transform(image).cuda() was hardcoded to CUDA, meaning the feature extractor crashes on CPU or multi-GPU setups. Now uses .to(self.device) with a device property added to both DinoV2FeatureExtractor and DinoV3FeatureExtractor.
Also removed the unconditional .cuda() call in ImageConditionedMixin._init_image_cond_model(), which destroyed device placement for the training code path.
3. Device type consistency + renderer hardening