Implementation:Haotian liu LLaVA Apply Delta
| Knowledge Sources | |
|---|---|
| Domains | Model_Distribution, Weight_Management, Vision_Language |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete tool for reconstructing a full LLaVA model by applying a weight delta to a base LLaMA model, enabling compact distribution of model weights as diffs.
Description
The apply_delta function loads a base LLaMA model and a delta checkpoint (stored as a LlavaLlamaForCausalLM), then adds the base weights back to the delta weights parameter-by-parameter. For parameters present in both models with matching shapes, it performs element-wise addition. For dimension mismatches in embed_tokens.weight and lm_head.weight (caused by vocabulary expansion), it adds only the overlapping portion. Parameters unique to the delta (mm_projector.weight/bias) are preserved as-is. The reconstructed model and tokenizer are saved to a target path. This is the inverse operation of make_delta.
Usage
Use this tool when you have a base LLaMA model and a LLaVA delta checkpoint and need to reconstruct the full LLaVA model. This was the standard method for obtaining early LLaVA model weights, where the full model could not be redistributed due to LLaMA license restrictions.
Code Reference
Source Location
- Repository: Haotian_liu_LLaVA
- File: llava/model/apply_delta.py
- Lines: 1-48
Signature
def apply_delta(base_model_path: str, target_model_path: str, delta_path: str) -> None:
"""
Reconstruct a full LLaVA model by adding base model weights to a delta checkpoint.
Args:
base_model_path: Path to the base LLaMA model weights.
target_model_path: Path where the reconstructed full model will be saved.
delta_path: Path to the LLaVA delta checkpoint.
"""
Import
from llava.model.apply_delta import apply_delta
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| base_model_path | str | Yes | Filesystem path to the base LLaMA model (e.g., llama-7b) |
| target_model_path | str | Yes | Filesystem path where the reconstructed model will be saved |
| delta_path | str | Yes | Filesystem path or HuggingFace repo ID for the LLaVA delta weights |
Outputs
| Name | Type | Description |
|---|---|---|
| Saved model | Files | Full LLaVA model saved to target_model_path (model weights + config) |
| Saved tokenizer | Files | Tokenizer files saved to target_model_path |
Usage Examples
CLI Usage
# Reconstruct LLaVA-7B from base LLaMA-7B and delta
python3 -m llava.model.apply_delta \
--base-model-path ~/model_weights/llama-7b \
--target-model-path ~/model_weights/llava-7b \
--delta-path liuhaotian/llava-7b-delta
Programmatic Usage
from llava.model.apply_delta import apply_delta
# Reconstruct the full LLaVA model
apply_delta(
base_model_path="/path/to/llama-7b",
target_model_path="/path/to/output/llava-7b",
delta_path="liuhaotian/llava-7b-delta"
)