Kernel Library for SGLang
Actively maintained. Last release 2 weeks ago, commits in 26 of the last 26 weeks. A safe choice.
pip install sglang-kernelsglang-kernel (prior sgl-kernel)
Kernel Library for LLM inference engines
sglang-kernel provides optimized compute primitives for LLM inference engines, enabling efficient inference for large language models and vision-language models through custom kernel operations. The source tree lives under the python/sglang/kernels/aot/ directory and the Python import path remains sgl_kernel.
Installation
Requires torch == 2.14.1
# Latest version
pip3 install sglang-kernel --upgrade
Building from Source
Requires
- CMake ≥3.31,
- Python ≥3.11
- scikit-build-core
- ninja(optional)
Use Makefile to build from the sgl-kernel source tree
make build
Limit build resource usage (CPU / parallelism)
By default, make build uses all available CPU cores. You can override build parallelism and NVCC compile threads:
# Limit parallel jobs (controls both make and cmake parallelism)
make build MAX_JOBS=2
# Additionally limit NVCC internal threads (reduces CPU and peak memory)
make build MAX_JOBS=2 CMAKE_ARGS="-DSGL_KERNEL_COMPILE_THREADS=1"
Contribution
Steps to add a new kernel:
- Implement the kernel in csrc
- Expose the interface in include/sgl_kernel_ops.h
- Create torch extension in csrc/common_extension.cc
- Update CMakeLists.txt to include new CUDA source