{
  "schema_version": "1.0",
  "id": "T-068d98e860c4",
  "url": "https://gpuatlas.top/articles/T-068d98e860c4/",
  "title": "训练长度从 2K 改到 8K，显存为什么突然不够？",
  "summary": "训练2K到8K会增加激活与注意力工作，但总显存不一定四倍，需核对实际样本和失败阶段。",
  "language": "zh-Hans",
  "category": {
    "id": "c-05",
    "name": "微调与训练",
    "url": "https://gpuatlas.top/categories/c-05/"
  },
  "topics": [
    {
      "id": "task-796e01d5af",
      "name": "训练",
      "kind": "task",
      "description": "模型训练时的资源占用与推理不同。查看优化器、激活值、并行策略和中断恢复相关问题。",
      "url": "https://gpuatlas.top/topics/task-796e01d5af/"
    }
  ],
  "body_text": "训练长度2K改8K后OOM，原因往往是反向激活和注意力工作增加。即使权重、batch和精度不变，序列更长也可能超过预算，推理KV不能代替这部分训练空间。\n\n总占用不能统一说四倍，权重和部分更新状态不随长度同样增长，内核与注意力实现又改变临时空间。高效注意力减少部分成本，不会让全部长序列开销消失。\n\n先看模板后实际token、历史与特殊标记，打包、填充和截断决定每步内容。上限8K不表示每条样本恰好8K，也可能让原先被截掉的回答或长样本进入，需保存长度分布。\n\n固定其他设置，逐档长度完成前向、反向与更新，记录峰值阶段，评估及保存另外验收。加载占用相同不能证明训练峰值相同，微批量为1也不代表单条足够小。\n\n长样本依赖前后两段内容时，切分前先确认答案仍能看到必要关系，不能仅为装下就丢监督。确实需要完整长依赖时，再比较受支持重计算和注意力实现，逐项记录有效token、峰值和完整耗时。能跑完8K只是容量结果，还要用未见长材料确认训练保留了所需能力。",
  "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": "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": "flashattention",
      "url": "https://raw.githubusercontent.com/Dao-AILab/flash-attention/main/README.md",
      "retrieved_at": "2026-11-25T10:07:29.175278+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-068d98e860c4/",
    "json": "https://gpuatlas.top/data/articles/T-068d98e860c4.json",
    "markdown": "https://gpuatlas.top/data/articles/T-068d98e860c4.md"
  }
}
