Fix DINOv3 layer access for transformers >= 5.0#156
Open
Eyalm321 wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix DINOv3 layer access for transformers >= 5.0#156Eyalm321 wants to merge 1 commit intomicrosoft:mainfrom
Eyalm321 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
In recent transformers releases, `DINOv3ViTModel` no longer exposes the
encoder layer ModuleList directly on the top-level model. The encoder is
wrapped under `.model`, so the layers now live at
`self.model.model.layer` (the inner `model` is `DINOv3ViTEncoder`).
Older transformers versions exposed `self.model.layer` directly. Probe
for both via `getattr(self.model, "model", self.model)` so the change is
backward compatible.
Repro before the fix (transformers 5.6.2 on PyPI):
AttributeError: 'DINOv3ViTModel' object has no attribute 'layer'
raised at trellis2/modules/image_feature_extractor.py:86 during
`Trellis2ImageTo3DPipeline.run()` when extracting DINOv3 features from
the input image.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
DINOv3ViTModelwraps its encoder under.model, so the layerModuleListlives atself.model.model.layer(the innermodelisDINOv3ViTEncoder). Older transformers exposed.layerdirectly on the top-level model.extract_featuresintrellis2/modules/image_feature_extractor.pyonly handled the old layout, breaking inference on a fresh install with a current transformers release.getattr(self.model, "model", self.model)so the path works on both old and new transformers.Repro
On a fresh
setup.sh --basic --flash-attn --nvdiffrast --nvdiffrec --cumesh --o-voxelinstall (transformers 5.6.2 from PyPI), runningTrellis2ImageTo3DPipeline.run(image)raises:The fix unblocks inference on the latest pinned transformers without affecting older versions.
Verified
Inference end-to-end on RTX A6000 + transformers 5.6.2 + torch 2.5.1+cu124 produced a valid GLB (504K verts / 945K faces) from a single 1024×1024 PNG input.
Test plan
self.model.layeralready exists (getattrreturns the same model object, behavior unchanged)🤖 Generated with Claude Code