[Bug]: Gemma 3 global layers run without their linear RoPE scaling (factor 8) on transformers 5.x

未关闭
#23,340 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@chaitanya0305 已经在做这个了。

开始于 2026年12月3日。

  • #23341 来自 @chaitanya0305 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, pytorch
领域
backend, testing

调研方向

Read RopeParams.from_config and the TestFromConfigPerLayerType regression test in tests/unittest/_torch/attention/test_rotary_embedding.py. Reproduce the reported CPU only case with transformers 5.5.4 and check that the normalized full_attention parameters yield 1000000.0 linear 8.0; completion is a regression test that catches the reported none and 1.0 result. An open linked pull request already addresses this issue.

由索引模型根据 Issue 内容生成。

描述

Customized kernels Pytorch
System Info

TensorRT-LLM main (3f692ac), PyTorch backend, transformers 5.5.4 (the version in requirements.txt). The config path is CPU-only, so no GPU is needed to reproduce it.

Who can help?

No response

Information
  • The official example scripts
  • My own modified scripts
Reproduction

On transformers 5.x, PretrainedConfig.rope_scaling is an alias of rope_parameters. For Gemma 3 that is a dict keyed by layer type:

from transformers import Gemma3TextConfig
from tensorrt_llm._torch.attention.backends.interface import RopeParams

# text_config of google/gemma-3-4b-it (same scaling in 12B and 27B)
cfg = Gemma3TextConfig(hidden_size=2560, num_attention_heads=8, num_key_value_heads=4,
                       head_dim=256, num_hidden_layers=34, max_position_embeddings=131072,
                       rope_theta=1e6, rope_local_base_freq=1e4,
                       rope_scaling={"rope_type": "linear", "factor": 8.0})
print(cfg.rope_scaling)
# {'sliding_attention': {'rope_type': 'default', 'rope_theta': 10000.0},
#  'full_attention': {'rope_type': 'linear', 'factor': 8.0, 'rope_theta': 1000000.0}}
rp = RopeParams.from_config(cfg)
print(rp.theta, rp.scale_type.name, rp.scale)
Expected behavior

1000000.0 linear 8.0. HF's Gemma3RotaryEmbedding divides the full-attention inv_freq by 8.

actual behavior

1000000.0 none 1.0.

Gemma3Attention builds every global (full-attention) layer from this RopeParams, so Gemma 3 4B/12B/27B (and fine-tunes such as MedGemma) run their global layers with RoPE angles 8x too large at every position. Sliding layers are not affected, because they override theta and scaling. The existing GPU test test_gemma3_allclose_to_hf[27B] does not catch this: it uses 8 tokens, atol=0.4, and a "most elements close" check, with a single global layer.

additional notes

Root cause: in RopeParams.from_config, from_config correctly picks rope_parameters["full_attention"] into normalized_rope_parameters. But it then reads scaling from getattr(config, "rope_scaling"). That is the outer per-layer-type dict, which is not None, so the fallback to the normalized entry never runs. rope_type and factor are both missing from the outer dict, so the scaling becomes none with a factor of 1.0.

Fix: when rope_scaling is None or is the per-layer-type rope_parameters itself, use the normalized entry. A fix with a CPU-only regression test (TestFromConfigPerLayerType in tests/unittest/_torch/attention/test_rotary_embedding.py) follows in a PR.

Before submitting a new issue...
  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
主要语言
Python
星标
15.2k
派生
3k
平均合并
2 天 21 小时
30 天内合并 PR
477

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/TensorRT-LLM 的其他 Issue

查看 NVIDIA/TensorRT-LLM 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。