Skip to content

nix-builder: redesign kernel testing#676

Merged
danieldk merged 5 commits into
mainfrom
testing-redesign
Jul 1, 2026
Merged

nix-builder: redesign kernel testing#676
danieldk merged 5 commits into
mainfrom
testing-redesign

Conversation

@danieldk

@danieldk danieldk commented Jun 25, 2026

Copy link
Copy Markdown
Member

This PR combines several changes to improve testing of kernels.

What we did so far: in tests for e.g. flash-attn3, we imported flash_attn3 in tests. However, this does not properly test the real-world use case of kernels, dynamically loaded kernels. It also lead to issues in some cases because it relies on the compatibility module being used. The compatibility module sometimes triggers a reload of a part of a kernel (first through the randomized name and then again through the regular name), resulting in operator registration clashes, etc.

What we will do instead: use get_kernels in tests. In development/tests shells set LOCAL_KERNELS to ensure that the local kernel gets tested.

Concrete changes:

  • Set LOCAL_KERNELS in nix develop and nix develop .#test.
  • Add a setup.py build_kernel subcommand to arch builds as a replacement for pip install. This subcommand was already supported by noarch kernels.
  • Update the documentation to use setup.py build_kernel in place of pip install.
  • Add a note about using get_kernel to the Kernel tests section.

danieldk added 3 commits June 24, 2026 12:27
In development shells, set `LOCAL_KERNELS` so that one can `get_kernel`
the kernel using its `repo-id` and get the local build.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

I think it'd be nice to have a short section in local-dev.md or build.md covering:

  • what the command does under the hood (the local_install target, arch vs. noarch)
  • the supported env vars (DEBUG, MAX_JOBS, NVCC_THREADS, ccache/sccache).


Writing kernels is a hard problem, so be specific to agents. A robust prompt will declare all core attributes, including:

- the library, for example `transformers` or `diffusers`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How were doc related formatting changes started showing up? Any version updates?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Possibly my editor reformatting these superfluous EOL whitespaces. If it's compatible with hf doc builder, we could consider using prettier to standardize formatting.

├── benchmark_rmsnorm.py # Micro-benchmark script
├── build.toml # kernel-builder config
├── setup.py # pip install -e .
├── setup.py # python setup.py build_kernel

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean that the existing skill files need to be updated?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so, I'll make a separate PR for that to move this forward.

Comment thread docs/source/builder/build.md Outdated
import torch
import torch.nn.functional as F

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This assumes that the kernel has been pushed to the Hub and the tests require loading remotely and NOT locally? Should we perhaps make that point a bit clearer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It doesn't, see the note about LOCAL_KERNELS below.

Comment on lines +166 to +167
debug = int(os.environ.get("DEBUG", 0))
cfg = "Debug" if debug else "Release"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to document this env var?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is part of the standardized CMake/setuptools integration stuff. I am not sure if we really want to document it? We should probably come up with a more principled way of enabling debugging if that's what we want.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Just one question:
#676 (comment)

@danieldk danieldk merged commit a5c9330 into main Jul 1, 2026
63 of 68 checks passed
@danieldk danieldk deleted the testing-redesign branch July 1, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants