CodexとClaudeによるすべてのためのカスタムカーネル
CodexとClaudeが提供するカスタムカーネルにより、あらゆるユーザーがAIモデルを自身のニーズに合わせて最適化できるようになります。
キーポイント
Hugging Faceが、AIエージェントにCUDAカーネル開発を自動化させるスキルを開発し、ClaudeやCodexが実際のdiffusers/transformersモデル向けに動作するカーネルを生成することに成功
CUDAカーネル開発の複雑な専門知識(GPUアーキテクチャ固有の最適化、PyTorchバインディング、環境依存問題など)をエージェントスキルとしてパッケージ化することで、人間の開発負荷を大幅に軽減
Kernel Hubによる配布システムと組み合わせることで、高性能カーネルの開発から配布までのエンドツーエンド自動化が可能に
影響分析・編集コメントを表示
影響分析
この技術は、高性能AIモデル開発における最大のボトルネックの一つであるGPU最適化コードの作成を自動化する可能性を開く。専門家の知識をAIエージェントに継承させることで、ハードウェア最適化の民主化と開発速度の大幅な加速が期待できる。
編集コメント
「AIがAIのためのコードを書く」というメタな進化が現実に。専門家の暗黙知をAIエージェントに継承する手法は、他の高度な開発領域にも応用可能なパラダイムシフトと言える。
カスタムカーネル作成の民主化:CodexとClaudeによるCUDAカーネル自動生成
要約:
本記事では、コーディングエージェントが本番用のCUDAカーネルを自動生成する「エージェントスキル」の開発について報告している。このスキルにより、ClaudeやCodexなどのAIエージェントが、実際のdiffusersパイプラインやtransformersモデル向けに、PyTorchバインディングを含む動作可能なカーネルをエンドツーエンドで作成することに成功した。
主要ポイント:
- 課題の複雑さ:CUDAカーネルの開発、特にtransformersやdiffusersとの統合は高度に専門的で困難である。GPUアーキテクチャ固有のメモリアクセスパターン、ベクトル化戦略、ワープシャッフル還元など、経験豊富な開発者でも陥りやすい多くの落とし穴が存在する。
- ソリューションアプローチ:ドメイン知識をパッケージ化した「スキル」をエージェントに与えることで、この課題を解決。スキルには、対象GPUアーキテクチャの選択、カーネルビルダープロジェクトの構造化、共有メモリとレジスタの使い分け、PyTorchバインディングの書き方などが含まれる。
- 技術的背景:Kernel Hubはカスタムハードウェアカーネルの配布問題を解決していたが、カーネル作成そのものが依然として課題だった。今回のスキルはこのギャップを埋めるものである。
- 開発の困難さ:
- 各世代GPU(H100、A100、T4など)ごとのハードウェア固有最適化ガイド
- diffusersとtransformersの異なるモジュール階層、正規化規則、統合パターン
- CUDA、PyTorch、Pythonバージョンに依存するカーネル配布の複雑さ
これらの知識は通常、ドキュメントやStack Overflowに散在しているが、エージェントスキルとして体系化された。
- 実用性:kernelsライブラリを通じて簡単に導入可能で、単一コマンドでコーディングエージェントにインストールできる。Claude CodeやCursorは自動的にスキルを認識し、他のエージェント向けにもカスタマイズ可能なインストールオプションを提供している。
この取り組みは、従来は限られた専門家の領域だった高性能コンピューティングの知識を、AIエージェントを通じて広く利用可能にする重要な一歩である。ドメイン知識を構造化されたスキルとしてパッケージ化するアプローチは、LLM訓練スキルなど他の分野にも応用可能な汎用性の高い方法論を示している。
原文を表示
Custom Kernels for All from Codex and Claude Back to Articles Custom Kernels for All from Codex and Claude
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, diffusers and transformers have different module hierarchies, normalization conventions, and integration patterns. Custom kernels need to be registered in PyTorch for torch.compile to 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:
we need to install kernels from main for this 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. For other agents:
Codex kernels skills add cuda-kernels --codex # OpenCode kernels skills add cuda-kernels --opencode # Custom destination kernels skills add cuda-kernels --dest ./my-agent/skills/ # Install globally (available across all projects) kernels skills add cuda-kernels --global # Overwrite an existing installation kernels skills add cuda-kernels --claude --force Once installed, prompt your agent:
Build a vectorized RMSNorm kernel for H100 targeting the Qwen3-8B model in transformers. Or, you can go for something more open-ended:
Build an optimized attention kernel for H100 targeting the Qwen3-8B model in transformers. Benchmark it against the PyTorch baseline and validate improvements in end-to-end performance. 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.
If you're working on more complex kernels, or architecture-specific optimizations, that aren't covered in the skill, then the skill supplies the fundamental building blocks and patterns to get you started. We are also open to contributions on the skill itself.
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.
NVIDIA GPU Architecture-aware optimization for H100, A100, and T4 (compute capabilities, memory bandwidth, shared memory sizes, block sizing)
Integration patterns for both diffusers and transformers, including the pitfalls specific to each library
Kernel templates with vectorized memory access patterns for BF16, FP16, and FP32
Benchmarking workflows for both isolated kernel micro-benchmarks and end-to-end pipeline comparisons
HuggingFace Kernel Hub integration via get_kernel for loading community kernels
.claude/skills/cuda-kernels/ ├── SKILL.md # Main instructions (~550 tokens) ├── scripts/ │ ├── benchmark_example.py # End-to-end benchmark template │ ├── benchmark_rmsnorm.py # Isolated kernel micro-benchmark │ ├── ltx_kernel_injection_example.py # Diffusers integration pattern │ ├── transformers_injection_example.py # Transformers integration pattern │ └── hugg
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み