Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.
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
27 changes: 27 additions & 0 deletions .github/workflows/test_extra_commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Test kernel flake commands"
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, synchronize, reopened] # trigger on PRs
workflow_dispatch:

jobs:
build:
name: Build kernel
runs-on:
group: aws-g6-12xlarge-plus
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v14
with:
name: huggingface
#authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
env:
USER: github_runner
- name: Test nix run .#kernels
run: ( cd examples/relu ; nix run .#kernels -- lock ../../tests/run-kernels )
98 changes: 61 additions & 37 deletions lib/gen-flake-outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,29 @@ let

# Enrich the build configs with generic attributes for framework
# order/version. Also make bundleBuild attr explicit.
buildConfigs = map (
buildSets = map (
set:
let
inherit (set) buildConfig;
in
buildConfig
set
// {
bundleBuild = buildConfig.bundleBuild or false;
frameworkOrder = if buildConfig ? cudaVersion then 0 else 1;
frameworkVersion =
buildConfig.cudaVersion or buildConfig.rocmVersion or buildConfig.xpuVersion or "0.0";
buildConfig =

buildConfig // {
bundleBuild = buildConfig.bundleBuild or false;
frameworkOrder = if buildConfig ? cudaVersion then 0 else 1;
frameworkVersion =
buildConfig.cudaVersion or buildConfig.rocmVersion or buildConfig.xpuVersion or "0.0";
};
}
) (build.applicableBuildSets path);
configCompare =
a: b:
setA: setB:
let
a = setA.buildConfig;
b = setB.buildConfig;
in
if a.bundleBuild != b.bundleBuild then
a.bundleBuild
else if a.frameworkOrder != b.frameworkOrder then
Expand All @@ -69,14 +77,14 @@ let
builtins.compareVersions a.torchVersion b.torchVersion > 0
else
builtins.compareVersions a.frameworkVersion b.frameworkVersion < 0;
buildConfigsSorted = lib.sort configCompare buildConfigs;
shellTorch =
if buildConfigsSorted == [ ] then
buildSetsSorted = lib.sort configCompare buildSets;
bestBuildSet =
if buildSetsSorted == [ ] then
throw "No build variant is compatible with this system"
else
buildName (builtins.head buildConfigsSorted);
builtins.head buildSetsSorted;
shellTorch = buildName bestBuildSet.buildConfig;
in

{
devShells = rec {
default = devShells.${shellTorch};
Expand All @@ -100,37 +108,53 @@ in
rev = revUnderscored;
};
};
packages = rec {
default = bundle;
packages =
let
bundle = build.buildTorchExtensionBundle {
inherit path doGetKernelCheck;
rev = revUnderscored;
};
in
{
inherit bundle;

build-and-copy = writeScriptBin "build-and-copy" ''
#!/usr/bin/env bash
set -euo pipefail
default = bundle;

if [ ! -d build ]; then
mkdir build
fi
build-and-copy = writeScriptBin "build-and-copy" ''
#!/usr/bin/env bash
set -euo pipefail

for build_variant in ${bundle}/*; do
build_variant=$(basename $build_variant)
if [ -e build/$build_variant ]; then
rm -rf build/$build_variant
if [ ! -d build ]; then
mkdir build
fi

cp -r ${bundle}/$build_variant build/
done
for build_variant in ${bundle}/*; do
build_variant=$(basename $build_variant)
if [ -e build/$build_variant ]; then
rm -rf build/$build_variant
fi

chmod -R +w build
'';
cp -r ${bundle}/$build_variant build/
done

bundle = build.buildTorchExtensionBundle {
inherit path doGetKernelCheck;
rev = revUnderscored;
};
redistributable = build.buildDistTorchExtensions {
inherit path doGetKernelCheck;
bundleOnly = false;
rev = revUnderscored;
chmod -R +w build
'';

kernels =
bestBuildSet.pkgs.python3.withPackages (
ps: with ps; [
kernel-abi-check
kernels
]
)
// {
meta.mainProgram = "kernels";
};

redistributable = build.buildDistTorchExtensions {
inherit path doGetKernelCheck;
bundleOnly = false;
rev = revUnderscored;
};
};
};
}
9 changes: 9 additions & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ final: prev: {
rewrite-nix-paths-macho = prev.callPackage ./pkgs/rewrite-nix-paths-macho { };

stdenvGlibc_2_27 = prev.callPackage ./pkgs/stdenv-glibc-2_27 { };

# Python packages
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
(
python-self: python-super: with python-self; {
kernel-abi-check = callPackage ./pkgs/python-modules/kernel-abi-check { };
}
Comment on lines +19 to +21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need to add this derivation here since we have it in pkgs/kernel-abi-check/default.nix

Copy link
Copy Markdown
Member Author

@danieldk danieldk Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkgs/kernel-abi-check/default.nix is Rust version (command-line utility), this is the Python module.

)
];
}
48 changes: 48 additions & 0 deletions pkgs/python-modules/kernel-abi-check/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
lib,
buildPythonPackage,
rustPlatform,
}:

let
version =
(builtins.fromTOML (builtins.readFile ../../../kernel-abi-check/kernel-abi-check/Cargo.toml))
.package.version;
in
buildPythonPackage {
pname = "kernel-abi-check";
inherit version;
format = "pyproject";

src =
let
sourceFiles =
file:
file.name == "Cargo.toml"
|| file.name == "Cargo.lock"
|| file.name == "manylinux-policy.json"
|| file.hasExt "pyi"
|| file.name == "pyproject.toml"
|| file.hasExt "rs"
|| file.name == "stable_abi.toml";
in
lib.fileset.toSource {
root = ../../../kernel-abi-check;
fileset = lib.fileset.fileFilter sourceFiles ../../../kernel-abi-check;
};

cargoDeps = rustPlatform.importCargoLock {
lockFile = ../../../kernel-abi-check/bindings/python/Cargo.lock;
};

sourceRoot = "source/bindings/python";

build-system = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

meta = with lib; {
description = "Check ABI compliance of Hugging Face Hub kernels";
};
}
2 changes: 2 additions & 0 deletions tests/run-kernels/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.kernels.dependencies]
"kernels-test/versions" = ">=0.1.0,<0.2.0"
Loading