[Bugfix] Fix InternVL/InternVL3 LoRA loading TypeError in adapter fallback#4684
Open
waynehacking8 wants to merge 1 commit into
Open
[Bugfix] Fix InternVL/InternVL3 LoRA loading TypeError in adapter fallback#4684waynehacking8 wants to merge 1 commit into
waynehacking8 wants to merge 1 commit into
Conversation
…lback InternVLChatModel.load_lora_weights and InternVLForConditionalGeneration.load_lora_weights fall back to the standalone load_lora_weights(model, weights, adapter_id) when the inner language model has no load_lora_weights, but called it with only (weights, adapter_id) -> "TypeError: load_lora_weights() missing 1 required positional argument: 'adapter_id'", blocking every InternVL3/InternVL LoRA adapter load. Additionally, InternVLForConditionalGeneration gated the call on hasattr(self.model.language_model, ...), but the constructor stores self.language_model (there is no self.model). hasattr swallowed the AttributeError, so the broken fallback fired unconditionally. Pass the top-level model (self) to the standalone loader, matching the canonical caller in internlm2.py -- its named_parameters() carry the "language_model." prefix the loader maps against -- and use self.language_model for the hasattr/delegate path. Fixes InternLM#4105 Co-authored-by: Claude <noreply@anthropic.com>
05a32d2 to
a628ebe
Compare
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
Fixes #4105. Serving
OpenGVLab/InternVL3-14B(or any InternVL) with a LoRA adapter on the PyTorch backend crashes with:Root cause
Both
InternVLChatModel.load_lora_weights(internvl.py) andInternVLForConditionalGeneration.load_lora_weights(internvl3_hf.py) fall back to the standalonelmdeploy.pytorch.adapter.adapter.load_lora_weightswhen the inner language model does not defineload_lora_weights. Its signature is:but both call it as
load_lora_weights(weights, adapter_id)—weightsbinds tomodel,adapter_idbinds toweights, andadapter_idis unbound →TypeError.internvl3_hf.pyhas a second bug that makes the broken branch fire unconditionally: it gates onhasattr(self.model.language_model, 'load_lora_weights'), but the constructor storesself.language_model(there is noself.model).hasattrswallows theAttributeErrorand always takes theelsebranch.Fix
Pass the top-level model (
self) to the standalone loader, and useself.language_modelfor thehasattr/delegate path ininternvl3_hf.py.selfis correct because the loader doesdict(model.named_parameters())and maps de-prefixed adapter keys likelanguage_model.model.layers.0.mlp.down_proj.lora_adapters.down_proj.lora_A— i.e. names that start withlanguage_model.. Only the top-level VLM (which haslanguage_modelas a child) produces that namespace. This mirrors the canonical callerinternlm2.py:Relation to #4106
The earlier (closed) #4106 passed
self.language_model(internvl.py) /self.model.language_model(internvl3_hf.py).self.language_model.named_parameters()yieldsmodel.layers...(nolanguage_model.prefix), so the loader'sparams_dict[param_name]lookup misses — which is theKeyError/param-name mismatch the reporter hit after trying #4106. Passingselfgives the loader the namespace it actually maps against, and also fixes the non-existentself.modelreference.Test
Added
tests/pytorch/test_internvl_lora.py(GPU-free; mocks the standalone loader):3 passed— both classes pass(model, weights, adapter_id)to the loader, andinternvl3_hfdelegates correctly when the language model implementsload_lora_weights.3 failed(loader called with the wrong(weights, adapter_id)arity; delegation never happens).ruff checkclean on all three files.Honesty / scope
The
TypeErrorandself.modelbugs are verified by code analysis + the GPU-free unit tests above. I do not have theInternVL3-14B+ LoRA serving setup to run the full end-to-end here; the parameter-namespace analysis indicates passingselfalso resolves the downstreamKeyErrorfrom #4106, but an e2e confirmation by someone with that model/adapter would be welcome. cc @windreamer (you triaged the original issue).AI-assisted (Claude); every line human-reviewed.