Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
( cd kernels && cargo fmt --all -- --check )
- name: Cargo fmt (kernel-builder)
run: ( cd kernel-builder && cargo fmt --all -- --check )
- name: Cargo fmt (kernels-tool)
run: ( cd kernels-tool && cargo fmt --all -- --check )
- name: Cargo fmt (kernel-port)
run: ( cd kernel-port && cargo fmt --all -- --check )

Expand Down Expand Up @@ -64,6 +66,8 @@ jobs:
( cd kernels && cargo clippy -- -D warnings )
- name: Clippy (kernel-builder)
run: ( cd kernel-builder && cargo clippy -- -D warnings )
- name: Clippy (kernels-tool)
run: ( cd kernels-tool && cargo clippy -- -D warnings )
- name: Clippy (kernel-port)
run: ( cd kernel-port && cargo clippy -- -D warnings )

Expand All @@ -90,5 +94,7 @@ jobs:
run: cargo test -p kernels-common
- name: Test (kernel-builder)
run: cargo test -p hf-kernel-builder
- name: Test (kernels-tool)
run: cargo test -p kernels-tool
- name: Test (kernel-port)
run: cargo test -p kernel-port
4 changes: 3 additions & 1 deletion .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ jobs:
* `kernel-builder`: this is the main user interface for building and uploading kernels,
though it also generates CMake/pyproject files which are used by the NIx builder.
* `kernels`: Python package that can download and load kernels from Hugging Face Hub.
* `kernels-common`: data structures shared by `kernel-builder` and `kernels`.
* `kernels-common`: data structures shared by `kernel-builder`, `kernels-tool` and `kernels`.
* `kernels-tool`: tools that process and validate built kernels (hashing, zipping,
provenance, ABI checks), used by the Nix builder.
* `nix-builder`: Nix code that drives kernel building, also contains Nix derivations for
some dependencies.

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "kernels/rust/**"
- "nix-builder/**"
- "kernels-common/**"
- "kernels-tool/**"
- ".github/workflows/test_e2e.yaml"
workflow_dispatch:
inputs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_kernels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- "docs/**"
- "*.md"
- "kernel-builder/**"
- "kernels-tool/**"
- "nix-builder/**"
workflow_dispatch:

Expand Down
23 changes: 19 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"kernel-builder",
"kernels",
"kernels-common",
"kernels-tool",
"kernel-port",
]
resolver = "2"
Expand Down
55 changes: 0 additions & 55 deletions docs/source/builder-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ This document contains the help content for the `kernel-builder` command-line pr
* [`kernel-builder build-and-upload`↴](#kernel-builder-build-and-upload)
* [`kernel-builder upload`↴](#kernel-builder-upload)
* [`kernel-builder check-config`↴](#kernel-builder-check-config)
* [`kernel-builder check-abi`↴](#kernel-builder-check-abi)
* [`kernel-builder check-builds`↴](#kernel-builder-check-builds)
* [`kernel-builder create-pyproject`↴](#kernel-builder-create-pyproject)
* [`kernel-builder devshell`↴](#kernel-builder-devshell)
* [`kernel-builder list-variants`↴](#kernel-builder-list-variants)
* [`kernel-builder hash`↴](#kernel-builder-hash)
* [`kernel-builder testshell`↴](#kernel-builder-testshell)
* [`kernel-builder update-build`↴](#kernel-builder-update-build)
* [`kernel-builder skills`↴](#kernel-builder-skills)
Expand All @@ -39,12 +36,9 @@ Build Hugging Face Hub kernels
* `build-and-upload` — Build the kernel and upload to Hugging Face Hub
* `upload` — Upload kernel build artifacts to the Hugging Face Hub
* `check-config` — Validate the build.toml file
* `check-abi` — Check the ABI compatibility of a kernel extension
* `check-builds` — Validate kernel builds
* `create-pyproject` — Generate CMake files for a kernel extension build
* `devshell` — Spawn a kernel development shell
* `list-variants` — List build variants
* `hash` — Hash the builds of a kernel
* `testshell` — Spawn a kernel test shell
* `update-build` — Update a `build.toml` to the current format
* `skills` — Install skills for AI coding assistants (Claude, Codex, OpenCode)
Expand Down Expand Up @@ -196,43 +190,6 @@ Validate the build.toml file



## `kernel-builder check-abi`

Check the ABI compatibility of a kernel extension

**Usage:** `kernel-builder check-abi [OPTIONS] [KERNEL_DIR]`

###### **Arguments:**

* `<KERNEL_DIR>` — Directory with kernels

###### **Options:**

* `-m`, `--manylinux <VERSION>` — Manylinux version

Default value: `manylinux_2_28`
* `--macos <VERSION>` — macOS version

Default value: `15.0`
* `-p`, `--python-abi <VERSION>` — Python ABI version

Default value: `3.9`
* `--torch-stable-abi <VERSION>` — Torch stable ABI version



## `kernel-builder check-builds`

Validate kernel builds

**Usage:** `kernel-builder check-builds [KERNEL_DIR]`

###### **Arguments:**

* `<KERNEL_DIR>`



## `kernel-builder create-pyproject`

Generate CMake files for a kernel extension build
Expand Down Expand Up @@ -286,18 +243,6 @@ List build variants



## `kernel-builder hash`

Hash the builds of a kernel

**Usage:** `kernel-builder hash [KERNEL_DIR]`

###### **Arguments:**

* `<KERNEL_DIR>`



## `kernel-builder testshell`

Spawn a kernel test shell
Expand Down
4 changes: 2 additions & 2 deletions docs/source/kernel-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ The ABI3 requirement can be checked with the ABI checker (see below).
### ABI checker

The manylinux_2_28 and Python ABI 3.9 version requirements can be checked with
`kernel-builder check-abi`:
`kernels-tool check-abi`:

```bash
$ kernel-builder check-abi examples/kernels/relu
$ kernels-tool check-abi examples/kernels/relu
🐍 Checking for compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cpu-x86_64-linux/_relu_cpu_30dc0ae_dirty.abi3.so
✅ No compatibility issues found
🐍 Checking for compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cu126-x86_64-linux/_relu_cuda_30dc0ae_dirty.abi3.so
Expand Down
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
mkShell {
nativeBuildInputs = [
kernel-builder
kernels-tool
nodejs # For hf-doc-builder.
pinact
pkg-config
Expand Down Expand Up @@ -264,7 +265,7 @@
formatter = pkgs.nixfmt-tree;

packages = rec {
inherit (buildSet.pkgs) kernel-builder kernel-port;
inherit (buildSet.pkgs) kernel-builder kernels-tool kernel-port;
kernels = buildSet.overrideTorch buildSet.pkgs.python3.pkgs.kernels;

update-build = pkgs.writeShellScriptBin "update-build" ''
Expand Down
4 changes: 0 additions & 4 deletions kernel-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ repository = "https://github.com/huggingface/kernels"

[dependencies]
base32 = "0.5"
kernel-abi-check = { path = "../kernel-abi-check", version = "0.20.0-dev0" }
kernels-common = { path = "../kernels-common", version = "0.20.0-dev0" }
object = "0.36.7"
clap = { version = "4", features = ["derive"] }
clap-markdown = "0.1.5"
clap_complete = "4"
Expand All @@ -25,7 +23,6 @@ minijinja = "2.5"
minijinja-embed = "2.5"
rand = "0.8"
regex = "1"
rustpython-parser = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde-value = "0.7"
Expand All @@ -35,7 +32,6 @@ url = { version = "2", features = ["serde"] }
dirs = "6"
reqwest = { version = "0.13", features = ["blocking"] }
walkdir = "2"
zip = { version = "9.7.0", default-features = false, features = ["deflate-flate2"] }

[build-dependencies]
minijinja-embed = "2.5"
Expand Down
2 changes: 1 addition & 1 deletion kernel-builder/skills/cuda-kernels/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def my_kernel(x: torch.Tensor) -> torch.Tensor:
4. `kernel-builder check-config` passes — `[general]` needs a **dash-separated** `name` (never underscores) and a `license`, plus `[torch]` (binding sources) and `[kernel.<name>]` sections.
5. The kernel directory is a git repository with all files committed (Nix refuses non-git builds).
6. The build succeeds: `nix run .#build-and-copy -L`.
7. ABI compliance passes: `kernel-builder check-abi` (after building).
7. ABI compliance passes: `kernels-tool check-abi` (after building).

## Quick Start

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ output[idx] = from_float(result, (scalar_t*)nullptr);

### 3. Build Errors Mentioning pybind11 / Py_LIMITED_API / abi3

**Problem:** Errors like `pybind11 does not support the limited API`, undefined `PyCFunction` variants, or `kernel-builder check-abi` failures.
**Problem:** Errors like `pybind11 does not support the limited API`, undefined `PyCFunction` variants, or `kernels-tool check-abi` failures.

**Cause:** The kernel uses a disallowed binding pattern — `#include <torch/extension.h>` (which transitively includes pybind11), `PYBIND11_MODULE`, or a hand-written `setup.py` with `torch.utils.cpp_extension.CUDAExtension`. kernel-builder compiles against the Python limited API (ABI3); pybind11 and setuptools extensions cannot be used.

Expand Down
2 changes: 1 addition & 1 deletion kernel-builder/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eyre::Result;

use crate::list_variants::variants;
use crate::nix::{Flake, Nix, NixSubcommand};
use crate::util::check_or_infer_kernel_dir;
use kernels_common::util::check_or_infer_kernel_dir;

fn prepare_build(
kernel_dir: Option<PathBuf>,
Expand Down
2 changes: 1 addition & 1 deletion kernel-builder/src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;

use crate::list_variants::arch_variants;
use crate::nix::{Flake, Nix, NixSubcommand};
use crate::util::check_or_infer_kernel_dir;
use kernels_common::util::check_or_infer_kernel_dir;

/// Validate a variant against the arch variants list.
fn validate_arch_variant(flake: &Flake, variant: &str) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kernel-builder/src/list_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use eyre::Result;

use crate::nix::{Flake, Nix, NixSubcommand};
use crate::util::check_or_infer_kernel_dir;
use kernels_common::util::check_or_infer_kernel_dir;

/// Get the list of variants for a flake.
pub fn variants(flake: &Flake) -> Result<Vec<String>> {
Expand Down
Loading
Loading