[jit_kernel] Add JIT segment_packbits kernel (port of sgl-kernel packbit.cu) #19088
[jit_kernel] Add JIT segment_packbits kernel (port of sgl-kernel packbit.cu) #19088Johnsonms wants to merge 4 commits intosgl-project:mainfrom
Conversation
Port sgl-kernel/csrc/speculative/packbit.cu to the JIT kernel framework. - csrc/speculative/packbit.cuh: TVM FFI entry point wrapping flashinfer::quantization::SegmentPackBits; uses RuntimeCheck validation and LaunchKernel::resolve_device for stream handling - packbit.py: Python wrapper with @register_custom_op and @cache_once; loads with flashinfer include path for quantization.cuh header - tests/test_packbit.py: 12 tests covering known-answer (0xFF, 0x00, little-endian, partial byte), CPU reference validation, and JIT vs AOT - benchmark/bench_packbit.py: throughput benchmark across batch sizes and segment lengths with correctness diff
Add test_variable_length_segments covering segments of lengths 1–65 in a single batch, mixing exact multiples-of-8 and partial last bytes, validated against the CPU reference.
Summary of ChangesHello @Johnsonms, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a JIT kernel for segment_packbits, porting an existing AOT kernel to the JIT framework. This is a valuable addition that reduces reliance on pre-built wheels. The implementation is well-structured, with a clear separation between the C++ FFI wrapper, the Python JIT loader, and the user-facing Python function. The accompanying tests are comprehensive, covering known-answer cases, comparison with a CPU reference implementation, and cross-validation against the AOT kernel, which ensures a high degree of confidence in its correctness. The benchmark script is also well-designed for comparing the JIT and AOT versions. I have one minor suggestion to improve the reproducibility of the benchmark.
Motivation
#17865
sgl-kernelships an AOT CUDA kernel forsegment_packbits. This PR portsit to the JIT kernel framework so it can be used without the pre-built
sgl-kernelwheel, following the same pattern as theeagle_utilsandngram_utilsJIT ports.Modifications
python/sglang/jit_kernel/csrc/speculative/packbit.cuh: TVM FFIentry point wrapping
flashinfer::quantization::SegmentPackBits; usesRuntimeCheckfor input validation andLaunchKernel::resolve_deviceforstream handling.
python/sglang/jit_kernel/packbit.py: Python wrapper with@register_custom_op(mutates_args=["y"]) and@cache_once; loads withthe flashinfer include path for
quantization.cuh.python/sglang/jit_kernel/tests/test_packbit.py: 13 tests —known-answer (0xFF, 0x00, little-endian, partial byte), CPU reference
validation for fixed-length and variable-length segments, and JIT vs AOT
cross-validation.
python/sglang/jit_kernel/benchmark/bench_packbit.py: Throughputbenchmark across batch sizes and segment lengths with a correctness diff
between JIT and AOT.
Accuracy Tests
python -m pytest python/sglang/jit_kernel/tests/test_packbit.py

Benchmarking and Profiling
python python/sglang/jit_kernel/benchmark/bench_packbit.pyChecklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci