Fix: inject LoRA adapters before loading LoRA weights in from_pretrained#28
Open
MarkovChain-why wants to merge 1 commit intodreamzero0:mainfrom
Open
Conversation
When `defer_lora_injection=True`, LoRA adapters are not created during model init — they are deferred until after base weights are loaded so that the pretrained weight key paths match the model's state dict. However, `VLA.from_pretrained` (the inference/deployment path) skips adapter injection when `lora_weights_path` is provided: it jumps straight to `load_lora_weight()` without first calling `inject_lora_after_loading()`. This means the LoRA weight keys (lora_A, lora_B) have no matching parameters in the model, so the loaded weights are silently dropped. The training path in `base.py` does not have this bug — it correctly calls `inject_lora_after_loading()` after loading pretrained weights (line 723-726). Fix: call `inject_lora_after_loading()` before `load_lora_weight()` when a LoRA weights path is provided. Co-Authored-By: Claude Opus 4.6 <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
defer_lora_injection=True,VLA.from_pretrained()(inference path) callsload_lora_weight()without first injecting LoRA adapters. The LoRA weight keys (lora_A,lora_B) have no matching parameters, so loaded weights are silently dropped.elsebranch correctly callsinject_lora_after_loading(), but theif lora_weights_path is not Nonebranch does not.inject_lora_after_loading()beforeload_lora_weight()when a LoRA weights path is provided.Note: The training path in
base.py(create_model) is not affected — it already callsinject_lora_after_loading()unconditionally after loading pretrained weights.Affected code
groot/vla/model/dreamzero/base_vla.py,VLA.from_pretrained()method.Before (buggy):
```python
if lora_weights_path is not None:
model.load_lora_weight(lora_weights_path) # LoRA adapters don't exist yet!
else:
if ... defer_lora_injection:
model.action_head.inject_lora_after_loading()
```
After (fixed):
```python
if lora_weights_path is not None:
if hasattr(model.action_head, 'inject_lora_after_loading'):
model.action_head.inject_lora_after_loading() # Create adapters first
model.load_lora_weight(lora_weights_path) # Then load weights
else:
if ... defer_lora_injection:
model.action_head.inject_lora_after_loading()
```
Test plan
defer_lora_injection=TrueviaVLA.from_pretrained()and verify LoRA weights are correctly applied