hiyouga/LlamaFactory · error · KeyError
Unable to process key {key}
Error message
Unable to process key {key} What it means
config patching rejects checkpoints whose architectures contain LlavaLlamaForCausalLM (patcher.py:410). That architecture name is the original liuhaotian/llava repository's custom class, which LlamaFactory cannot load; it requires the llava-hf conversions that use transformers' native LlavaForConditionalGeneration.
Source
Thrown at scripts/convert_ckpt/llamafy_qwen.py:83
elif "attn.c_proj" in key:
llama_state_dict[key.replace("attn.c_proj", "self_attn.o_proj")] = value
llama_state_dict[key.replace("attn.c_proj.weight", "self_attn.o_proj.bias")] = torch.zeros_like(
value[:, 0]
).squeeze()
elif "ln_1" in key:
llama_state_dict[key.replace("ln_1", "input_layernorm")] = value
elif "ln_2" in key:
llama_state_dict[key.replace("ln_2", "post_attention_layernorm")] = value
elif "mlp.w1" in key:
llama_state_dict[key.replace("mlp.w1", "mlp.up_proj")] = value
elif "mlp.w2" in key:
llama_state_dict[key.replace("mlp.w2", "mlp.gate_proj")] = value
elif "mlp.c_proj" in key:
llama_state_dict[key.replace("mlp.c_proj", "mlp.down_proj")] = value
elif "lm_head" in key:
llama_state_dict[key] = value
else:
raise KeyError(f"Unable to process key {key}")
weights_name = SAFE_WEIGHTS_NAME if save_safetensors else WEIGHTS_NAME
filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
state_dict_split = split_torch_state_dict_into_shards(
llama_state_dict, filename_pattern=filename_pattern, max_shard_size=shard_size
)
for shard_file, tensors in tqdm(state_dict_split.filename_to_tensors.items(), desc="Save weights"):
shard = {tensor: llama_state_dict[tensor].contiguous() for tensor in tensors}
if save_safetensors:
save_file(shard, os.path.join(output_dir, shard_file), metadata={"format": "pt"})
else:
torch.save(shard, os.path.join(output_dir, shard_file))
if not state_dict_split.is_sharded:
print(f"Model weights saved in {os.path.join(output_dir, weights_name)}.")
else:
index = {
"metadata": state_dict_split.metadata,View on GitHub (pinned to f28afaf635)
Solutions
- Switch model_name_or_path to the llava-hf equivalent, e.g. llava-hf/llava-1.5-7b-hf
- Re-publish/convert legacy checkpoints with the llava-hf conversion scripts if the weights are custom
Example fix
# before model_name_or_path: liuhaotian/llava-v1.5-7b # after model_name_or_path: llava-hf/llava-1.5-7b-hf
Defensive patterns
Strategy: validation
Validate before calling
from transformers import AutoConfig arch = getattr(AutoConfig.from_pretrained(model_path), 'architectures', []) or [] assert 'LlavaLlamaForCausalLM' not in arch, 'Use llava-hf/* checkpoints (e.g. llava-hf/llava-1.5-7b-hf)'
Type guard
def is_hf_llava(model_name_or_path: str) -> bool:
cfg = AutoConfig.from_pretrained(model_name_or_path, trust_remote_code=False)
archs = getattr(cfg, 'architectures', None) or []
return 'LlavaLlamaForCausalLM' not in archs and any(a.startswith('Llava') for a in archs) Try / catch
try:
run_sft(train_args)
except ValueError as e:
if 'llava' in str(e):
raise SystemExit('Switch to llava-hf/... model id') from e
raise Prevention
- Always source LLaVA model ids from the llava-hf organization
- Check architectures before adding models to training configs
When it happens
Trigger: model_name_or_path points at liuhaotian/llava-v1.5-7b (or a finetune derived from it); AutoConfig reports LlavaLlamaForCausalLM in architectures and the loader raises ValueError immediately.
Common situations: Copying a model id from the original LLaVA paper/repo instead of the llava-hf org; using community merges or LoRA bases published in the legacy format.
Related errors
- Please upgrade `transformers` to 4.34.0
- Invalid length
- Template is required for MultiModalDataCollator.
- This model does not support image input. Please check whethe
- This model does not support video input. Please check whethe
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/98a021f8c61efabe.
Report an issue: GitHub.