{
  "schema_version": "1.0",
  "id": "T-eba5e68b04ce",
  "url": "https://gpuatlas.top/articles/T-eba5e68b04ce/",
  "title": "LLaMA-Factory 的 cutoff_len 怎么设，才能不浪费显存？",
  "summary": "LLaMA-Factory的cutoff_len应按模板后长度和有效回答选择，packing及损失掩码需一起检查。",
  "language": "zh-Hans",
  "category": {
    "id": "c-09",
    "name": "框架配置与故障",
    "url": "https://gpuatlas.top/categories/c-09/"
  },
  "topics": [],
  "body_text": "LLaMA-Factory的cutoff_len先根据数据经过模板和分词后的长度分布选择。原始字符数不是token数，系统说明、历史和回答都可能加入，统一给所有模型填写2048或8192没有数据依据。\n\n重点抽查长样本和截断结果，确认回答、关键条件与需要监督的内容仍存在。只看平均长度容易漏掉极长样本或空目标，长度降下来以后训练更快，也可能只是删除了真正要学习的内容。\n\n显存和计算还受微批量、填充、打包与模型结构影响。packing可以重新组织短样本，相关跨样本注意力与损失处理要按实际配置核对，不能只开启选项就认为工作量与原先相同。\n\n检查train_on_prompt和mask_history等监督条件，确认学哪些token。当前固定源码还会在packing设置下调整cutoff_len，记录时应保存有效配置与处理样本，而不只写启动时填写的数字。\n\n可以围绕长度分布选几档cutoff_len，专门比较原先最长的那些样本：关键条件和目标回答还剩多少，峰值与耗时怎样变化。短样本较多时再单独比较packing，避免把截断与打包的收益混在一起。最后选能保留任务信息的范围，并完成一次保存恢复，而不是按每秒样本数最高的档位决定。",
  "published_at": null,
  "modified_at": "2026-11-26T15:00:32.276655+00:00",
  "evidence": {
    "type": "documentation_and_conditional_estimates",
    "hardware_tested": false,
    "note": "资料解释与条件估算，非硬件实测。"
  },
  "sources": [
    {
      "id": "llamafactory-data-args",
      "url": "https://raw.githubusercontent.com/hiyouga/LLaMA-Factory/main/src/llamafactory/hparams/data_args.py",
      "retrieved_at": "2026-11-25T11:04:14.292936+00:00"
    },
    {
      "id": "llamafactory-data",
      "url": "https://raw.githubusercontent.com/hiyouga/LLaMA-Factory/main/data/README.md",
      "retrieved_at": "2026-11-25T11:04:14.292936+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"
    }
  ],
  "revision_note": "更新使用说明与操作示例；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-eba5e68b04ce/",
    "json": "https://gpuatlas.top/data/articles/T-eba5e68b04ce.json",
    "markdown": "https://gpuatlas.top/data/articles/T-eba5e68b04ce.md"
  }
}
