Kernel Library for SGLang
Actively maintained. Last release 11 months ago, commits in 26 of the last 26 weeks. A safe choice.
pip install sgl-kernelsgl-kernel
Kernel Library for LLM inference engines
sgl-kernel provides optimized compute primitives for LLM inference engines, enabling efficient inference for large language models and vision-language models through custom kernel operations. It has been used by LightLLM, SGLang and so on.
Installation
Requires torch == 2.9.1
# Latest version
pip3 install sgl-kernel --upgrade
Building from Source
Requires
- CMake ≥3.31,
- Python ≥3.10
- scikit-build-core
- ninja(optional)
Use Makefile to build sgl-kernel
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
- Expose Python interface in