{"record":{"id":"98a021f8c61efabe","repo":"hiyouga/LlamaFactory","slug":"unable-to-process-key-key","errorCode":null,"errorMessage":"Unable to process key {key}","messagePattern":"Unable to process key (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"scripts/convert_ckpt/llamafy_qwen.py","lineNumber":83,"sourceCode":"            elif \"attn.c_proj\" in key:\n                llama_state_dict[key.replace(\"attn.c_proj\", \"self_attn.o_proj\")] = value\n                llama_state_dict[key.replace(\"attn.c_proj.weight\", \"self_attn.o_proj.bias\")] = torch.zeros_like(\n                    value[:, 0]\n                ).squeeze()\n            elif \"ln_1\" in key:\n                llama_state_dict[key.replace(\"ln_1\", \"input_layernorm\")] = value\n            elif \"ln_2\" in key:\n                llama_state_dict[key.replace(\"ln_2\", \"post_attention_layernorm\")] = value\n            elif \"mlp.w1\" in key:\n                llama_state_dict[key.replace(\"mlp.w1\", \"mlp.up_proj\")] = value\n            elif \"mlp.w2\" in key:\n                llama_state_dict[key.replace(\"mlp.w2\", \"mlp.gate_proj\")] = value\n            elif \"mlp.c_proj\" in key:\n                llama_state_dict[key.replace(\"mlp.c_proj\", \"mlp.down_proj\")] = value\n            elif \"lm_head\" in key:\n                llama_state_dict[key] = value\n            else:\n                raise KeyError(f\"Unable to process key {key}\")\n\n    weights_name = SAFE_WEIGHTS_NAME if save_safetensors else WEIGHTS_NAME\n    filename_pattern = weights_name.replace(\".bin\", \"{suffix}.bin\").replace(\".safetensors\", \"{suffix}.safetensors\")\n    state_dict_split = split_torch_state_dict_into_shards(\n        llama_state_dict, filename_pattern=filename_pattern, max_shard_size=shard_size\n    )\n    for shard_file, tensors in tqdm(state_dict_split.filename_to_tensors.items(), desc=\"Save weights\"):\n        shard = {tensor: llama_state_dict[tensor].contiguous() for tensor in tensors}\n        if save_safetensors:\n            save_file(shard, os.path.join(output_dir, shard_file), metadata={\"format\": \"pt\"})\n        else:\n            torch.save(shard, os.path.join(output_dir, shard_file))\n\n    if not state_dict_split.is_sharded:\n        print(f\"Model weights saved in {os.path.join(output_dir, weights_name)}.\")\n    else:\n        index = {\n            \"metadata\": state_dict_split.metadata,","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/scripts/convert_ckpt/llamafy_qwen.py#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nmodel_name_or_path: liuhaotian/llava-v1.5-7b\n\n# after\nmodel_name_or_path: llava-hf/llava-1.5-7b-hf","handlingStrategy":"validation","validationCode":"from transformers import AutoConfig\narch = getattr(AutoConfig.from_pretrained(model_path), 'architectures', []) or []\nassert 'LlavaLlamaForCausalLM' not in arch, 'Use llava-hf/* checkpoints (e.g. llava-hf/llava-1.5-7b-hf)'","typeGuard":"def is_hf_llava(model_name_or_path: str) -> bool:\n    cfg = AutoConfig.from_pretrained(model_name_or_path, trust_remote_code=False)\n    archs = getattr(cfg, 'architectures', None) or []\n    return 'LlavaLlamaForCausalLM' not in archs and any(a.startswith('Llava') for a in archs)","tryCatchPattern":"try:\n    run_sft(train_args)\nexcept ValueError as e:\n    if 'llava' in str(e):\n        raise SystemExit('Switch to llava-hf/... model id') from e\n    raise","preventionTips":["Always source LLaVA model ids from the llava-hf organization","Check architectures before adding models to training configs"],"tags":["model","llava","multimodal","checkpoint-format","config"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}