Repository navigation
[Bugfix] Keep rope_theta when --json-model-override-args overrides rope_scaling - #43067
Conversation
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
1b2164a to
8b0c634
Compare
There was a problem hiding this comment.
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.
|
Thanks for checking the recipes. Confirmed on 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. |
|
/tag-and-rerun-ci |
Motivation
Fixes #41227.
Under transformers v5 the RoPE base lives inside
rope_parameters, andrope_scalingis an alias whose setter replaces that dict wholesale.get_config()applies--json-model-override-argswith a plainsetattr, so an override like(even one that just restates the checkpoint's own scaling) leaves
rope_parameterswithoutrope_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 isrope_scalingorrope_parametersand 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; nestedPretrainedConfigoverrides keep the existingupdate()path.Accuracy Tests
No model code changes. Two cases in
test/registered/unit/utils/test_hf_transformers_loading.py, using a local Llamaconfig.jsonwithrope_theta: 500000(no weights, no download):factorthrough eitherrope_scalingorrope_parameterskeepsrope_theta == 500000and applies the factor;rope_thetastill wins, while the other rope keys survive.On
mainboth fail (AssertionError: 10000 != 500000.0, thenKeyError: '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_scalingproperty setter in transformers (configuration_utils.py), which replacesrope_parameterswholesale; 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