Skip to content

Comments

[jit_kernel] Add JIT eagle_utils kernel#19083

Open
Johnsonms wants to merge 7 commits intosgl-project:mainfrom
Johnsonms:eagle-utils-jit-from-main
Open

[jit_kernel] Add JIT eagle_utils kernel#19083
Johnsonms wants to merge 7 commits intosgl-project:mainfrom
Johnsonms:eagle-utils-jit-from-main

Conversation

@Johnsonms
Copy link
Contributor

@Johnsonms Johnsonms commented Feb 20, 2026

Motivation

#17865
The eagle_utils kernels (build_tree_kernel_efficient and
verify_tree_greedy) are currently only available as AOT-compiled functions
in sgl-kernel. Porting them to the JIT kernel framework allows SGLang to
build and use these kernels without requiring a pre-compiled sgl-kernel
package, improving portability and enabling faster iteration during
development.

Modifications

  • python/sglang/jit_kernel/csrc/speculative/eagle_utils.cuh: JIT port of
    sgl-kernel/csrc/speculative/eagle_utils.cu. Replaces PyTorch ATen tensor
    types with tvm::ffi::TensorView, at::cuda::getCurrentCUDAStream() with
    LaunchKernel::resolve_device(), and CHECK_* macros with RuntimeCheck. The
    two CUDA device kernels (build_tree_efficient,
    build_tree_efficient_partial_packed, VerifyTreeGreedy) are unchanged.
  • python/sglang/jit_kernel/eagle_utils.py: Python wrappers for
    build_tree_kernel_efficient and verify_tree_greedy using
    @register_custom_op, following the same pattern as speculative_sampling.py.
  • python/sglang/jit_kernel/tests/test_eagle_utils.py: Tests covering smoke
    runs across batch sizes and tree configurations, accept-all / accept-none
    boundary cases, and bitwise JIT vs AOT cross-validation for both kernels
    (19 tests, all passing).
  • python/sglang/jit_kernel/benchmark/bench_eagle_utils.py:
    triton.testing.perf_report benchmarks for both kernels comparing JIT vs AOT
    across typical EAGLE tree configurations and batch sizes.

Accuracy Tests

python -m pytest python/sglang/jit_kernel/tests/test_eagle_utils.py -v
image

Correctness
image

Benchmarking and Profiling

Performance Benchmark
image

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

…+ verify_tree_greedy)

Port sgl-kernel/csrc/speculative/eagle_utils.cu to the JIT kernel framework:
- csrc/speculative/eagle_utils.cuh: CUDA kernels using TVM FFI TensorView
- eagle_utils.py: Python wrappers with register_custom_op
- tests/test_eagle_utils.py: smoke, boundary, and JIT vs AOT cross-validation tests
- benchmark/bench_eagle_utils.py: perf benchmarks for both kernels
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 eagle_utils kernels, build_tree_kernel_efficient and verify_tree_greedy, into SGLang's Just-In-Time (JIT) compilation system. This strategic shift from Ahead-Of-Time (AOT) compilation significantly improves the framework's portability by eliminating dependencies on pre-compiled sgl-kernel packages and streamlines the development process through faster iteration. The changes encompass adapting the CUDA kernel logic for the JIT environment, providing Python interfaces, and establishing robust testing and benchmarking to validate both functional correctness and performance efficiency.

Highlights

  • JIT Kernel Porting: The eagle_utils kernels, build_tree_kernel_efficient and verify_tree_greedy, have been ported from AOT-compiled functions to the JIT kernel framework, enhancing portability and accelerating development iteration.
  • CUDA Code Adaptation: The underlying CUDA implementations in eagle_utils.cuh were adapted to the JIT environment by replacing PyTorch ATen tensor types with tvm::ffi::TensorView and at::cuda::getCurrentCUDAStream() calls with LaunchKernel::resolve_device(), along with CHECK_* macros with RuntimeCheck.
  • Python Wrappers and Integration: New Python wrappers for the JIT kernels were created in eagle_utils.py, utilizing the @register_custom_op decorator for seamless integration into the SGLang system.
  • Comprehensive Testing: A dedicated test suite (test_eagle_utils.py) was added, covering smoke runs, boundary cases (accept-all/accept-none), and bitwise cross-validation against the existing AOT sgl-kernel implementations to ensure correctness.
  • Performance Benchmarking: Benchmarks (bench_eagle_utils.py) were introduced to compare the performance of the new JIT kernels against their AOT counterparts across typical EAGLE tree configurations and batch sizes.

🧠 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
  • python/sglang/jit_kernel/benchmark/bench_eagle_utils.py
    • Added a new benchmark script to compare the performance of JIT and AOT eagle_utils kernels.
  • python/sglang/jit_kernel/csrc/speculative/eagle_utils.cuh
    • Implemented JIT-compatible C++ CUDA kernels for build_tree_efficient, build_tree_efficient_partial_packed, and VerifyTreeGreedy.
  • python/sglang/jit_kernel/eagle_utils.py
    • Created Python wrappers for the JIT build_tree_kernel_efficient and verify_tree_greedy functions, registering them as custom operations.
  • python/sglang/jit_kernel/tests/test_eagle_utils.py
    • Added a new test file containing smoke tests, boundary case tests, and bitwise cross-validation tests for the JIT eagle_utils kernels.
Activity
  • The author provided a detailed motivation for porting the eagle_utils kernels to the JIT framework.
  • Modifications to the CUDA kernel, Python wrappers, and new test/benchmark files were clearly outlined.
  • Accuracy test results were presented, demonstrating the correctness of the JIT kernels.
  • Performance benchmarking results were included, comparing the JIT and AOT implementations.
  • The author completed a checklist confirming adherence to code formatting, unit testing, documentation, and code style guidelines.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully ports the eagle_utils kernels to the JIT framework, which is a valuable addition for portability and development speed. The implementation correctly adapts the existing AOT kernels. However, there are critical gaps in input validation within the C++ host functions and missing metadata in the Python custom op registration. Specifically, the tree_mask mutation is not declared in the Python wrapper, and the build_tree_kernel_efficient host function lacks the robust type, shape, and device checks present in its counterpart verify_tree_greedy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant