You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mistral-7B微调后加载报KeyError,请求技术排查

问题

使用Axolotl项目的pet.py对mistralai/Mistral-7B-v0.1进行QLoRA微调,微调过程正常;此前相同配置可正常运行,但现在加载微调后的模型时,持续出现错误:KeyError: 'base_model.model.model.layers.0.mlp.down_proj.lora_A.weight'。以下是微调配置:

base_model: mistralai/Mistral-7B-v0.1
model_type: MistralForCausalLM
tokenizer_type: LlamaTokenizer
is_mistral_derived_model: true
hub_model_id: DevSelego/Mistral7b_summarizer_v5

load_in_8bit: false
load_in_4bit: true
strict: false
datasets:
  - path: DevSelego/jobmaker_summarize_v5
    type: alpaca
dataset_prepared_path: last_run_prepared
val_set_size: 0.05
output_dir: ./qlora-out

adapter: qlora
lora_model_dir:

sequence_len: 8192
sample_packing: false
pad_to_sequence_len: true

lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:
lora_target_modules:
  - gate_proj
  - down_proj
  - up_proj
  - q_proj
  - v_proj
  - k_proj
  - o_proj

wandb_project: Mistral_Jobmaker
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:

gradient_accumulation_steps: 1
micro_batch_size: 10
num_epochs: 1
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 0.0002

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false
tf32: false

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true

loss_watchdog_threshold: 5.0
loss_watchdog_patience: 3

warmup_steps: 10
eval_steps: 0.05
eval_table_size:
eval_table_max_new_tokens: 128
save_steps:
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
  bos_token: "<s>"
  eos_token: "</s>"
  unk_token: "<unk>"
排查思路与解决方法
  • 检查LoRA权重路径与完整性:确认加载模型时指定的路径是配置里的./qlora-out,且该目录下存在完整的LoRA文件(adapter_config.json、adapter_model.bin等)。如果路径错误或文件缺失/损坏,会直接导致权重键找不到。
  • 对齐模型加载模式:微调时启用了4bit加载(load_in_4bit: true),加载微调模型时必须保持一致的模式,不能用全精度方式加载base模型再挂载LoRA,否则权重命名空间会不匹配。
  • 验证Axolotl版本一致性:如果近期更新过Axolotl,可能是版本迭代导致LoRA权重命名规则变化。可以回退到之前能正常运行的版本,或者用当前版本重新微调一次后再加载。
  • 确保LoRA目标模块一致:加载模型时指定的LoRA目标模块要和微调配置里的lora_target_modules完全一致,不能少写或错写模块(比如down_proj必须包含在内),否则会找不到对应模块的LoRA权重。
  • 排查中断导致的权重异常:如果微调过程中曾意外中断,可能导致adapter_model.bin文件不完整。重新完整运行一次微调流程,确保权重正常保存后再尝试加载。

内容的提问来源于stack exchange,提问作者Ilona Bienfaisance

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 03:37:10