Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 13 min read How-to mediumAdept

Easily Build and Share ROCm Kernels with Hugging Face

Hugging 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.

Related posts

  • From Zero to GPU: A Guide to Building and Scaling Production-Ready CUDA Kernels

    Hugging Face mediumAdept

    Hugging 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.

  • Custom Kernels for All from Codex and Claude

    Hugging Face mediumAdept

    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.

  • Learn the Hugging Face Kernel Hub in 5 Minutes

    Hugging Face mediumAdept

    Hugging 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.

  • 🤗 Kernels: Major Updates

    Hugging Face mediumAdept

    Hugging Face's Kernels project, which packages and distributes custom GPU kernels via the Hub, now has a dedicated "kernel" repository type and several security layers on top of Nix-based reproducible builds. By default only kernels from trusted publishers load, with an explicit trust_remote_code opt-in for others, and Sigstore cosign signing with ephemeral keys tied to trusted GitHub workflows (verification is not yet enforced at load time). Other changes include separate kernels and kernel-builder CLIs designed to be easy for agents to drive, Torch Stable ABI and Apache TVM FFI support, and compatibility-checking APIs. A segfault-causing libstdc++ global-initialization conflict was fixed by switching from static linking to dynamic linking with the official manylinux_2_28 toolchain.

  • Creating custom kernels for the AMD MI300

    Hugging Face hardMaster

    Hugging Face and AMD wrote three open-source fused kernels for serving Llama 3.1 405B in FP8 with vLLM on an 8x MI300X node: residual add + RMS norm + FP8 quantization, SwiGLU + FP8 conversion, and a skinny GEMM for decode-sized batches. The write-up walks through the MI300X hierarchy (threads, 64-thread warps, compute units, XCDs, L2 and infinity cache), then uses vLLM profiling to show that GEMMs and all-reduce communications dominate decode latency. RMS norm and SwiGLU still account for about 15% of latency, which made them worth fusing. The basic fused RMS norm kernel alone is about 10x faster than PyTorch, and memory-access optimizations push it further; the kernels and benchmarks are available in the hf-rocm-kernels repo.

The quest for software engineering knowledge.

Look:
Layout: