[jit-kernel] Support per token group quant 8bit v2 jit kernel#27449
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a JIT port of the AOT sgl_per_token_group_quant_8bit_v2 kernel, including benchmarking, unit tests, and integration into the FP8 quantization layer. The review feedback highlights several critical issues in the CUDA kernel and Python wrapper: potential GPU hangs on Volta+ architectures due to a hardcoded warp mask in __shfl_xor_sync, a potential CUDA runtime error when num_groups is zero, and multiple C++ strict aliasing violations from reinterpret_cast pointer casting that should be replaced with type-safe CUDA intrinsics like __int_as_float and __float_as_uint.
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.
060195a to
9ed4e46
Compare
9ed4e46 to
21100db
Compare
b25dc90 to
66049a8
Compare
66049a8 to
45957c7
Compare
DarkSharpness
left a comment
There was a problem hiding this comment.
Let's move on first. We can optimize in depth after merge.
|
There are some ci failure unrelated with code change, let's rebase main and rerun ci. |
000ac62 to
cb814c3
Compare
Summary
Ports the AOT
sgl_per_token_group_quant_8bit_v2per-token-group FP8 quantization kernel (sgl-kernel/csrc/gemm/per_token_group_quant_8bit_v2.cu) into thejit_kernelmodule with full feature parity, and routes theenable_v2path ofsglang_per_token_group_quant_fp8to the JIT version. The AOT kernel stays in thetree as a dormant fallback.
Motivation: moving this kernel to
jit_kernelremoves the AOT wheel rebuild from the iteration loop (first-use JIT compilation), keeps it next to the other JIT quant kernels, and lets us tune it without asgl-kernelrelease.The JIT kernel is a near-verbatim port (same 256-bit vectorized loads, 8 threads / 128-group, PDL,
NaiveScheduler+MaskedLayoutScheduler, ue8m0 / float scales, fp8 / int8 output, fused silu+mul). It is bit-exact with the AOT kernel.What changed
New
python/sglang/jit_kernel/csrc/gemm/per_token_group_quant_8bit_v2.cuh— the ported kernel + launcher.python/sglang/jit_kernel/per_token_group_quant_8bit_v2.py— Python wrapper.python/sglang/jit_kernel/tests/test_per_token_group_quant_8bit_v2.py— bit-exact tests vs the AOT op.python/sglang/jit_kernel/benchmark/bench_per_token_group_quant_8bit_v2.py— JIT vs AOT benchmark.Modified
python/sglang/srt/layers/quantization/fp8_kernel.py— import the JIT v2 wrapper and call it from theenable_v2branch ofsglang_per_token_group_quant_fp8.Implementation notes
TensorView::data_ptr()/device().--use_fast_mathis required in the JIT build to match the AOT kernel (which is compiled with-use_fast_math); without it the FP8 scale division rounds slightly differently and produces scattered 1-ulp FP8 differences.device::PDLWaitPrimary/PDLTriggerSecondaryhelpers.Validation
Hardware: NVIDIA H20-3e (SM90), CUDA 13.
Correctness — bit-exact vs the AOT kernel (
104 passed)torch.equalon both the FP8 codes and the scales, againstsgl_per_token_group_quant_8bit(..., enable_v2=True):NaiveScheduler): vanilla + fused silu+mul × bf16 / fp16 × num_tokens {1,7,64,333} × hidden {128,2048,4096} × float / ue8m0 scales.MaskedLayoutScheduler): ue8m0 + silu + masked 3D[num_experts, tokens_pad, hidden*2]× experts {2,5} × hidden {2048,4096} × tokens_pad {128,384}.Benchmark — JIT v2 vs AOT v2
group_size=128,hidden=4096, bf16, CUDA-graph timing:JIT v2 matches the AOT kernel at large batch and is slightly faster at small batch (no per-call output allocation on the measured path).
Note: This kernel occupies decode GPU 45.7% in Qwen/Qwen3.5-122B-A10B-FP8.
End-to-end —
Qwen/Qwen3.5-122B-A10B-FP8, TP4, H20-3eServed the model with the wired code (
enable_v2→ JIT v2):CUDA graph capture succeeds (70 s, clean) — confirms the JIT kernel is CUDA-graph-compatible (compiles during warmup, captures cleanly).
GSM8K (200 questions, 5-shot): accuracy
0.970, invalid0.000— identical to the AOT baseline (0.970), so the dispatch change is accuracy-neutral.Notes
sgl_per_token_group_quant_8bitremains available as a fallback (just not the default path).enable_v2group-size gate ({16, 32, 64, 128}) is unchanged.CI States
Latest PR Test (Base): ✅ Run #27405353245
Latest PR Test (Extra): ✅ Run #27405352943