[jit_kernel] Add JIT ngram_utils kernel #19085
[jit_kernel] Add JIT ngram_utils kernel #19085Johnsonms wants to merge 4 commits intosgl-project:mainfrom
Conversation
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 introduces a Just-In-Time (JIT) compiled version of 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 ngram_utils, improving portability and development iteration speed. The changes include a new CUDA kernel, a Python wrapper, and comprehensive tests and benchmarks. The code appears to be well-structured and follows existing patterns within the project. The addition of correctness checks and performance benchmarks is a good practice.
Motivation
#17865
The reconstruct_indices_from_tree_mask kernel in sgl-kernel reconstructs
tree traversal indices (positions, retrive_index, retrive_next_token,
retrive_next_sibling) from a flat boolean tree attention mask. Porting it
to the JIT kernel framework makes it available without requiring a
pre-compiled sgl-kernel package, improving portability and development
iteration speed.
Modifications
sgl-kernel/csrc/speculative/ngram_utils.cu. Replaces PyTorch ATen tensor
types with tvm::ffi::TensorView, at::cuda::getCurrentCUDAStream() with
LaunchKernel::resolve_device(), and adds comprehensive input validation via
RuntimeCheck. The CUDA device kernel reconstructIndicesFromTreeMask is
unchanged.
reconstruct_indices_from_tree_mask using @register_custom_op, following the
same pattern as other JIT kernels.
runs across batch sizes and tree sizes, known-answer tests for a
linear-chain tree (positions, next_token links, sibling links), and JIT vs
AOT cross-validation (15 tests, all passing).
triton.testing.perf_report benchmark comparing JIT vs AOT across typical
batch sizes and draft token counts, with a correctness diff section.
Accuracy Tests
python -m pytest python/sglang/jit_kernel/tests/test_ngram_utils.pyBenchmarking and Profiling
python python/sglang/jit_kernel/benchmark/bench_ngram_utils.pyChecklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci