fix: support non-128-aligned element sizes in HiCache JIT - #30736
Chronostasys wants to merge 2 commits into
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
@DarkSharpness could you take a review? |
|
/rerun-group hicache |
|
Results for 🚀 🚀 🚀 🚀 |
|
One more real-world element size for this PR: 656 bytes, from the W4AFP8 GLM-5.2 checkpoint Correctness. We enabled Mooncake L3 in production on v0.5.17, i.e. with #31443 already in, Performance. Under load, per replica (8 ranks aggregated): |
…ernel Rebased onto the sglang.kernels layout per RFC sgl-project#29630 (sgl-project#31666/sgl-project#32015/sgl-project#32072) now that sglang.jit_kernel is retired. No logic changes: the patch now lives in kernels/jit/csrc/kvcacheio/hicache.cuh and kernels/ops/kvcache/hicache.py.
07be905 to
41e5311
Compare
|
Rebased onto the new sglang.kernels layout — #32072 retired the jit_kernel directory, so the patch now lives in The report from @alilxxey above is worth extra weight IMO, since it covers both sides of this fix:
@DarkSharpness could you take another look when you get a chance? Happy to address any feedback on the new layout. |
|
One clarification on my 656 case:
|
656 (= 2^4 * 41) cannot satisfy the per-thread 4-byte alignment at the default unroll (num_threads=16 gives 41 bytes/thread), and no caller passes unroll explicitly, so it had no reachable configuration and can_use_hicache_jit_kernel rejected it. Resolve unrolls by walking the ladder from the performance default toward larger unroll (fewer threads per package), so 656 now lands on unroll=8 (num_threads=4, 164 bytes/thread, 4B packages). All non-staged entry points share the same resolver, so the check and the transfer helpers can no longer disagree on the chosen unroll. Sizes that divide cleanly at the default (576, 1024, ...) keep their original unroll.
|
Good catch, thanks for walking through the arithmetic — 656 = 2^4 × 41 indeed has no viable config at the default unroll. Fixed in 3487820: the non-staged paths now resolve the unroll by walking the ladder from the performance default toward fewer threads per package (num_threads 16 → 8 → 4 → 2 → 1), so 656 lands on unroll=8 (num_threads=4, 164 bytes/thread, 4B packages). The resolver is shared by |
|
We hit exactly this in production: a GLM-5.3 fine-tuned FP8 model (MLA layout, Startup log showed Impact: production data plane crashed mid-task, systemd restart loop amplified the outage (concurrent long-context requests hit every restarted instance). Temporary mitigation: disabled HiCache entirely on single-box deployments (host offload is not critical there), throughput cost ~15% (933 vs 1099 tok/s at concurrency 8 on 8×B200). We'd love to see this land — after merge we'll re-enable HiCache and run the long-context concurrency regression to confirm. Thanks for the fix! |
|
Thanks for the detailed report — and sorry it took a production crash to surface this. 576 is exactly the primary case this fix targets: after it lands, the JIT path accepts 576 (num_threads=16, 36 B/thread, 4B packages) instead of rejecting it, so your load path stays on the JIT kernels rather than the prebuilt fallback that segfaulted for you. Your post-merge long-context regression will be the real confirmation — if anything in the staged write-back path still misbehaves for 576, happy to follow up on it here. |
Motivation
HiCache JIT currently assumes each transferred element size is 128-byte aligned. Models with MLA KV layouts such as GLM-5.2 can use an
element_sizeof 576 bytes, which is not divisible by 128. In that case the JIT kernel is rejected before it can be used, even though the data can still be safely transferred with smaller vectorized memory packages.I checked upstream
mainand searched existing issues/PRs for related HiCache JIT fixes (HiCache JIT element_size 576,hicache multiple of 128,GLM-5.2 hicache) and did not find an existing fix for this case.Changes
16B,8B, or4B) that evenly covers each worker thread's byte range.Validation
python3 -m py_compile python/sglang/jit_kernel/hicache.pypython3 -m ruff check --select=F401,F821,UP037 python/sglang/jit_kernel/hicache.pypython3 -m isort --check-only python/sglang/jit_kernel/hicache.pygit diff --check upstream/main..HEADelement_size=576with the default unroll configuration.CI States
Latest PR Test (Base): ❌ Run #33533584580
Latest PR Test (Extra): ❌ Run #33533584383
Latest PR Test (AMD ROCm 7.2): ❌ Run #33533584427
✨ Presented to you with Mind Lab — A Lab for Experiential Intelligence.