Support loading original InternVL2 checkpoints natively#47047
Open
malakazlan wants to merge 1 commit into
Open
Support loading original InternVL2 checkpoints natively#47047malakazlan wants to merge 1 commit into
malakazlan wants to merge 1 commit into
Conversation
The original OpenGVLab/InternVL2-* checkpoints ship the bespoke internvl_chat remote-code layout, which is incompatible with Transformers v5 meta-device initialization (the custom code calls .item() during construction). Load them into the native InternVLForConditionalGeneration without trust_remote_code: - Register the internvl_chat model_type as an alias of the native InternVLConfig (mirrors the existing gpt-sw3 -> GPT2Config alias), so AutoConfig/AutoModel resolve the local implementation when trust_remote_code is not passed. - Normalize the original internvl_chat config (llm_config / intern_vit_6b vision_config / select_layer) onto InternVLConfig in from_dict. - Add a load-time weight conversion that renames the original weight layout onto the native names and splits the fused vision attn.qkv into q/k/v via Chunk. Verified on OpenGVLab/InternVL2-1B: loads with no missing/unexpected/mismatched weights and each converted tensor is bit-exact against the original checkpoint. Relates to vllm-project/vllm#38425. InternVL2-2B (InternLM2 wqkv split) to follow. Signed-off-by: malakazlan <azlanmalikai@gmail.com>
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, internvl |
Contributor
CI recapDashboard: View test results in Grafana |
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.
What does this PR do?
The original
OpenGVLab/InternVL2-*checkpoints ship the bespokeinternvl_chatremote-code layout. Under Transformers v5 (meta-device init), that custom code
calls
.item()during construction and crashes, so the checkpoints can no longerbe loaded via
AutoModel.from_pretrained(..., trust_remote_code=True). This is theblocker tracked in vllm-project/vllm#38425.
This PR makes the original checkpoints load into the native
InternVLForConditionalGeneration, without remote code:internvl_chatmodel_typeas an alias of thenative
InternVLConfig(mirrors the existinggpt-sw3→GPT2Configalias), soAutoConfig/AutoModelresolve the local implementation whentrust_remote_codeis not passed (per @hmellor's guidance in the linked issue).
internvl_chatconfig(
llm_config/intern_vit_6bvision_config/select_layer) ontoInternVLConfiginfrom_dict.native names and split the fused vision
attn.qkvintoq/k/vviaChunk,reusing the mapping already established in
convert_internvl_weights_to_hf.py.Test plan
Built Transformers from source (v5) and verified on
OpenGVLab/InternVL2-1B:AutoConfig.from_pretrained(..., trust_remote_code=False)returns a nativeInternVLConfig(Qwen2 text + InternVL vision sub-configs).from_pretrainedloads with no missing / unexpected / mismatched weights.q/k/v) is bit-exact vs. the original.Added
tests/models/internvl/test_modeling_internvl.py::InternVLOriginalCheckpointTest(passes, CPU-only).
Notes
wqkvsplit) is a planned follow-up.internvl_chat…internvl” infowarning; happy to silence it for this alias if preferred.
cc @hmellor
Before submitting