Custom Kernels for All from Codex and Claude
Hugging Face packaged CUDA kernel expertise (GPU architecture guides for H100/A100/T4, diffusers and transformers integration patterns, vectorized kernel templates, benchmark scripts) into an agent skill that lets Claude and Codex generate complete kernel-builder projects with PyTorch bindings. Agent-written RMSNorm kernels averaged 1.88x over PyTorch for LTX-Video and 1.94x for Qwen3-8B on H100 in BF16, with Qwen3 speedups growing from 1.58x at 128 tokens to 2.47x at 8192. End to end, LTX-Video gained only 6% (1.43x with torch.compile), consistent with RMSNorm taking about 5% of compute. The post also walks through building all PyTorch/CUDA variants with Nix and publishing to the Kernel Hub for one-line loading via get_kernel.
Related posts
- Learn the Hugging Face Kernel Hub in 5 Minutes
Hugging Face mediumAdeptHugging Face's Kernel Hub and `kernels` library let PyTorch code download pre-compiled, optimized GPU kernels such as FlashAttention, activations, RMSNorm and quantization kernels with a single `get_kernel` call. The library matches the binary to the installed Python, PyTorch and CUDA versions, which avoids source builds that for FlashAttention can need about 96 GB of RAM and hours of compilation. The walkthrough checks a fast GELU kernel against PyTorch and swaps a Triton LlamaRMSNorm into a simple model with the `use_kernel_forward_from_hub` decorator. It then benchmarks the kernel against a plain PyTorch RMSNorm using CUDA events.
- From Zero to GPU: A Guide to Building and Scaling Production-Ready CUDA Kernels
Hugging Face mediumAdeptHugging Face's kernel-builder lets developers write a custom CUDA kernel, register it as a native PyTorch operator, build it reproducibly with Nix for every supported PyTorch/CUDA combination, and publish it to the Hub for loading via `get_kernel`. The worked example is an RGB-to-grayscale kernel using a 2D thread grid, bound through TORCH_LIBRARY so it works with torch.compile and the dispatcher's per-device backends. It covers the build.toml manifest, Nix dev shells per torch/CUDA variant, build2cmake, and uploading build artifacts with Git LFS. Production concerns follow, including versioning kernels so API changes don't break downstream users and packaging kernels as Python wheels.
- Easily Build and Share ROCm Kernels with Hugging Face
Hugging Face mediumAdeptHugging Face's kernels library and kernel-builder can package a custom ROCm kernel as a native PyTorch operator and share it on the Hub, shown with the prize-winning RadeonFlow FP8 block-wise GEMM kernel for AMD MI300X. The walkthrough covers the expected project layout, renaming HIP sources to .h/.hip, a build.toml manifest targeting gfx942, and a flake.nix for reproducible Nix builds. It also covers registering the launcher via TORCH_LIBRARY so it is exposed through torch.ops, plus a Python __init__.py wrapper. Builds run with `nix build` or a `nix develop` shell using build2cmake and CMake, and enabling the Hugging Face cachix cache avoids expensive rebuilds.
- We Got Claude to Build CUDA Kernels and teach open models!
Hugging Face mediumAdeptupskill is a CLI that uses a strong teacher model (Claude Opus 4.5) to turn an agent trace into a portable Agent Skill (SKILL.md), auto-generates test cases, and measures skill lift on cheaper or local student models with and without the skill. Applied to building CUDA kernels with Hugging Face's kernel-builder, a ~520-token skill raised a quantized local GLM-4.7-Flash from 40% to 85% on the generated tests. The gains were not uniform across models. Some models used fewer tokens with the skill, while Opus gained no accuracy and spent more tokens, so each model should be evaluated on both accuracy and token cost before a skill is adopted.
- Hugging Face ❤️ TorchTPU: TPUs, Natively
Hugging Face mediumAdeptTorchTPU is a native PyTorch backend that makes TPU an ordinary device, replacing the lazy-tensor torch_xla path and making Optimum TPU unnecessary for running Hugging Face models. Transformers loads models with device_map="tpu", and Diffusers pipelines run with pipe.to("tpu"), optionally with torch.compile and tensor parallelism across chips. Pallas kernels from the Kernels Hub, such as a Tokamax ragged-dot MoE kernel, speed up batch-64 decoding by 21.5× on Qwen3-30B-A3B and 12.8× on Gemma 4 26B-A4B. Of the Transformers tests that run on TPU, 96.5% pass, and 34 TorchTPU issues have been reported so far, 19 of them fixed.