Skip to content

[FEATURE SUPPORT] Add HuggingFace Kernel Hub support#276

Merged
LoserCheems merged 7 commits intomainfrom
support-kernels
Apr 28, 2026
Merged

[FEATURE SUPPORT] Add HuggingFace Kernel Hub support#276
LoserCheems merged 7 commits intomainfrom
support-kernels

Conversation

@LoserCheems
Copy link
Copy Markdown
Collaborator

Summary

  • Add support for publishing Flash Sparse Attention Triton kernels to HuggingFace Kernel Hub, enabling users to load kernels directly via
    get_kernel() without installing the full package.

Design

  • A build script (scripts/build_hf_kernels.py) generates a self-contained kernel package under huggingface_kernels/, rewriting absolute
    imports to relative imports and producing all required config files (build.toml, flake.nix, CARD.md).
  • The package is built and uploaded using kernel-builder from HuggingFace, which uses Nix for reproducible sandboxed builds.
  • Alternative considered: manual packaging without kernel-builder. Rejected because kernel-builder handles ABI compatibility across
    CUDA/PyTorch versions automatically.

Changes

  • scripts/build_hf_kernels.py — New script to generate the HuggingFace kernel package with import rewriting, config generation, and compliance
    checks.
  • README.md, README_zh.md — Added HuggingFace Kernel usage section under Installation.
  • docs/huggingface_kernels_guide.md — Full build & publish guide.
  • mkdocs.yml — Added guide to docs navigation.

Implementation Notes

  • The Nix binary cache address is huggingface.cachix.org (not huggingface-kernels.cachix.org).
  • kernel-builder build-and-upload may fail with 403 if the repo already exists. The recommended workflow is build-and-copy followed by upload
    --repo-type model.
  • NIX_CONFIG can only be exported once; multiple exports overwrite each other.

Tests

  • scripts/test_hf_kernel.py validates loading from Hub and runs dense forward, sparse forward, and dense decode.
  • huggingface_kernels/tests/test_flash_attn.py is generated by the build script for kernel-builder's CI.
  • All 12 public functions verified present in the generated init.py.

Docs

  • docs/huggingface_kernels_guide.md — Build & publish guide.
  • README.md / README_zh.md — Usage examples added.
  • mkdocs.yml — Navigation updated.

@LoserCheems LoserCheems merged commit 6288fc0 into main Apr 28, 2026
1 check passed
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