Skip to content

[Bugfix] Keep rope_theta when --json-model-override-args overrides rope_scaling - #43067

Merged
JustinTong0323 merged 3 commits into
sgl-project:mainfrom
jinwukong:fix/rope-override-keeps-base
Oct 14, 2026
Merged

JustinTong0323 merged 3 commits into
sgl-project:mainfrom
jinwukong:fix/rope-override-keeps-base

Conversation

@jinwukong

@jinwukong jinwukong commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #41227.

Under transformers v5 the RoPE base lives inside rope_parameters, and rope_scaling is an alias whose setter replaces that dict wholesale. get_config() applies --json-model-override-args with a plain setattr, so an override like

--json-model-override-args '{"rope_scaling": {"rope_type": "llama3", "factor": 32.0, ...}}'

(even one that just restates the checkpoint's own scaling) leaves rope_parameters without rope_theta. get_rope_config() then silently falls back to 10000 and the model keeps generating fluent text with the wrong base; the issue measured Llama-3.2-3B-Instruct GSM8K (first 200) dropping from 161 to 106. Models with a hard-coded per-model fallback (Qwen3 dense, 1e6) hide the problem; Llama (500000) and Qwen3-MoE do not.

An earlier attempt (#41239) was closed by its author before review.

Modifications

python/sglang/srt/utils/hf_transformers/config.py: when the override key is rope_scaling or rope_parameters and both the override and the loaded value are dicts, merge them (override keys win, the rest survives) instead of replacing the dict. Other override keys are untouched; nested PretrainedConfig overrides keep the existing update() path.

Accuracy Tests

No model code changes. Two cases in test/registered/unit/utils/test_hf_transformers_loading.py, using a local Llama config.json with rope_theta: 500000 (no weights, no download):

  • restating the checkpoint's llama3 scaling with a new factor through either rope_scaling or rope_parameters keeps rope_theta == 500000 and applies the factor;
  • an override that names rope_theta still wins, while the other rope keys survive.

On main both fail (AssertionError: 10000 != 500000.0, then KeyError: 'factor'); with the fix they pass and the whole file passes (6 tests, 4 subtests; Python 3.12, CPU).

Speed Tests and Profiling

Not applicable: config loading only.

Upstream

The root cause is the rope_scaling property setter in transformers (configuration_utils.py), which replaces rope_parameters wholesale; huggingface/transformers#49515 proposes fixing it there. SGLang still needs this merge for the transformers releases it supports today (up to 5.19.0 at the time of this PR).

Checklist


CI States

Latest PR Test (Base): ✅ Run #38275324245
Latest PR Test (Extra): ❌ Run #38275323981
Latest PR Test (AMD ROCm 10): ❌ Run #38275324202

Under transformers v5 the RoPE base lives inside rope_parameters and
rope_scaling is an alias whose setter replaces that dict wholesale, so a
--json-model-override-args rope_scaling override dropped rope_theta and
get_rope_config fell back to 10000 (Llama-3.2-3B GSM8K 161 -> 106).

Merge dict overrides for rope_scaling / rope_parameters: override keys
win, the remaining keys survive from the loaded config.

Fixes sgl-project#41227

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgl cookbook recipes (Qwen3-Next 1M context, Ling-2.6/Ling-3.0 YaRN) instruct users to launch with --json-model-override-args '{"rope_scaling": ...}', so the silent rope_theta → 10000 drop hits officially documented usage on the pinned transformers v5, and the merge semantics here look correct.

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinwukong

Copy link
Copy Markdown
Contributor Author

Thanks for checking the recipes. Confirmed on main: the Qwen3-Next 1M-context commands pass {"rope_scaling": {"rope_type": "yarn", "factor": 4.0, "original_max_position_embeddings": 262144}} with no rope_theta, which is exactly the case test_rope_scaling_override_keeps_the_rope_base covers (the base silently falls back to the default). The Ling-2.6 / Ling-3.0 snippets spell out rope_theta and partial_rotary_factor inside the override, so they survive either way; with this merge both styles give the same result.

The root cause in the transformers setter is proposed upstream in huggingface/transformers#49515; this PR keeps the override correct on the transformers releases SGLang pins today.

@JustinTong0323

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 12, 2026

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JustinTong0323
JustinTong0323 merged commit 44b4477 into sgl-project:main Oct 14, 2026
315 of 361 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

3 participants