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 kernel for tree speculative sampling, migrating an existing Ahead-Of-Time (AOT) kernel to the JIT system. This change aims to streamline the availability of tree speculative sampling by removing the need for a heavy AOT compilation path, thereby improving development and deployment efficiency. The new JIT kernel maintains API compatibility and demonstrates comparable, if not slightly improved, performance against its AOT counterpart. 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
|
beaef84 to
55a0011
Compare
There was a problem hiding this comment.
Code Review
The pull request successfully ports the tree_speculative_sampling_target_only kernel from the AOT sgl-kernel to the JIT system. The implementation is clean and follows the established patterns for JIT kernels in the repository. I have identified a few minor issues related to missing header includes in the CUDA source and an inefficient cloning pattern in the benchmark script that could skew performance results.
- bench_speculative_sampling: only reset mutated tensors (predicts, accept_index, accept_token_num, draft_probs) via copy_() between iterations instead of cloning all tensors including large read-only target_probs, removing significant allocation overhead from measurements - speculative_sampling.cuh: add explicit #include <numeric> for std::gcd used at line 192 to avoid relying on transitive inclusion from flashinfer
|
Thanks @Johnsonms! The target tree |
Motivation
Part of the ongoing effort to migrate
sgl-kernelAOT kernels to thejit_kernelsystem (tracking issue #17865). This PR portssgl-kernel/csrc/speculative/speculative_sampling.cuto a JIT kernel, making tree speculative sampling available without the heavyweight AOT compilation path.Key Design Decisions
extra_include_paths: The kernel depends onflashinfer/sampling.cuhforvec_t,SamplingTempStorage,DeviceSamplingFromProb, and dispatch macros (DISPATCH_ALIGNED_VEC_SIZE,DISPATCH_DETERMINISTIC). Following the pattern fromrope.py, these headers are included viaextra_include_pathsat JIT compile time.__global__kernel and host launcher are copied verbatim fromsgl-kernel/csrc/speculative/speculative_sampling.cuh(renamed toTreeSpeculativeSamplingTargetOnlyLauncherto avoid symbol conflicts). A thin tvm-ffi wrapper validates inputs and resolves the CUDA stream.DType=float,IdType=int32_t,IdType2=int64_tmatching the AOT implementation.sgl_kernel.tree_speculative_sampling_target_onlyexactly (same keyword argument names and types).Changes
python/sglang/jit_kernel/csrc/speculative/speculative_sampling.cuh— CUDA kernel + tvm-ffi host wrapperpython/sglang/jit_kernel/speculative_sampling.py— Python API with@register_custom_opand@cache_oncepython/sglang/jit_kernel/tests/test_speculative_sampling.py— 13 tests (smoke, AOT cross-validation, boundary)python/sglang/jit_kernel/benchmark/bench_speculative_sampling.py— JIT vs AOT throughput benchmarkTest Results
All 13 tests pass:
Benchmark (JIT vs AOT, µs, A100):

Correctness:
Performance: JIT is at parity or faster than AOT across all 12 configurations.

No regressions. No further tuning needed.