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

オープン
#23,340 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
477

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT-LLM のほかの issue

NVIDIA/TensorRT-LLM の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。