{
  "schema_version": "1.0",
  "id": "T-1cc838bfe49c",
  "url": "https://gpuatlas.top/articles/T-1cc838bfe49c/",
  "title": "Gemma 3 4B 微调时想保留长文本，哪些设置最占显存？",
  "summary": "Gemma 3 4B长文微调先核有效图文样本，再按驻留和反向峰值调整，模型小与局部窗口都不是训练长度保证。",
  "language": "zh-Hans",
  "category": {
    "id": "c-18",
    "name": "模型微调",
    "url": "https://gpuatlas.top/categories/c-18/"
  },
  "topics": [
    {
      "id": "model-6bfe1186af",
      "name": "Gemma 3",
      "kind": "model",
      "description": "按 Gemma 3 的具体模型大小查显卡搭配，分清权重占用、上下文开销和额外运行空间。",
      "url": "https://gpuatlas.top/topics/model-6bfe1186af/"
    },
    {
      "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": "先检查处理后样本与损失范围，再选择长度。Gemma 3 4B带视觉组件和混合注意力，128K推理能力不是训练长度保证，普通推理KV也不能预测反向激活。\n\n核模板、历史、回答、截断、填充和打包，确保长材料保留时关键答案仍在。图文样本保存处理设置，文本token相同不代表图片工作量相同，不能只用短文本代表真实数据。\n\n明确冻结组件、LoRA目标模块、rank和精度，检查实际可训练参数。量化基础权重不表示激活同步低位，先核完整前向、反向与保存支持，用真实长样本完成更新并记录阶段峰值。\n\n基础驻留不足先研究支持的精度布局，反向不足再比较微批量、长度组织与检查点。梯度累积不自动让单条长样本装下，重计算、可能的通信和主存都应加入完整时间。\n\n图文训练比较长度方案时，先确认图片处理条件没有改变，再对照有效训练token与反向峰值。否则看似同样长的文本，实际可能少做了视觉工作。保存恢复后同时检查独立长文与图片识别，才知道Gemma 3 4B省出的空间是否以任务退步为代价。",
  "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": "gemma3-official",
      "url": "https://raw.githubusercontent.com/google-gemma/docs/main/docs/models/gemma-3/index.md",
      "retrieved_at": "2026-11-25T11:28:43.769677+00:00"
    },
    {
      "id": "gemma3-config-code",
      "url": "https://raw.githubusercontent.com/google/gemma_pytorch/main/gemma/config.py",
      "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-1cc838bfe49c/",
    "json": "https://gpuatlas.top/data/articles/T-1cc838bfe49c.json",
    "markdown": "https://gpuatlas.top/data/articles/T-1cc838bfe49c.md"
  }
}
