Skip to content

[Model] Add support for Nanbeige4.2 - #32151

Merged
JustinTong0323 merged 6 commits into
sgl-project:mainfrom
Nanbeige:nbg42
Sep 5, 2026
Merged

JustinTong0323 merged 6 commits into
sgl-project:mainfrom
Nanbeige:nbg42

Conversation

@zqlcode

@zqlcode zqlcode commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add day-0 / native SGLang support for Nanbeige4.2, which uses a custom looped Transformer architecture (model_type=nanbeige, NanbeigeForCausalLM).

Model / weights: (https://huggingface.co/Nanbeige/Nanbeige4.2-3B)

Modifications

  • Add NanbeigeConfig (python/sglang/srt/configs/nanbeige.py) and register it in config / HF config registry.
  • Add model implementation python/sglang/srt/models/nanbeige.py:
    • unique layer_id per loop for KV cache / CUDA graph
    • NanbeigeForCausalLM + NanbeigeForSequenceClassification (EntryClass)
  • Update model_config.py: num_attention_layers = num_hidden_layers * num_loops for NanbeigeForCausalLM.
  • Generalize loop-model handling in layer_setup.py (expand ModuleList attentions, sort by layer_id; also cover num_loops / loop_num).
  • Wire parsers for serving UX:
    • --tool-call-parser nanbeige → Qwen3CoderDetector
    • --reasoning-parser nanbeige → Qwen3Detector

Impact

This PR is primarily a model registration + architecture enablement change. It does not modify the shared serving/runtime path for existing models.

The only non-registration runtime touch is in layer_setup.py, which generalizes loop-model attention collection so Prefill CUDA Graph can correctly index RadixAttention by layer_id for num_loops > 1. Behavior for non-loop models is unchanged.

Accuracy Tests

  • Model:
  • Command:
python3 -m sglang.launch_server \
  --model-path Nanbeige/Nanbeige4.2-3B \
  --host 0.0.0.0 \
  --port 9000 \
  --tp-size 1 \
  --mem-fraction-static 0.8  \
  --reasoning-parser nanbeige \
  --tool-call-parser nanbeige

gsm8k
image

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #33857111747
Latest PR Test (Extra): ❌ Run #33857111409
Latest PR Test (AMD ROCm 7.2): ❌ Run #33857111640

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@hnyls2002

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 Sep 3, 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

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
JustinTong0323 merged commit 77aee20 into sgl-project:main Sep 5, 2026
289 of 343 checks passed
StevenChenSE pushed a commit to StevenChenSE/sglang that referenced this pull request Sep 6, 2026
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

Development

Successfully merging this pull request may close these issues.

3 participants