[Fix] Make vision encoder DropPath initialization safe on meta devices - #1279
Open
cyyecao-lappland wants to merge 1 commit into
Open
cyyecao-lappland wants to merge 1 commit into
cyyecao-lappland wants to merge 1 commit into
Conversation
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
Related to #1254.
The DropPath schedule inherits the default device from
torch.linspace. Under a meta-device initialization context, extracting its Python scalar probabilities with.item()raisesRuntimeError: Tensor.item() cannot be called on meta tensors.internvl_chatandinternvl_chat_gpt_oss.Thanks to @Liu-524 for identifying the explicit-CPU workaround in this comment.
Validation
Tested on Linux with Python 3.12.8, PyTorch 2.10.0+cu128, Transformers 5.1.0, timm 1.0.30, Accelerate 1.15.0, pytest 9.1.1, and an NVIDIA RTX 4090.
The same regression suite produced:
Coverage includes CPU/meta parameter placement, one/four layers, zero/nonzero DropPath rates, exact schedule preservation, and small-config state-dict checkpoint round trips from meta initialization to CPU/CUDA with matching finite forward outputs on the same device.
git diff --checkpasses. Repository pre-commit checks on the changed files pass or have no applicable files, except flake8: both existing model files reportW604for docstring backticks at line 191. Running the same checks on the unmodified baseline reproduces those errors.Scope and known limitations
This is a focused initialization fix, not a claim of full Transformers 5.x compatibility.
A separate tiny-model
save_pretrained()/from_pretrained()probe moves past the original.item()failure after this patch, but still fails withAttributeError: 'InternVisionModel' object has no attribute 'all_tied_weights_keys'under Transformers 5.1.0. That loading issue and the separategenerate/GenerationMixin reports are outside this patch.No full pretrained InternVL checkpoint or end-to-end image/chat inference was tested. The passing checkpoint tests use PyTorch state-dict loading (
assign=True), not Hugging Facefrom_pretrained().