{
  "schema_version": "1.0",
  "id": "T-16c27df7e242",
  "url": "https://gpuatlas.top/articles/T-16c27df7e242/",
  "title": "LLaMA-Factory 一开始训练就 OOM，应该按什么顺序调参数？",
  "summary": "LLaMA-Factory启动训练OOM先定位加载、前向、反向或更新，再按权重、激活和状态逐项调整。",
  "language": "zh-Hans",
  "category": {
    "id": "c-09",
    "name": "框架配置与故障",
    "url": "https://gpuatlas.top/categories/c-09/"
  },
  "topics": [
    {
      "id": "task-796e01d5af",
      "name": "训练",
      "kind": "task",
      "description": "模型训练时的资源占用与推理不同。查看优化器、激活值、并行策略和中断恢复相关问题。",
      "url": "https://gpuatlas.top/topics/task-796e01d5af/"
    }
  ],
  "body_text": "LLaMA-Factory一开始训练就OOM，先定位发生在加载、前向、反向还是优化器更新。不同阶段需要不同调整，照一张省显存参数表全部打开，会丢掉原因也可能改变训练目标。\n\n先核对精确模型、量化精度、可训练参数和目标模块，以及其他GPU进程。计划LoRA却意外更新更多基础参数，会增加梯度与优化器状态；基础权重已经放不下时，调梯度累积不能解决加载。\n\n使用单样本微批量和较短真实序列建立基线，检查模板后的token与损失范围。微批量为1时，单条样本仍可能过长，不能换成短数据后宣称原负载已修复。\n\n激活成为主要峰值时，分别比较必要长度、微批量、受支持的重计算和注意力实现；更新阶段失败则检查状态精度、训练范围和优化器。梯度累积安排有效批量，不会让一个单步无限缩小。\n\n继续尝试分片或卸载前，先留出主存、通信与保存所需的资源，再单独改变这一项。调整后把原先失败的那条样本送回相应阶段：反向OOM就确认反向和更新都能走完，随后再检查评估、保存和恢复。短样本能跑，只能帮助定位，不能替原样本宣布修复。",
  "published_at": null,
  "modified_at": "2026-11-26T15:17:38.690397+00:00",
  "evidence": {
    "type": "documentation_and_conditional_estimates",
    "hardware_tested": false,
    "note": "资料解释与条件估算，非硬件实测。"
  },
  "sources": [
    {
      "id": "llamafactory",
      "url": "https://raw.githubusercontent.com/hiyouga/LLaMA-Factory/main/README.md",
      "retrieved_at": "2026-11-25T09:52:45.997121+00:00"
    },
    {
      "id": "transformers-training-memory",
      "url": "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/model_memory_anatomy.md",
      "retrieved_at": "2026-11-25T10:16:15.738480+00:00"
    },
    {
      "id": "peft-quantization",
      "url": "https://raw.githubusercontent.com/huggingface/peft/main/docs/source/developer_guides/quantization.md",
      "retrieved_at": "2026-11-25T09:52:45.997121+00:00"
    },
    {
      "id": "torch-checkpoint",
      "url": "https://docs.pytorch.org/docs/2.15/checkpoint.html",
      "retrieved_at": "2026-11-25T10:16:15.738480+00:00"
    }
  ],
  "revision_note": "完善阅读结构；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-16c27df7e242/",
    "json": "https://gpuatlas.top/data/articles/T-16c27df7e242.json",
    "markdown": "https://gpuatlas.top/data/articles/T-16c27df7e242.md"
  }
}
