Skip to content

[Model] Add support for JetBrains' Mellum v2 code generation model - #27375

Merged
alexnails merged 11 commits into
sgl-project:mainfrom
shadeMe:feat/new-model-mellum
Jul 14, 2026
Merged

alexnails merged 11 commits into
sgl-project:mainfrom
shadeMe:feat/new-model-mellum

Conversation

@shadeMe

@shadeMe shadeMe commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add support for JetBrains/Mellum2-12B-A2.5B-Thinking and related variants, a hybrid sliding-window-attention MoE code-generation model from JetBrains.

Modifications

  • New MellumForCausalLM model file inheriting from Qwen with the following additions/changes: interleaved sliding-window/full attention via layer_types, per-layer-type RoPE and per-layer dense/sparse MLP routing via mlp_layer_types.
  • HF config compatibility shim in _CONFIG_REGISTRY: prefers native MellumConfig when available (transformers>=5.10.2), falls back to a Qwen3MoeConfig-based alias otherwise.
  • Hybrid-SWA registration in model_config.py.
  • MellumForCausalLM added to common_utils.py MoE tuning architecture dispatch.
  • Documentation row added to docs_new/docs/supported-models/generative_models.mdx.

Usage

Launch Server

python -m sglang.launch_server --model-path JetBrains/Mellum2-12B-A2.5B-Thinking \
  --host 0.0.0.0 --port 30000 --attention-backend flashinfer \
  --reasoning-parser qwen3

Basic Chat

from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")

resp = client.chat.completions.create(
    model="JetBrains/Mellum2-12B-A2.5B-Thinking",
    messages=[{"role": "user", "content": "Write a Python function to compute Fibonacci numbers."}],
    max_tokens=1024,
    extra_body={"chat_template_kwargs": {"enable_thinking": False}},
)
print(resp.choices[0].message.content)

# Thinking/Reasoning
resp = client.chat.completions.create(
    model="JetBrains/Mellum2-12B-A2.5B-Thinking",
    messages=[{"role": "user", "content": "If a train travels at 60 km/h for 2.5 hours, how far?"}],
    max_tokens=2048,
    extra_body={"chat_template_kwargs": {"enable_thinking": True}},
)
print(resp.choices[0].message.reasoning_content)
print(resp.choices[0].message.content)

Accuracy Tests

BF16, served via sglang.launch_server with flashinfer attention backend. SGLang TP=1 on 1×H200; SGLang TP=2 on 2×H200.

Eval SGLang TP=1 SGLang TP=2
GSM8K (200, 5-shot, completion API) 0.830 0.840
MMLU (500, thinking off) 0.620 0.624
HumanEval pass@1 (50, thinking off) 0.852 0.844
HumanEval pass@5 0.860 0.860

Sampling: temperature=0, max_tokens=512 (GSM8K) / 1024 (MMLU, HumanEval). GSM8K uses /v1/completions to bypass the chat template's <think> prefix; MMLU and HumanEval use /v1/chat/completions with enable_thinking=false.

Speed Tests and Profiling

BF16, sglang.bench_serving --backend sglang --dataset-name random.

Latency (10 prompts, cc=1)

python3 -m sglang.bench_serving --backend sglang \
  --host 127.0.0.1 --port 30000 \
  --dataset-name random --num-prompts 10 --max-concurrency 1
Metric TP=1 TP=2
Successful requests 10 10
Output token throughput (tok/s) 305.37 338.53
Total token throughput (tok/s) 610.73 677.07
Mean TTFT (ms) 42.77 36.61
Mean TPOT (ms) 3.23 2.92
Median ITL (ms) 3.23 2.87

Throughput (1000 prompts, cc=100)

python3 -m sglang.bench_serving --backend sglang \
  --host 127.0.0.1 --port 30000 \
  --dataset-name random --num-prompts 1000 --max-concurrency 100
Metric TP=1 TP=2
Successful requests 1000 1000
Request throughput (req/s) 7.51 10.24
Output token throughput (tok/s) 7687.10 10486.3
Total token throughput (tok/s) 15374 20973
Mean TTFT (ms) 1494.67 1175.03
Mean TPOT (ms) 11.54 8.34
Median ITL (ms) 10.22 7.17

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 #29285622880
Latest PR Test (Extra): ❌ Run #29285622794

[Mellum](https://www.jetbrains.com/mellum/) v2 is an update to JetBrains'
open-weights code generation model that is built on a Mixture-of-Experts
architecture.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds support for the Mellum model architecture (MellumForCausalLM), a Qwen3-MoE variant featuring interleaved sliding-window/full attention, per-layer-type RoPE, and mixed dense/MoE MLP layers. The changes include updating model and benchmark configurations, implementing the model layers and class, and registering a custom configuration alias for older transformers versions. The review feedback highlights two critical issues: first, gate_up_proj should be defined in packed_modules_mapping at the class level rather than conditionally at the instance level to prevent issues with weight loaders and quantization frameworks; second, the __post_init__ method in the configuration alias must not accept **kwargs to avoid raising a TypeError during initialization.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/models/mellum.py Resolved
Comment thread python/sglang/srt/models/mellum.py Resolved
shadeMe and others added 3 commits June 5, 2026 12:16
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 5, 2026
@shadeMe

shadeMe commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

cc @wisclmy0611 @zijiexia @JustinTong0323

Any chance we could get this reviewed and merged this week?

@Jiminator Jiminator self-assigned this Jul 11, 2026

@alexnails alexnails 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.

all minor, please ping me on slack if any questions

Comment thread python/sglang/srt/models/mellum.py Resolved
Comment thread python/sglang/srt/models/mellum.py Resolved
@alexnails

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 Jul 11, 2026
# Conflicts:
#	python/sglang/srt/configs/model_config.py
#	python/sglang/srt/utils/hf_transformers/common.py
@Jiminator
Jiminator requested a review from sogalin as a code owner July 12, 2026 05:16
@Jiminator
Jiminator force-pushed the feat/new-model-mellum branch from fc1ae51 to 03e1701 Compare July 12, 2026 05:20
@alexnails

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

Jiminator and others added 3 commits July 12, 2026 10:04
- Dense mlp_layer_types layers crashed: Qwen3MoeDecoderLayer.forward calls
  self.mlp(x, forward_batch) but Qwen3MoeMLP.forward only accepts x. Add a
  signature-compatible MellumMLP wrapper.
- Reject the NPU prepare path: it primes shared rotary cos/sin on the first
  local layer only, which Mellum's per-layer RoPE breaks (get_rope returns
  distinct instances for the per-layer rope params).
- Raise on missing config.sliding_window for sliding_attention layers instead
  of silently building full attention.
- Honor the legacy rope "type" key alongside "rope_type" (get_rope accepts
  both, but the YaRN precompute and rope_scaling gating silently returned
  default-rope behavior for legacy-key configs).
- Document the positions int32 over-approximation invariant; fix the
  MellumConfig version comment and docstring.
@shadeMe

shadeMe commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@Jiminator @alexnails Thanks a lot for picking this up 🙏 AFAICT, the test failures seem to be unrelated. Please let me know if anything else is required from my side.

@alexnails
alexnails merged commit 702bddc into sgl-project:main Jul 14, 2026
212 of 247 checks passed
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…gl-project#27375)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Jiminator <[email protected]>
Co-authored-by: Alex Nails <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation 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