Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit 2997c77

Browse files
authored
Support setting version in build.toml (#342)
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.
1 parent f6a2c44 commit 2997c77

9 files changed

Lines changed: 22 additions & 7 deletions

File tree

build2cmake/src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl Build {
3535

3636
pub struct General {
3737
pub name: String,
38+
pub version: Option<usize>,
3839

3940
/// Hugging Face Hub license identifier.
4041
pub license: Option<String>,

build2cmake/src/config/v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl TryFrom<Build> for super::Build {
9898
Ok(Self {
9999
general: super::General {
100100
name: build.general.name,
101+
version: None,
101102
license: None,
102103
backends,
103104
hub: None,

build2cmake/src/config/v2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl General {
163163

164164
super::General {
165165
name: general.name,
166+
version: None,
166167
license: None,
167168
backends,
168169
cuda,

build2cmake/src/config/v3.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct Build {
2121
pub struct General {
2222
pub name: String,
2323

24+
pub version: Option<usize>,
25+
2426
pub license: Option<String>,
2527

2628
pub backends: Vec<Backend>,
@@ -143,6 +145,7 @@ impl From<General> for super::General {
143145
fn from(general: General) -> Self {
144146
Self {
145147
name: general.name,
148+
version: general.version,
146149
license: general.license,
147150
backends: general.backends.into_iter().map(Into::into).collect(),
148151
cuda: general.cuda.map(Into::into),
@@ -296,6 +299,7 @@ impl From<super::General> for General {
296299
fn from(general: super::General) -> Self {
297300
Self {
298301
name: general.name,
302+
version: general.version,
299303
license: general.license,
300304
backends: general.backends.into_iter().map(Into::into).collect(),
301305
cuda: general.cuda.map(Into::into),

build2cmake/src/metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use serde::{Deserialize, Serialize};
33
#[derive(Debug, Deserialize, Serialize)]
44
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
55
pub struct Metadata {
6+
#[serde(skip_serializing_if = "Option::is_none")]
7+
pub version: Option<usize>,
68
#[serde(skip_serializing_if = "Option::is_none")]
79
pub license: Option<String>,
810
pub python_depends: Vec<String>,

build2cmake/src/torch/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ pub fn write_metadata(backend: Backend, general: &General, file_set: &mut FileSe
4343
.collect::<Result<Vec<_>>>()?;
4444

4545
let metadata = Metadata {
46+
version: general.version,
4647
license: general.license.clone(),
4748
python_depends,
4849
};
4950

50-
serde_json::to_writer(writer, &metadata)?;
51+
serde_json::to_writer_pretty(writer, &metadata)?;
5152

5253
Ok(())
5354
}

docs/writing-kernels.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ depends = [ "torch" ]
9393

9494
- `name` (required): the name of the kernel. The Python code for a Torch
9595
extension must be stored in `torch-ext/<name>`.
96+
- `version` (int, **experimental**): the major version of the kernel.
97+
The version is written to the kernel's `metadata.json` and is used
98+
by the `kernels upload` command to upload the kernel to a version
99+
branch named `v<version>`.
96100
- `backends` (required): a list of supported backends. Must be one or
97101
more of `cpu`, `cuda`, `metal`, `rocm`, or `xpu`.
98102
- `python-depends` (**experimental**): a list of additional Python dependencies
@@ -124,9 +128,9 @@ options:
124128
- `include` (optional): include directories relative to the project root.
125129
Default: `[]`.
126130
- `maxver` (optional): only build for this Torch version and earlier. Use cautiously, since this option produces
127-
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
131+
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
128132
- `minver` (optional): only build for this Torch version and later. Use cautiously, since this option produces
129-
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
133+
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
130134

131135
### `kernel.<name>`
132136

lib/gen-flake-outputs.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ in
197197
"hub"
198198
"repo-id"
199199
] "kernels-community/${buildToml.general.name}" buildToml;
200-
branch = lib.attrByPath [ "general" "hub" "branch" ] "main" buildToml;
200+
branch = lib.attrByPath [ "general" "hub" "branch" ] null buildToml;
201+
branchOpt = lib.optionalString (branch != null) "--branch ${branch}";
201202
# `kernels upload` fails when there are no build variants to upload.
202203
# However, we do not want this command to error out in that case, so
203204
# only insert the upload command when there is something to upload.
204205
uploadStr = lib.optionalString (applicableBuildSets != [ ]) ''
205-
${pkgs.python3.pkgs.kernels}/bin/kernels upload --repo-id ${repo_id} --branch ${branch} ${bundle}
206+
${pkgs.python3.pkgs.kernels}/bin/kernels upload --repo-id ${repo_id} ${branchOpt} ${bundle}
206207
'';
207208
in
208209
writeScriptBin "build-and-upload" ''

overlay.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ in
9595
src = final.fetchFromGitHub {
9696
owner = "huggingface";
9797
repo = "kernels";
98-
tag = "v${version}";
99-
hash = "sha256-kTBGje4oMiRqN/m98rvg3r3gqoV1Tg5APleRZbPlziY=";
98+
rev = "ff4de4eafdfe5c2346b252cf09c6c412e13f3135";
99+
hash = "sha256-hn9PZsGnd2BsBejjDQXVKye8abnS5K9jWga7YVkvXOg=";
100100
};
101101
});
102102

0 commit comments

Comments
 (0)