Skip to content
Closed
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
18 changes: 11 additions & 7 deletions docs/source/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,26 @@ instead — `kernels` will then never load an incompatible kernel at all.
## Inspecting Loaded Kernels

[`~kernels.get_loaded_kernels`] returns a snapshot of every kernel that has been loaded
into the current process. Each entry is a [`~kernels.LoadedKernel`] namedtuple with the
imported `module`, the `package_name`, and `repo_infos` (repo id, resolved
revision, and the backend argument that was passed).
into the current process. Each entry is a [`~kernels.LoadedKernel`] dataclass with
the kernel's `metadata`, the imported `module`, and optional `repo_info`
(repository ID and resolved revision).

```python
from kernels import get_kernel, get_loaded_kernels

get_kernel("kernels-community/activation", version=1)

for loaded in get_loaded_kernels():
print(loaded.package_name, loaded.repo_infos)
print(loaded.metadata.name, loaded.repo_info)
for url in loaded.metadata.upstream:
print(url)
```

`repo_infos` is populated only for kernels loaded with [`~kernels.get_kernel`]. Kernels
loaded from a local path ([`~kernels.get_local_kernel`]) or via a lockfile
([`~kernels.get_locked_kernel`], [`~kernels.load_kernel`]) have `repo_infos=None`.
`repo_info` is populated when the kernel's Hub repository is known; otherwise it
is `None`, as for kernels loaded directly from a local path.
`metadata.upstream` is a list of original upstream repository URLs, empty when
none is specified. See the [migration guide](migration.md#018) for the change
from a single URL to a list in `kernels` 0.18.

Browse through different kernels compatible with `kernels` from [here](https://huggingface.co/kernels).

Expand Down
2 changes: 1 addition & 1 deletion docs/source/builder/triton-autotune.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ files are picked up from the kenel's Python source directory, so add `json` to t
[general]
name = "gemm-triton-autotune"
version = 1
edition = 5
edition = 6
license = "Apache-2.0"
backends = ["cuda", "rocm", "xpu"]

Expand Down
10 changes: 6 additions & 4 deletions docs/source/builder/writing-kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ backends = [
]
name = "mykernel"
version = 1
edition = 5
edition = 6

[general.hub]
repo-id = "myorg/mykernel"
Expand Down Expand Up @@ -199,12 +199,14 @@ The following sections enumerate all supported options for `build.toml`.
by the `kernel-builder upload` command to upload the kernel to a version
branch named `v<version>`.
- `edition` (required): the `build.toml` format edition. The current
edition is `5`. Older `build.toml` files can be migrated with
edition is `6`. Older `build.toml` files can be migrated with
`kernel-builder update-build`.
- `backends` (required): a list of supported backends. Must be one or
more of `cpu`, `cuda`, `metal`, `rocm`, or `xpu`.
- `upstream`: Git-compatible URL (passable to `git clone`) of the original
upstream repository where the kernel source code comes from.
- `upstream`: list of Git-compatible URLs (passable to `git clone`) of the original
repositories where the kernel source code comes from. Editions before 6 use a
single URL string; `kernel-builder update-build` converts it to a list. For example:
`upstream = ["https://github.com/org/repo-a", "https://github.com/org/repo-b"]`.
- `source`: Git-compatible URL (passable to `git clone`) of the kernel-builder
formatted source repository. This repository must contain a `build.toml` and
`flake.nix` so that it can be pulled and built with the kernel builder.
Expand Down
5 changes: 5 additions & 0 deletions docs/source/cli-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Python dependencies: -
Backends: cuda, metal
```

The `Upstream` line lists every upstream repository, separated by commas, or
`-` if none is specified. JSON output includes an `upstream` array (empty
when unspecified), including when reading legacy single-string metadata.
The field is omitted when metadata is unavailable.

## See Also

- [kernels versions](cli-versions.md) - List available versions of a kernel
Expand Down
5 changes: 3 additions & 2 deletions docs/source/kernel-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ metadata. Currently the following top-level keys are supported:
installed.
- `license` (`str`, required): the kernel license in. Refer to the
list of [supported license identifiers](https://huggingface.co/docs/hub/repositories-licenses).
- `upstream` (`str`, optional): Git-compatible URL (passable to `git clone`)
of the original upstream repository where the kernel source code comes from.
- `upstream` (`str | list[str]`, optional): Git-compatible URLs (passable to
`git clone`) of the original repositories where the kernel source code comes
from.
- `source` (`str`, optional): Git-compatible URL (passable to `git clone`)
of the kernel-builder formatted source repository (must contain `build.toml`
and `flake.nix`).
Expand Down
33 changes: 33 additions & 0 deletions docs/source/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,36 @@ class FastSiluAndMul(nn.Module):
```

For more information, see the [layer documentation](layers.md).

## 0.18

### Upstream repositories are returned as a list

The `upstream` property of kernel metadata now returns `list[str]` instead of
`str | None`. This is a breaking API change for code that reads
`loaded.metadata.upstream` from the [`~kernels.LoadedKernel`] entries returned by
[`~kernels.get_loaded_kernels`].

A kernel with one upstream repository returns `[url]`; one with no upstream
returns `[]`. Iterate over the list to handle kernels with multiple upstreams:

```python
from kernels import get_loaded_kernels

# Old:
for loaded in get_loaded_kernels():
if loaded.metadata.upstream is not None:
print(loaded.metadata.upstream)

# New:
for loaded in get_loaded_kernels():
for url in loaded.metadata.upstream:
print(url)
```

Replace `upstream is None` checks with `not upstream` to detect an absent
upstream. Code that processes a URL string should now process each URL in the
list.

Existing metadata files with a single URL string, `null`, or no `upstream` field
still load successfully.
6 changes: 5 additions & 1 deletion examples/kernels/cutlass-gemm-tvm-ffi/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/cutlass-gemm/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/gemm-triton-autotune/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ No benchmark available yet.

## Source code

Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}

6 changes: 5 additions & 1 deletion examples/kernels/kernel-deps/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-archs-subset/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-backprop-compile/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-compiler-flags/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-invalid-capability/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ No benchmark available yet.

## Source code

Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}

6 changes: 5 additions & 1 deletion examples/kernels/relu-metal-cpp/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-nki/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-specific-torch/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-torch-bounds/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-torch-stable-abi/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ No benchmark available yet.

## Source code

Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}

6 changes: 5 additions & 1 deletion examples/kernels/relu-tpu/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-triton/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ No benchmark available yet.

## Source code

Source code of this kernel originally comes from {{ upstream }} and it was repurposed for compatibility with `kernels`.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}

6 changes: 5 additions & 1 deletion examples/kernels/relu-tvm-ffi-compiler-flags/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu-tvm-ffi/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/relu/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/silu-and-mul-bad-registration/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
6 changes: 5 additions & 1 deletion examples/kernels/silu-and-mul/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ No benchmark available yet.

## Upstream

The original source code for this kernel comes from {{ upstream }}.
The original source code for this kernel comes from:

{% for url in upstream %}
- {{ url }}
{% endfor %}
{% endif %}
{% if source %}

Expand Down
Loading
Loading