Welcome to SGL-KERNEL-NPU! We appreciate your interest in contributing. This guide provides a concise overview of how to set up your environment, run tests, build documentation, and open a Pull Request (PR). Whether you’re fixing a small bug or developing a major feature, we encourage following these steps for a smooth contribution process.
SGL-KERNEL-NPU is a kernel library for LLM inference engines, which provides optimized compute primitives (including Ascendc and Triton) especially for engines running on NPU. It has been used by SGLang.
Note: New contributors do not have the write permission to push to the official SGL-KERNEL-NPU repo. Please fork the repository under your GitHub account, then clone your fork locally.
git clone https://github.com/<your_user_name>/sgl-kernel-npu.gitRefer to Install SGL-KERNEL-NPU from Source.
-
Implement the kernel in csrc. You can start by reading the helloworld kernel, a simple example of adding two bf16 vectors. If you are new to this, the Ascend C Kernel Development Guide could also be helpful.
-
Expose the interface in include/sgl_kernel_npu_ops.h
-
Create torch extension in pytorch_extensions.cpp
-
Update CMakeLists.txt to include new kernel source
Triton kernels are located at sgl_kernel_npu
-
How to write schema: Schema reference
// We need def with schema here for torch.compile m.def("helloworld(Tensor x, Tensor y) -> Tensor"); m.impl("helloworld", TORCH_FN(sglang::npu_kernel::helloworld));
If you add a new feature or fix a bug, please add corresponding unit tests test to ensure coverage and prevent regression. SGL-KERNEL-NPU uses Python's built-in unittest framework.
We use pre-commit to maintain consistent code style checks. Before pushing your changes, please run:
pip3 install pre-commit
pre-commit install
pre-commit run --all-filespre-commit run --all-filesmanually runs all configured checks, applying fixes if possible. If it fails the first time, re-run it to ensure lint errors are fully resolved. Make sure your code passes all checks before creating a Pull Request.- Do not commit directly to the
mainbranch. Always create a new branch (e.g.,feature/my-new-feature), push your changes, and open a PR from that branch.
Thank you for your interest in SGL-KERNEL-NPU. Happy coding!