Custom Kernels for All from Codex and Claude

AI agents powered by Claude and Codex can now write production-grade CUDA kernels, bridging the gap between high-level AI models and low-level hardware optimization.
tl;dr: We built an agent skill that teaches coding agents how to write production CUDA kernels. Then we pointed Claude and Codex at two real targets: a diffusers pipeline and a transformers model. The agents produced working kernels for both, with correct PyTorch bindings and benchmarks, end to end.
Writing CUDA kernels is hard. Writing CUDA kernels that correctly integrate with transformers and diffusers is harder. There are architecture-specific memory access patterns, vectorization strategies, warp shuffle reductions, and a dozen integration pitfalls that trip up even experienced developers. It is exactly the kind of specialized, high-stakes problem where agent skills shine.
We gave coding agents the domain knowledge they need, like which GPU architecture to target, how to structure a kernel-builder project, when to use shared memory versus registers, and how to write PyTorch bindings. The agents did the rest. If you have used the LLM training skill or read We Got Claude to Teach Open Models, the pattern will feel familiar: package domain expertise into a skill, point the agent at a problem, and let it work.
The Kernel Hub solved the distribution of custom hardware kernels. You can load pre-compiled kernels from the Hub with a single get_kernel call. No builds, no flags. However, someone still needs to write the kernels. That is the gap this skill fills.
CUDA kernel development has a brutal surface area:
- Hardware-specific optimization guides for each generation of GPU. H100, A100, and T4 each have different compute capabilities, shared memory sizes, and bandwidth profiles
- In Libraries,
diffusersandtransformershave different module hierarchies, normalization conventions, and integration patterns. Custom kernels need to be registered in PyTorch fortorch.compileto recognize. - For distribution, kernels can depend on CUDA, Pytorch, and Python versions creating massive environment matrices.
This is domain knowledge that gets lost in documentation tabs and Stack Overflow answers. An agent skill packages it into context that loads on demand.
First, let's show how to use the skill right away, then we'll dive into the details of how we benchmarked the kernels.
The skill ships with the kernels library. Install it into your coding agent with a single command:
pip install git+https://github.com/huggingface/kernels.git#subdirectory=kernels
kernels skills add cuda-kernels --claude
This drops the skill into .claude/skills/cuda-kernels/ where Claude Code and Cursor pick it up automatically. Once installed, prompt your agent:
Build a vectorized RMSNorm kernel for H100 targeting the Qwen3-8B model in transformers.
The agent can read the skill, select the right architecture parameters, generate the CUDA source, write the PyTorch bindings, set up build.toml, and create a benchmark script.
The skill is roughly 550 tokens of structured guidance plus reference scripts, GPU optimization guides, troubleshooting docs, and complete working examples. Agentic coding tools like Codex and Claude can read this and produce a working kernel project.
We tested this on two real targets: LTX-Video (Diffusers) and Qwen3-8B (Transformers). For LTX-Video, the agent built RMSNorm, RoPE 3D, GEGLU, and AdaLN kernels. The RMSNorm kernel achieved an average speedup of 1.88x over the PyTorch baseline on H100. For Qwen3-8B, the optimized kernels provided a 6% end-to-end speedup, consistent with the model's compute profile.
Source: Hugging Face Blog
















