{
  "schema_version": "1.0",
  "id": "T-5150bb3f0f70",
  "url": "https://gpuatlas.top/articles/T-5150bb3f0f70/",
  "title": "Gemma 4 31B 微调时想保留长文本，哪些设置最占显存？",
  "summary": "Gemma 4 31B长文训练先核真实token与有效答案，再按激活、微批量和训练格式定位峰值，256K推理能力不是训练保证。",
  "language": "zh-Hans",
  "category": {
    "id": "c-18",
    "name": "模型微调",
    "url": "https://gpuatlas.top/categories/c-18/"
  },
  "topics": [
    {
      "id": "model-bf587b53c1",
      "name": "Gemma 4",
      "kind": "model",
      "description": "这里整理已有 Gemma 4 相关文章的配置问题；实际使用前，需核对文章所指版本、来源与框架支持。",
      "url": "https://gpuatlas.top/topics/model-bf587b53c1/"
    },
    {
      "id": "task-e33d9598da",
      "name": "微调",
      "kind": "task",
      "description": "让模型适应自己的任务，从训练方式、样本和显存预算入手，最后验证适配器是否真正起效。",
      "url": "https://gpuatlas.top/topics/task-e33d9598da/"
    },
    {
      "id": "task-a7bab8d8aa",
      "name": "长文本",
      "kind": "task",
      "description": "长文本训练会增加哪些中间开销？查看序列长度与 batch 的取舍，避免只按模型权重估算显存。",
      "url": "https://gpuatlas.top/topics/task-a7bab8d8aa/"
    }
  ],
  "body_text": "先看处理后长度和损失范围，不从256K推理上限开始。Gemma 4 31B约30.7B参数，训练还要承担反向激活和状态，静态加载参考不能预测完整训练峰值。\n\n核对模板、历史、回答、截断、填充和打包，确认保留材料没有删除关键答案。图文样本固定处理设置，31B支持文本与图像，不套12B音频路径，文本token相同也不代表视觉工作量相同。\n\n明确格式、冻结范围、目标模块、rank和精度。QAT发布不自动证明当前低位训练支持，先核前向、反向和保存，用真实长样本完成更新，分别记录峰值，不只观察加载。\n\n若基础驻留不足，先研究支持的精度或布局；若反向超预算，再比较微批量、长度组织与检查点。梯度累积不消除单条过长需求，重计算和分片通信要计入完整时间。\n\nGemma 4 31B长文与图文方案比较时，应同时保留有效训练token和图片处理条件；单看文本长度相同，无法判断工作量是否相同。选定配置后恢复适配器，分别检查长文错引与图片信息退步。这里验证的是文本和图像，不能直接延用到12B的音频流程。",
  "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": "gemma4-card",
      "url": "https://raw.githubusercontent.com/google-gemma/docs/main/docs/models/gemma-4/model-card.md",
      "retrieved_at": "2026-11-25T11:31:21.126309+00:00"
    },
    {
      "id": "gemma4-official",
      "url": "https://raw.githubusercontent.com/google-gemma/docs/main/docs/models/gemma-4/index.md",
      "retrieved_at": "2026-11-25T11:31:21.126309+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": "torch-checkpoint",
      "url": "https://docs.pytorch.org/docs/2.15/checkpoint.html",
      "retrieved_at": "2026-11-25T10:16:15.738480+00:00"
    },
    {
      "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"
    }
  ],
  "revision_note": "完善阅读结构；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-5150bb3f0f70/",
    "json": "https://gpuatlas.top/data/articles/T-5150bb3f0f70.json",
    "markdown": "https://gpuatlas.top/data/articles/T-5150bb3f0f70.md"
  }
}
