diff --git a/.github/workflows/build_kernel.yaml b/.github/workflows/build_kernel.yaml index eeee5f25..3a8bce39 100644 --- a/.github/workflows/build_kernel.yaml +++ b/.github/workflows/build_kernel.yaml @@ -24,7 +24,7 @@ jobs: group: ${{ matrix.runner }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 with: extra-conf: | max-jobs = 8 diff --git a/.github/workflows/build_kernel_rocm.yaml b/.github/workflows/build_kernel_rocm.yaml index 996ed11c..6c3c54d8 100644 --- a/.github/workflows/build_kernel_rocm.yaml +++ b/.github/workflows/build_kernel_rocm.yaml @@ -17,7 +17,7 @@ jobs: group: aws-highmemory-32-plus-nix steps: - uses: actions/checkout@v6 - - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 with: extra-conf: | max-jobs = 4 diff --git a/.github/workflows/build_kernel_xpu.yaml b/.github/workflows/build_kernel_xpu.yaml index f98e1dbe..09853596 100644 --- a/.github/workflows/build_kernel_xpu.yaml +++ b/.github/workflows/build_kernel_xpu.yaml @@ -17,7 +17,7 @@ jobs: group: aws-highmemory-32-plus-nix steps: - uses: actions/checkout@v6 - - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 with: extra-conf: | max-jobs = 4 diff --git a/.github/workflows/nix_checks.yml b/.github/workflows/nix_checks.yml new file mode 100644 index 00000000..c45be796 --- /dev/null +++ b/.github/workflows/nix_checks.yml @@ -0,0 +1,37 @@ +name: "Nix checks" +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, synchronize, reopened] # trigger on PRs + workflow_dispatch: + +jobs: + build: + name: Nix checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 + with: + extra-conf: | + max-jobs = 4 + cores = 12 + sandbox-fallback = false + - uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17 + with: + name: huggingface + env: + USER: runner + - name: Check formatting + run: nix fmt -- --ci + - name: Nix checks + run: nix build .\#checks.x86_64-linux.default + - name: Test kernel card generation + run: | + ( + cd examples/kernels/silu-and-mul + nix build -L . + test -e result/CARD.md + ) diff --git a/.github/workflows/nix_fmt.yaml b/.github/workflows/nix_fmt.yaml deleted file mode 100644 index 807fc9a3..00000000 --- a/.github/workflows/nix_fmt.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: "Nix checks" -on: - push: - branches: [main] - pull_request: - branches: [main] - types: [opened, synchronize, reopened] # trigger on PRs - workflow_dispatch: - -jobs: - build: - name: Nix checks - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: cachix/install-nix-action@v31 - with: - nix_path: nixpkgs=channel:nixos-unstable - - name: Check formatting - run: nix fmt -- --ci - - name: Nix checks - run: nix build .\#checks.x86_64-linux.default diff --git a/.github/workflows/test_e2e.yaml b/.github/workflows/test_e2e.yaml index da8ae30e..99d8cef9 100644 --- a/.github/workflows/test_e2e.yaml +++ b/.github/workflows/test_e2e.yaml @@ -32,7 +32,7 @@ jobs: variant: ${{ steps.variant.outputs.name }} steps: - uses: actions/checkout@v6 - - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 with: extra-conf: | max-jobs = 8 diff --git a/.github/workflows/test_extra_commands.yaml b/.github/workflows/test_extra_commands.yaml index 8fe09352..99d78aa4 100644 --- a/.github/workflows/test_extra_commands.yaml +++ b/.github/workflows/test_extra_commands.yaml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 with: extra-conf: | max-jobs = 4 diff --git a/examples/kernels/cutlass-gemm-tvm-ffi/CARD.md b/examples/kernels/cutlass-gemm-tvm-ffi/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/cutlass-gemm-tvm-ffi/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/cutlass-gemm-tvm-ffi/build.toml b/examples/kernels/cutlass-gemm-tvm-ffi/build.toml index e6d5087d..2537338c 100644 --- a/examples/kernels/cutlass-gemm-tvm-ffi/build.toml +++ b/examples/kernels/cutlass-gemm-tvm-ffi/build.toml @@ -5,6 +5,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/cutlass-gemm-tvm-ffi" + [tvm-ffi] src = [ "tvm-ffi-ext/tvm_ffi_binding.cpp", diff --git a/examples/kernels/cutlass-gemm/CARD.md b/examples/kernels/cutlass-gemm/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/cutlass-gemm/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/cutlass-gemm/build.toml b/examples/kernels/cutlass-gemm/build.toml index 250dd86b..7fcf90ae 100644 --- a/examples/kernels/cutlass-gemm/build.toml +++ b/examples/kernels/cutlass-gemm/build.toml @@ -5,6 +5,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/cutlass-gemm" + [torch] src = [ "torch-ext/torch_binding.cpp", @@ -26,4 +29,3 @@ depends = [ "sycl_tla", ] src = ["gemm_sycl.cpp"] - diff --git a/examples/kernels/extra-data/CARD.md b/examples/kernels/extra-data/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/extra-data/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/extra-data/build.toml b/examples/kernels/extra-data/build.toml index 391b3043..566edbb3 100644 --- a/examples/kernels/extra-data/build.toml +++ b/examples/kernels/extra-data/build.toml @@ -8,6 +8,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/extra-data" + [torch] src = [ "torch-ext/torch_binding.cpp", diff --git a/examples/kernels/relu-backprop-compile/CARD.md b/examples/kernels/relu-backprop-compile/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-backprop-compile/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-backprop-compile/build.toml b/examples/kernels/relu-backprop-compile/build.toml index 6de49b78..402684bb 100644 --- a/examples/kernels/relu-backprop-compile/build.toml +++ b/examples/kernels/relu-backprop-compile/build.toml @@ -5,6 +5,9 @@ backends = [ "rocm", ] +[general.hub] +repo-id = "kernels-test/relu-backprop-compile" + [torch] src = [ "torch-ext/torch_binding.cpp", diff --git a/examples/kernels/relu-compiler-flags/CARD.md b/examples/kernels/relu-compiler-flags/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-compiler-flags/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-compiler-flags/build.toml b/examples/kernels/relu-compiler-flags/build.toml index b358d67f..00adf665 100644 --- a/examples/kernels/relu-compiler-flags/build.toml +++ b/examples/kernels/relu-compiler-flags/build.toml @@ -6,6 +6,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/relu-compiler-flags" + [torch] src = ["torch-ext/torch_binding.cpp", "torch-ext/torch_binding.h"] diff --git a/examples/kernels/relu-metal-cpp/CARD.md b/examples/kernels/relu-metal-cpp/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-metal-cpp/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-metal-cpp/build.toml b/examples/kernels/relu-metal-cpp/build.toml index 8cf012bc..aa5d4ec5 100644 --- a/examples/kernels/relu-metal-cpp/build.toml +++ b/examples/kernels/relu-metal-cpp/build.toml @@ -2,6 +2,9 @@ name = "relu" backends = ["metal"] +[general.hub] +repo-id = "kernels-test/relu-metal-cpp" + [torch] src = [ "torch-ext/torch_binding.cpp", @@ -17,4 +20,4 @@ src = [ "relu/relu_cpp.metal", "relu/common.h", ] -depends = [ "torch", "metal-cpp" ] \ No newline at end of file +depends = [ "torch", "metal-cpp" ] diff --git a/examples/kernels/relu-nki/CARD.md b/examples/kernels/relu-nki/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-nki/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-nki/build.toml b/examples/kernels/relu-nki/build.toml index 70e4ef7e..86f2c106 100644 --- a/examples/kernels/relu-nki/build.toml +++ b/examples/kernels/relu-nki/build.toml @@ -5,5 +5,8 @@ backends = [ "neuron", ] +[general.hub] +repo-id = "kernels-test/relu-nki" + [general.neuron] python-depends = ["nki"] diff --git a/examples/kernels/relu-specific-torch/CARD.md b/examples/kernels/relu-specific-torch/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-specific-torch/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-specific-torch/build.toml b/examples/kernels/relu-specific-torch/build.toml index 191c4081..cb0a4c7b 100644 --- a/examples/kernels/relu-specific-torch/build.toml +++ b/examples/kernels/relu-specific-torch/build.toml @@ -5,6 +5,9 @@ backends = [ "rocm", ] +[general.hub] +repo-id = "kernels-test/relu-specific-torch" + [torch] src = [ "torch-ext/torch_binding.cpp", diff --git a/examples/kernels/relu-torch-bounds/CARD.md b/examples/kernels/relu-torch-bounds/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-torch-bounds/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-torch-bounds/build.toml b/examples/kernels/relu-torch-bounds/build.toml index fcb0ba3d..7d621e34 100644 --- a/examples/kernels/relu-torch-bounds/build.toml +++ b/examples/kernels/relu-torch-bounds/build.toml @@ -5,6 +5,9 @@ backends = [ "rocm", ] +[general.hub] +repo-id = "kernels-test/relu-torch-bounds" + [torch] minver = "2.10" maxver = "2.10" diff --git a/examples/kernels/relu-tvm-ffi/CARD.md b/examples/kernels/relu-tvm-ffi/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu-tvm-ffi/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu-tvm-ffi/build.toml b/examples/kernels/relu-tvm-ffi/build.toml index 49eb4b82..c93278f5 100644 --- a/examples/kernels/relu-tvm-ffi/build.toml +++ b/examples/kernels/relu-tvm-ffi/build.toml @@ -8,6 +8,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/relu-tvm-ffi" + [tvm-ffi] src = [ "tvm-ffi-ext/tvm_ffi_binding.cpp", diff --git a/examples/kernels/relu/CARD.md b/examples/kernels/relu/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/relu/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/relu/build.toml b/examples/kernels/relu/build.toml index 3627027c..51d8a9be 100644 --- a/examples/kernels/relu/build.toml +++ b/examples/kernels/relu/build.toml @@ -8,6 +8,9 @@ backends = [ "xpu", ] +[general.hub] +repo-id = "kernels-test/relu" + [torch] src = [ "torch-ext/torch_binding.cpp", diff --git a/examples/kernels/silu-and-mul/CARD.md b/examples/kernels/silu-and-mul/CARD.md new file mode 100644 index 00000000..010023b1 --- /dev/null +++ b/examples/kernels/silu-and-mul/CARD.md @@ -0,0 +1,48 @@ +--- +library_name: kernels +{% if license %}license: {{ license }} +{% endif %}--- + +This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. + +## How to use +{% if functions %} + +```python +# make sure `kernels` is installed: `pip install -U kernels` +from kernels import get_kernel + +kernel_module = get_kernel("{{ repo_id }}") +{{ functions[0] }} = kernel_module.{{ functions[0] }} + +{{ functions[0] }}(...) +``` +{% else %} + +Usage example not available. +{% endif %} + +## Available functions +{% if functions %} +{% for func in functions %} +- `{{ func }}` +{% endfor %} +{% else %} + +Function list not available. +{% endif %} + +## Benchmarks +{% if has_benchmark %} + +Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`. +{% else %} + +No benchmark available yet. +{% endif %} +{% if upstream %} + +## Source code + +Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`. +{% endif %} diff --git a/examples/kernels/silu-and-mul/build.toml b/examples/kernels/silu-and-mul/build.toml index 7f022ef5..49708d96 100644 --- a/examples/kernels/silu-and-mul/build.toml +++ b/examples/kernels/silu-and-mul/build.toml @@ -8,3 +8,6 @@ backends = [ "rocm", "xpu", ] + +[general.hub] +repo-id = "kernels-tests/silu-and-mul" diff --git a/kernel-builder/src/build.rs b/kernel-builder/src/build.rs index a10d04d5..b8c19fbc 100644 --- a/kernel-builder/src/build.rs +++ b/kernel-builder/src/build.rs @@ -4,8 +4,7 @@ use eyre::Result; use crate::list_variants::variants; use crate::nix::{Flake, Nix, NixSubcommand}; -use crate::pyproject::write_card; -use crate::util::{check_or_infer_kernel_dir, parse_build}; +use crate::util::check_or_infer_kernel_dir; fn prepare_build( kernel_dir: Option, @@ -16,12 +15,6 @@ fn prepare_build( ) -> Result<(Flake, Option, Nix)> { let kernel_dir = check_or_infer_kernel_dir(kernel_dir)?; - if let Ok(build) = parse_build(&kernel_dir) { - if let Err(e) = write_card(&build, &kernel_dir) { - eprintln!("Warning: cannot generate CARD.md: {e}"); - } - } - let flake = Flake::from_path(kernel_dir)?; if let Some(ref variant) = variant { diff --git a/kernel-builder/src/pyproject/card.rs b/kernel-builder/src/card.rs similarity index 79% rename from kernel-builder/src/pyproject/card.rs rename to kernel-builder/src/card.rs index 0e2d25a5..1b99a475 100644 --- a/kernel-builder/src/pyproject/card.rs +++ b/kernel-builder/src/card.rs @@ -1,4 +1,8 @@ -use std::{fs, path::Path}; +use std::{ + fs, + io::{self, Write}, + path::{Path, PathBuf}, +}; use eyre::{bail, Context, Result}; use minijinja::{context, Environment}; @@ -6,6 +10,8 @@ use rustpython_parser::{ast, Parse}; use kernels_data::config::Build; +use crate::util::{check_or_infer_kernel_dir, parse_build}; + fn extract_functions(kernel_dir: &Path, module_name: &str) -> Option> { let init_path = kernel_dir .join("torch-ext") @@ -49,7 +55,7 @@ fn extract_functions(kernel_dir: &Path, module_name: &str) -> Option None } -pub fn write_card(build: &Build, kernel_dir: &Path) -> Result<()> { +fn render_card(build: &Build, kernel_dir: &Path) -> Result { let card_template_path = kernel_dir.join("CARD.md"); if !card_template_path.exists() { bail!( @@ -66,13 +72,14 @@ pub fn write_card(build: &Build, kernel_dir: &Path) -> Result<()> { env.add_template_owned("card", template_content) .wrap_err("Cannot load card template")?; - let repo_id = build.repo_id().unwrap_or("{repo_id}"); + let repo_id = build.repo_id().ok_or(eyre::eyre!( + "Cannot fill card template because `repo-id` is not specified in `[general.hub]`" + ))?; let module_name = build.general.name.python_name(); let functions = extract_functions(kernel_dir, &module_name); let has_benchmark = kernel_dir.join("benchmarks").join("benchmark.py").exists(); - let content = env - .get_template("card") + env.get_template("card") .wrap_err("Cannot get card template")? .render(context! { repo_id => repo_id, @@ -81,17 +88,27 @@ pub fn write_card(build: &Build, kernel_dir: &Path) -> Result<()> { upstream => build.general.upstream.as_ref().map(|u| u.to_string()), license => build.general.license.clone(), }) - .wrap_err("Cannot render card template")?; + .wrap_err("Cannot render card template") +} - let build_dir = kernel_dir.join("build"); - fs::create_dir_all(&build_dir) - .wrap_err_with(|| format!("Cannot create directory `{}`", build_dir.display()))?; +pub fn fill_card(kernel_dir: Option, output: Option) -> Result<()> { + let kernel_dir = check_or_infer_kernel_dir(kernel_dir)?; + let build = parse_build(&kernel_dir)?; + let content = render_card(&build, &kernel_dir)?; - let card_path = build_dir.join("CARD.md"); - fs::write(&card_path, content) - .wrap_err_with(|| format!("Cannot write `{}`", card_path.display()))?; + match output { + Some(path) => { + fs::write(&path, &content) + .wrap_err_with(|| format!("Cannot write `{}`", path.display()))?; + eprintln!("Generated {}", path.display()); + } + None => { + io::stdout() + .write_all(content.as_bytes()) + .wrap_err("Cannot write to stdout")?; + } + } - eprintln!("Generated {}", card_path.display()); Ok(()) } diff --git a/kernel-builder/src/main.rs b/kernel-builder/src/main.rs index aa1dbbbe..16282d4d 100644 --- a/kernel-builder/src/main.rs +++ b/kernel-builder/src/main.rs @@ -2,6 +2,8 @@ use std::fs::File; use std::io::{BufWriter, Write}; use std::path::PathBuf; +mod card; + use clap::{Args, CommandFactory, Parser, Subcommand}; use clap_complete::Shell; use eyre::{Context, Result}; @@ -158,6 +160,18 @@ enum Commands { nix_args: NixArgs, }, + /// Render the CARD.md template for a kernel. + #[command(hide = true)] + FillCard { + /// Kernel source directory (current directory when not specified). + #[arg(value_name = "KERNEL_DIR")] + kernel_dir: Option, + + /// File to write the rendered card to (defaults to stdout). + #[arg(value_name = "OUTPUT")] + output: Option, + }, + /// List build variants. ListVariants { #[arg(name = "KERNEL_DIR")] @@ -365,6 +379,7 @@ fn main() -> Result<()> { force, } => skills::add_skill(skill, claude, codex, opencode, global, dest, force), }, + Commands::FillCard { kernel_dir, output } => card::fill_card(kernel_dir, output), Commands::CleanPyproject { kernel_dir, target_dir, diff --git a/kernel-builder/src/pyproject/mod.rs b/kernel-builder/src/pyproject/mod.rs index 16de0376..ad0d1a6a 100644 --- a/kernel-builder/src/pyproject/mod.rs +++ b/kernel-builder/src/pyproject/mod.rs @@ -10,7 +10,6 @@ use minijinja::Environment; use crate::util::{check_or_infer_kernel_dir, check_or_infer_target_dir, parse_build}; -mod card; pub(crate) mod common; pub mod deps; pub mod fileset; @@ -19,7 +18,6 @@ mod ops_identifier; mod torch; mod tvm_ffi; -pub use card::write_card; pub use fileset::FileSet; pub use kernels_data::metadata::parse_metadata; diff --git a/nix-builder/lib/build.nix b/nix-builder/lib/build.nix index ece493ec..a5c73b69 100644 --- a/nix-builder/lib/build.nix +++ b/nix-builder/lib/build.nix @@ -180,7 +180,6 @@ rec { buildSets, }: let - # We just need to get any nixpkgs for use by the path join. extensions = mkDistTorchExtensions { inherit buildSets @@ -205,6 +204,12 @@ rec { import ./join-paths { inherit pkgs contents; name = "torch-ext-bundle"; + # Fill card iff we build any variants. + postInstall = lib.optionalString (buildSets != [ ]) '' + if [ -f "${path}/CARD.md" ]; then + ${(builtins.head buildSets).pkgs.kernel-builder}/bin/kernel-builder fill-card ${path} $out/CARD.md + fi + ''; }; # Get a development shell with the extension in PYTHONPATH. Handy diff --git a/nix-builder/lib/join-paths/default.nix b/nix-builder/lib/join-paths/default.nix index 3fcad0d9..f29c0648 100644 --- a/nix-builder/lib/join-paths/default.nix +++ b/nix-builder/lib/join-paths/default.nix @@ -8,6 +8,8 @@ args@{ preferLocalBuild ? true, allowSubstitutes ? false, + + postInstall ? "", }: let inherit (pkgs) lib; @@ -23,4 +25,6 @@ let mkdir -p ${placeholder "out"} ''; in -pkgs.runCommand name args_ (prelude + lib.concatStringsSep "\n" (builtins.map copyPkg contents)) +pkgs.runCommand name args_ ( + prelude + lib.concatStringsSep "\n" (builtins.map copyPkg contents) + postInstall +)