Skip to content

Latest commit

 

History

History
67 lines (39 loc) · 3.55 KB

File metadata and controls

67 lines (39 loc) · 3.55 KB

Contribution Guide

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.

Install SGL-KERNEL-NPU from Source

Fork and clone the repository

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.git

Build from source

Refer to Install SGL-KERNEL-NPU from Source.

Ascend C Kernel Contribution

Steps to add a new Ascend C kernel:

  1. 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.

  2. Expose the interface in include/sgl_kernel_npu_ops.h

  3. Create torch extension in pytorch_extensions.cpp

  4. Update CMakeLists.txt to include new kernel source

Triton Kernel Contribution

Triton kernels are located at sgl_kernel_npu

Development Tips

  • 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));

Run and add unit tests

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.

Format code with pre-commit

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-files
  • pre-commit run --all-files manually 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 main branch. 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!