From 096883523a39f876b31469ae875511659a6860c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 13 Jan 2026 08:36:52 +0000 Subject: [PATCH 1/3] Support setting `version` in `build.toml` This change adds the `version` option to the `general` section in `build.toml`. The version will be written to the build metadata and will be used by `kernels upload` to upload builds to a versioned branch. --- build2cmake/src/config/mod.rs | 1 + build2cmake/src/config/v1.rs | 1 + build2cmake/src/config/v2.rs | 1 + build2cmake/src/config/v3.rs | 4 ++++ build2cmake/src/metadata.rs | 2 ++ build2cmake/src/torch/common.rs | 3 ++- docs/writing-kernels.md | 8 ++++++-- 7 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build2cmake/src/config/mod.rs b/build2cmake/src/config/mod.rs index a11f4e97..1078a604 100644 --- a/build2cmake/src/config/mod.rs +++ b/build2cmake/src/config/mod.rs @@ -35,6 +35,7 @@ impl Build { pub struct General { pub name: String, + pub version: Option, /// Hugging Face Hub license identifier. pub license: Option, diff --git a/build2cmake/src/config/v1.rs b/build2cmake/src/config/v1.rs index 5bba9086..56473137 100644 --- a/build2cmake/src/config/v1.rs +++ b/build2cmake/src/config/v1.rs @@ -98,6 +98,7 @@ impl TryFrom for super::Build { Ok(Self { general: super::General { name: build.general.name, + version: None, license: None, backends, hub: None, diff --git a/build2cmake/src/config/v2.rs b/build2cmake/src/config/v2.rs index 86d4dc37..d1b308ae 100644 --- a/build2cmake/src/config/v2.rs +++ b/build2cmake/src/config/v2.rs @@ -163,6 +163,7 @@ impl General { super::General { name: general.name, + version: None, license: None, backends, cuda, diff --git a/build2cmake/src/config/v3.rs b/build2cmake/src/config/v3.rs index bf3409ee..f2757c80 100644 --- a/build2cmake/src/config/v3.rs +++ b/build2cmake/src/config/v3.rs @@ -21,6 +21,8 @@ pub struct Build { pub struct General { pub name: String, + pub version: Option, + pub license: Option, pub backends: Vec, @@ -143,6 +145,7 @@ impl From for super::General { fn from(general: General) -> Self { Self { name: general.name, + version: general.version, license: general.license, backends: general.backends.into_iter().map(Into::into).collect(), cuda: general.cuda.map(Into::into), @@ -296,6 +299,7 @@ impl From for General { fn from(general: super::General) -> Self { Self { name: general.name, + version: general.version, license: general.license, backends: general.backends.into_iter().map(Into::into).collect(), cuda: general.cuda.map(Into::into), diff --git a/build2cmake/src/metadata.rs b/build2cmake/src/metadata.rs index d9f4abbc..c8635d90 100644 --- a/build2cmake/src/metadata.rs +++ b/build2cmake/src/metadata.rs @@ -3,6 +3,8 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct Metadata { + #[serde(skip_serializing_if = "Option::is_none")] + pub version: Option, #[serde(skip_serializing_if = "Option::is_none")] pub license: Option, pub python_depends: Vec, diff --git a/build2cmake/src/torch/common.rs b/build2cmake/src/torch/common.rs index e2ba4dcd..5c4c995d 100644 --- a/build2cmake/src/torch/common.rs +++ b/build2cmake/src/torch/common.rs @@ -43,11 +43,12 @@ pub fn write_metadata(backend: Backend, general: &General, file_set: &mut FileSe .collect::>>()?; let metadata = Metadata { + version: general.version, license: general.license.clone(), python_depends, }; - serde_json::to_writer(writer, &metadata)?; + serde_json::to_writer_pretty(writer, &metadata)?; Ok(()) } diff --git a/docs/writing-kernels.md b/docs/writing-kernels.md index d0223f8b..a3be7e9a 100644 --- a/docs/writing-kernels.md +++ b/docs/writing-kernels.md @@ -93,6 +93,10 @@ depends = [ "torch" ] - `name` (required): the name of the kernel. The Python code for a Torch extension must be stored in `torch-ext/`. +- `version` (int, **experimental**): the major version of the kernel. + The version is written to the kernel's `metadata.json` and is used + by the `kernels upload` command to upload the kernel to a version + branch named `v`. - `backends` (required): a list of supported backends. Must be one or more of `cpu`, `cuda`, `metal`, `rocm`, or `xpu`. - `python-depends` (**experimental**): a list of additional Python dependencies @@ -124,9 +128,9 @@ options: - `include` (optional): include directories relative to the project root. Default: `[]`. - `maxver` (optional): only build for this Torch version and earlier. Use cautiously, since this option produces - non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md). + non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md). - `minver` (optional): only build for this Torch version and later. Use cautiously, since this option produces - non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md). + non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md). ### `kernel.` From d93b72ddba467ae9d87441ca2da5a5831b31c57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 13 Jan 2026 14:29:15 +0000 Subject: [PATCH 2/3] `build-and-upload`: only add branch option when specified This allows version-based uploading to kick in when no branch is specified. --- lib/gen-flake-outputs.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gen-flake-outputs.nix b/lib/gen-flake-outputs.nix index 64e312fc..d50a5035 100644 --- a/lib/gen-flake-outputs.nix +++ b/lib/gen-flake-outputs.nix @@ -197,12 +197,13 @@ in "hub" "repo-id" ] "kernels-community/${buildToml.general.name}" buildToml; - branch = lib.attrByPath [ "general" "hub" "branch" ] "main" buildToml; + branch = lib.attrByPath [ "general" "hub" "branch" ] null buildToml; + branchOpt = lib.optionalString (branch != null) "--branch ${branch}"; # `kernels upload` fails when there are no build variants to upload. # However, we do not want this command to error out in that case, so # only insert the upload command when there is something to upload. uploadStr = lib.optionalString (applicableBuildSets != [ ]) '' - ${pkgs.python3.pkgs.kernels}/bin/kernels upload --repo-id ${repo_id} --branch ${branch} ${bundle} + ${pkgs.python3.pkgs.kernels}/bin/kernels upload --repo-id ${repo_id} ${branchOpt} ${bundle} ''; in writeScriptBin "build-and-upload" '' From 0798703f523d071b416fb7d5d8450399a73a8eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 13 Jan 2026 14:30:17 +0000 Subject: [PATCH 3/3] python3Packages.kernels: use `version-option` branch --- overlay.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/overlay.nix b/overlay.nix index cb1879c1..b1b59c71 100644 --- a/overlay.nix +++ b/overlay.nix @@ -95,8 +95,8 @@ in src = final.fetchFromGitHub { owner = "huggingface"; repo = "kernels"; - tag = "v${version}"; - hash = "sha256-kTBGje4oMiRqN/m98rvg3r3gqoV1Tg5APleRZbPlziY="; + rev = "ff4de4eafdfe5c2346b252cf09c6c412e13f3135"; + hash = "sha256-hn9PZsGnd2BsBejjDQXVKye8abnS5K9jWga7YVkvXOg="; }; });