Repository navigation
[Feature] Add MiniCPM-SALA support - #30360
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for MiniCPM-SALA sparse attention and hybrid models with Simple GLA (Lightning) attention, including JIT-compiled CUDA kernels, memory pool extensions, and an XML tool call detector. The code review highlights several critical issues, including a potential out-of-bounds memory access in the get_block_table_cuda_v3 kernel, a server crash when radix cache is enabled with sparse attention, and multiple GPU-to-CPU synchronization bottlenecks in the forward path caused by operations on GPU tensors (such as torch.max, .any(), .item(), and torch.arange). Additionally, defensive checks are recommended to prevent potential AttributeError and TypeError exceptions during configuration and tool parsing.
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.
There was a problem hiding this comment.
Pull request overview
This PR adds first-class serving support for MiniCPM-SALA hybrid models by introducing a new HF config, extending the MiniCPM model implementation with hybrid mixer support (sparse attention + Simple GLA/lightning layers), adding MiniCPM-specific attention backends and sparse KV metadata/memory pools, and providing a JIT CUDA kernel for sparse block-table generation plus CI tests/benchmarks.
Changes:
- Add
MiniCPMHybridConfigand update model runner / KV-cache builder to treat MiniCPM-SALA as a hybrid (linear-attn + sparse-attn) architecture. - Introduce MiniCPM sparse-attention utilities/kernels/backends (FlashAttention + FlashInfer paths), new req-to-token auxiliary sparse index pools, and CUDA-graph-related plumbing.
- Add
minicpm4_xmltool-call parser plus unit tests for sparse metadata, tool-call parsing, and get-block-table JIT kernel (incl. benchmark).
Reviewed changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/registered/unit/layers/test_minicpm_sparse_metadata.py | Adds CPU tests for sparse metadata behavior (chunked prefill + CUDA-graph padding). |
| test/registered/jit/test_get_block_table.py | Adds CUDA tests for get-block-table v1/v2/v3 parity + golden checks. |
| test/registered/jit/benchmark/bench_get_block_table.py | Adds a Triton perf report benchmark for block-table kernels. |
| test/registered/function_call/test_minicpm4_xml_detector.py | Adds tests for MiniCPM4 XML tool-call detection/parsing (incl. streaming). |
| python/sglang/srt/utils/hf_transformers/common.py | Registers MiniCPMHybridConfig as a supported HF config. |
| python/sglang/srt/server_args.py | Adds MiniCPM backend names + MiniCPM tuning flags and model-arch adjustments. |
| python/sglang/srt/models/minicpm.py | Extends MiniCPM with hybrid mixer selection and SimpleGLA mixer wrapper; updates EntryClass registration. |
| python/sglang/srt/model_executor/runner/decode_cuda_graph_runner.py | Adds a replay side-channel for MiniCPM CUDA-graph replay metadata. |
| python/sglang/srt/model_executor/model_runner.py | Exposes minicpm_hybrid_config and includes it in “mambaish” detection. |
| python/sglang/srt/model_executor/model_runner_kv_cache_mixin.py | Initializes MiniCPM-specific req-to-token pools for sparse/hybrid layouts. |
| python/sglang/srt/mem_cache/memory_pool.py | Adds MiniCPM sparse auxiliary pools and hybrid req-to-token pool implementations. |
| python/sglang/srt/mem_cache/mamba_radix_cache.py | Persists/frees MiniCPM auxiliary sparse indices alongside radix-cache lifecycle. |
| python/sglang/srt/mem_cache/kv_cache_builder.py | Treats MiniCPM hybrid as requiring hybrid-cache handling. |
| python/sglang/srt/mem_cache/common.py | Allocates/writes auxiliary sparse indices during extend/decode allocations. |
| python/sglang/srt/mem_cache/chunk_cache.py | Saves/frees MiniCPM auxiliary sparse indices for chunk-cache lifecycle. |
| python/sglang/srt/layers/attention/minicpm/sparse_utils.py | Adds sparse attention metadata/config/helpers for MiniCPM (builder/analyzer + compression metadata). |
| python/sglang/srt/layers/attention/minicpm/sparse_kernels.py | Adds Triton kernels for key compression and sparse-page-table → flashinfer conversion. |
| python/sglang/srt/layers/attention/minicpm/fuse_kernel.py | Adds TileLang fused kernels for pooled top-k selection (prefill/decode). |
| python/sglang/srt/layers/attention/minicpm/attention_kernels.py | Adds a backend-agnostic attention-kernel interface and FlashInfer/FlashAttn implementations. |
| python/sglang/srt/layers/attention/hybrid_linear_attn_backend.py | Adds SimpleGLAAttnBackend and ALiBi slope helper for lightning layers. |
| python/sglang/srt/layers/attention/attention_registry.py | Registers minicpm_flashattn and minicpm_flashinfer attention backends. |
| python/sglang/srt/function_call/minicpm4_xml_detector.py | Implements MiniCPM4 XML tool-call detection/parsing (non-streaming + streaming). |
| python/sglang/srt/function_call/function_call_parser.py | Registers minicpm4_xml format detector. |
| python/sglang/srt/configs/minicpm.py | Adds MiniCPMHybridConfig including sparse + lightning parameters and cache params. |
| python/sglang/srt/configs/mamba_utils.py | Adds SimpleGLA state shape/cache params for hybrid-linear backends. |
| python/sglang/srt/configs/init.py | Exports MiniCPMHybridConfig. |
| python/sglang/jit_kernel/utils.py | Adds CCCL include-path fallback (flashinfer-bundled) for JIT robustness. |
| python/sglang/jit_kernel/minicpm_sala/get_block_table.py | Adds Python wrapper to JIT-compile/dispatch get-block-table kernels by topk. |
| python/sglang/jit_kernel/minicpm_sala/init.py | Exports get-block-table functions. |
| python/sglang/jit_kernel/csrc/minicpm_sala/get_block_table.cuh | Adds CUDA kernels + tvm-ffi wrappers for get-block-table v1/v2/v3. |
| python/sglang/srt/layers/attention/minicpm/backend.py | Implements MiniCPMSparseBackend dispatching to flash-attn or flashinfer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ad80e7e to
ec3320e
Compare
ec3320e to
b844e97
Compare
|
/rerun-failed-ci |
956b9f3 to
fbd5d8c
Compare
|
@DarkSharpness Thanks! We have resolved these issues. Please take a look when you are available. |
DarkSharpness
left a comment
There was a problem hiding this comment.
LGTM on JIT kernel side
The five test files added in this branch are pytest-style with no `if __name__ == "__main__":` block. `collect_tests` treats that as a hard error, so every Stage A job collecting the base-a-test-cpu file list died before running a single test. Add `sys.exit(pytest.main([__file__, "-v"]))` (wrapped, so a failing test propagates its exit code to the CI runner) plus the `sys` and `pytest` imports each file was missing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…leLang compile stall with mutable local scalars TileLang 0.1.12 propagates dynamic loop-bound constraints to Z3 via tile-ai/tvm@3a10c4d. Represent the reassigned sequence lengths as mutable kernel-local scalars to avoid expanding conditional expressions throughout layout inference.
|
/rerun-failed-ci |
2 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
Resolve attention_registry.py: main added attn_backend_wrapper_for_draft_decode and this branch added the two MiniCPM sparse backend registrations at the same spot. Both are kept. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Motivation
Add native serving support for MiniCPM-SALA checkpoints, which interleave MiniCPM sparse softmax-attention layers with constant-decay Lightning linear-attention layers.
The implementation integrates the model with SGLang's existing attention, linear-attention, CUDA graph, and memory-pool infrastructure. It also replaces the serving-time dependency on the original out-of-tree block-table extension with SGLang JIT kernels.
Modifications
MiniCPMHybridConfigand register bothMiniCPMForCausalLMandMiniCPMSALAForCausalLM.Mamba2CacheParamsand linear-attention model registry.seg_lakernels instead of introducing a model-specific linear-attention backend or external dependency.minicpm_flashattnandminicpm_flashinfersparse-attention backends.FlashAttentionBackendfor dense metadata and CUDA graph state.ReqToTokenPool.minicpm_flashattn, orminicpm_flashinferon supported Blackwell GPUs.SGLANG_MINICPM_FUSE_TOPK,SGLANG_MINICPM_SPLIT_STAGE1,SGLANG_MINICPM_DENSE_AS_SPARSE, andSGLANG_MINICPM_FORCE_DENSEenvironment switches.Accuracy Tests
The following CPU regression suite passes on the final rebased branch:
It covers:
CUDA correctness tests are included for:
End-to-end checkpoint output accuracy has not yet been recorded on the final rebased branch and should be added before merge.
Speed Tests and Profiling
test/registered/kernels/benchmark/bench_get_block_table.pybenchmarks the v2 prefill and v3 decode block-table kernels across token counts.Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ⏳ Run #32711430603
Latest PR Test (Extra): ⏳ Run #32711430188
Latest PR Test (AMD ROCm 7.2): ⏳ Run #32711430438