Buckets:

download
raw
30.8 kB
import{s as Bl,n as Ll,o as Gl}from"../chunks/scheduler.f3b1e791.js";import{S as Hl,i as Vl,e as i,s as n,c as p,h as _l,a as o,d as l,b as a,f as Ql,g as c,j as r,k as Et,l as Zl,m as s,n as d,t as m,o as u,p as M}from"../chunks/index.023a9934.js";import{C as Rl}from"../chunks/CopyLLMTxtMenu.62c4edd4.js";import{C as h}from"../chunks/CodeBlock.4d7ad63e.js";import{H as y,E as Sl}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.79721a76.js";function Wl(Pt){let f,Ne,Ie,Ae,U,Qe,b,Be,j,Xt="Code agents are a good fit to build custom kernels because the hard part is not just writing in Domain Specific Language (DSLs) like CUDA. You also need the right project layout, PyTorch bindings, architecture-specific choices, model-specific integration, and trustworthy benchmarks.",Le,J,Yt="Kernels on Hugging Face are compatible with agents via skills and the <code>hf</code> CLI. The <code>cuda-kernels</code> and <code>rocm-kernels</code> skills contain knowledge so an agent can generate and publish a complete kernel project, instead of isolated snippets.",Ge,g,Ft="This guide is for <strong>authoring new kernels</strong>. If you only want to <strong>load an existing precompiled kernel</strong>, use <code>get_kernel()</code> instead.",He,C,Ve,k,qt="You need:",_e,$,zt="<li>a coding agent that supports skills, such as Claude Code, Codex, Cursor, or OpenCode</li> <li>a clear target: library, model, operation, GPU, dtype, and representative shapes</li>",Ze,x,Ot="The skill currently focuses on NVIDIA GPUs such as <strong>H100</strong>, <strong>A100</strong>, and <strong>T4</strong>, and on integration patterns for <strong>transformers</strong> and <strong>diffusers</strong>.",Re,I,Kt="Install the skill into your agent. If you need the latest version from <code>main</code>, use:",Se,v,We,T,el='<p>Check <a href="https://github.com/burtenshaw/kernel-skill/tree/main/examples/ltx_video" rel="nofollow">this example</a> to see what generated kernels look like.</p>',De,N,Ee,A,tl="Writing kernels is a hard problem, so be specific to agents. A robust prompt will declare all core attributes, including:",Pe,Q,ll="<li>the library, for example <code>transformers</code> or <code>diffusers</code></li> <li>the model id, for example <code>Qwen3-8B</code> or <code>LTX-Video</code></li> <li>the operation, for example <code>RMSNorm</code>, attention, RoPE, <code>GEGLU</code>, or <code>AdaLN</code></li> <li>the target GPU, for example <code>H100</code>, <code>A100</code>, or <code>T4</code></li> <li>the dtype, for example <code>bfloat16</code>, <code>float16</code>, or <code>float32</code></li> <li>the outputs you expect: kernel code, bindings, tests, and benchmarks</li>",Xe,B,sl="In practice, you can often skip some of these and the agent will infer based on common practice, but if you know a detail declare it.",Ye,L,nl="For example:",Fe,G,qe,H,al="Or for diffusers:",ze,V,Oe,_,il="If you prefer, you can first scaffold a project with <code>kernel-builder init --name &lt;org&gt;/&lt;kernel&gt;</code> and then ask the agent to fill in the implementation.",Ke,Z,et,R,ol="A useful result is a full <code>kernel-builder</code> project, not just a <code>.cu</code> file. The exact layout can vary, but it should include at least:",tt,S,lt,W,rl="The agent skills contain example scipts to help you verify the project. So you can briefly test it yourself by running:",st,D,nt,E,at,P,pl="Let’s dive deeper into the generated files, and explore how to validate the project.",it,X,ot,Y,cl="This is the main configuration file for <code>kernel-builder</code>. It tells <code>kernel-builder</code> what to build and how so it should contain all the core information about your kernel project.",rt,F,pt,q,dl="First check that:",ct,z,ml="<li><code>backends = [&quot;cuda&quot;]</code> is correct for your project</li> <li>the kernel source files are listed correctly</li> <li>the Torch binding sources are included under <code>[torch]</code></li> <li><code>cuda-capabilities</code> is only set when the kernel truly targets specific architectures</li>",dt,O,ul="For architecture-specific kernels, typical capability values are:",mt,K,Ml="<li>H100: <code>9.0</code></li> <li>A100: <code>8.0</code></li> <li>T4: <code>7.5</code></li>",ut,ee,hl="If the kernel does <strong>not</strong> require a specific capability, the kernels docs recommend leaving <code>cuda-capabilities</code> unset so the builder can target all supported capabilities. In practice, you can prompt your agent to review the <code>build.toml</code> for excessive definitions. Agents have a tendency to over-specify capabilities.",Mt,te,ht,le,yl="The kernel should be registered as Torch ops in <code>torch-ext/torch_binding.cpp</code>, with declarations in a header and a small Python wrapper in <code>torch-ext/&lt;name&gt;/__init__.py</code>. This is what makes the kernel callable from Python and is the right foundation for <code>torch.compile</code> compatibility.",yt,se,ft,ne,fl="Make sure the integration matches the library:",Tt,ae,Tl="<li><strong>transformers</strong>: patch the target modules directly, often RMSNorm modules whose class name contains <code>RMSNorm</code></li> <li><strong>diffusers</strong>: inspect the actual pipeline structure before patching, because modules and attention processors can differ across pipelines</li>",wt,w,wl="<p>One common issue is that the agent will not integrate the kernel at all. Typically because the project’s context is so long.</p>",Ut,ie,Ul="A few patterns matter in practice for the integration code:",bt,oe,bl="<li>In <strong>transformers</strong>, RMSNorm modules generally have weights, but epsilon may be exposed as <code>variance_epsilon</code> or <code>eps</code> depending on the model.</li> <li>In <strong>diffusers</strong>, some RMSNorm modules may have <code>weight=None</code>, so the integration code needs to handle both weighted and unweighted cases.</li> <li>In <strong>diffusers</strong>, checking <code>type(module).__name__</code> is often more reliable than <code>isinstance(...)</code> for matching RMSNorm modules across implementations.</li> <li>If a diffusers pipeline uses CPU offloading, inject custom kernels <strong>before</strong> enabling offload.</li>",jt,re,jl="For attention, prefer the model library’s existing optimized path when one already exists. For example, in <code>transformers</code>, Flash Attention 2 is usually the right baseline for attention, while custom kernels are especially useful for operations like RMSNorm and other targeted hotspots.",Jt,pe,gt,ce,Jl='Kernel Hub kernels must support all recent PyTorch and CUDA configurations. The kernel-builder Nix flake handles this automatically. Copy the <a href="https://github.com/huggingface/kernels/blob/main/builder/examples/relu/flake.nix" rel="nofollow">example <code>flake.nix</code></a> into your project and run:',Ct,de,kt,me,gl="This builds the kernel for every required PyTorch/CUDA variant and places the results in <code>build/</code>. For faster builds, enable the HuggingFace Nix cache:",$t,ue,xt,Me,It,he,Cl="There are two main benchmarks to consider:",vt,ye,kl="<li>an isolated kernel micro-benchmark</li> <li>an end-to-end benchmark in the real model or pipeline</li>",Nt,fe,$l="The agent will generate both benchmarks based on the agent skills examples. Typically as a script called <code>benchmark_example.py</code>. If you have access to the target hardware, you can run it to verify the kernel works. For example, the agent will generat a table like this:",At,Te,Qt,we,xl='Interpret the results carefully. A kernel can show a large isolated speedup but only a modest end-to-end gain if that operation is a small fraction of total runtime. In the LTX-Video example from <a href="https://huggingface.co/blog/custom-cuda-kernels-agent-skills" rel="nofollow">the blog we wrote</a>, the generated RMSNorm kernel improved the isolated benchmark by about <strong>1.88x</strong> on average, but end-to-end video generation improved by about <strong>6%</strong>, which matched the fact that RMSNorm accounted for only a small share of total compute.',Bt,Ue,Lt,be,Il="Once the project is correct and benchmarked, you can build Hub-compatible artifacts and upload them. For this, you should first push to the Hub using the <code>hf</code> CLI tool:",Gt,je,Ht,Je,vl="Or, you can manually create the repository and upload the artifacts:",Vt,ge,_t,Ce,Nl="After pushing to the Hub, users can load the kernel without compiling:",Zt,ke,Rt,$e,Al="Well done! You have now built a custom kernel and published it to the Hub.",St,xe,Wt,ve,Dt;return U=new Rl({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new y({props:{title:"Writing custom kernels with code agents",local:"writing-custom-kernels-with-code-agents",headingTag:"h1"}}),C=new y({props:{title:"Before you start",local:"before-you-start",headingTag:"h2"}}),v=new h({props:{code:"Y2FyZ28lMjBpbnN0YWxsJTIwLS1naXQlMjBodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZodWdnaW5nZmFjZSUyRmtlcm5lbHMlMjBoZi1rZXJuZWwtYnVpbGRlciUwQSUwQSUyMyUyMEluc3RhbGwlMjB5b3VyJTIwc2tpbGxzLiUyMFVzZSUyMC0tY2xhdWRlJTJDJTIwLS1jb2RleCUyQyUyMG9yJTIwLS1vcGVuY29kZSUwQWtlcm5lbC1idWlsZGVyJTIwc2tpbGxzJTIwYWRkJTIwLS1jbGF1ZGU=",highlighted:`cargo install --git https://github.com/huggingface/kernels hf-kernel-builder
<span class="hljs-meta prompt_">
# </span><span class="language-bash">Install your skills. Use --claude, --codex, or --opencode</span>
kernel-builder skills add --claude`,wrap:!1}}),N=new y({props:{title:"1. Give the agent a precise task prompt",local:"1-give-the-agent-a-precise-task-prompt",headingTag:"h2"}}),G=new h({props:{code:"QnVpbGQlMjBhJTIwdmVjdG9yaXplZCUyMFJNU05vcm0lMjBrZXJuZWwlMjBmb3IlMjBIMTAwJTIwdGFyZ2V0aW5nJTIwUXdlbjMtOEIlMjBpbiUyMHRyYW5zZm9ybWVycy4lMEFDcmVhdGUlMjB0aGUlMjBmdWxsJTIwa2VybmVsLWJ1aWxkZXIlMjBwcm9qZWN0JTJDJTIwUHlUb3JjaCUyMGJpbmRpbmdzJTJDJTIwY29ycmVjdG5lc3MlMjB0ZXN0cyUyQyUyMGFuZCUyMGJlbmNobWFyayUyMHNjcmlwdHMu",highlighted:`<span class="hljs-keyword">Build </span>a vectorized RMSNorm kernel for H100 targeting Qwen3<span class="hljs-number">-8</span>B in transformers.
Create the full kernel-<span class="hljs-keyword">builder </span>project, PyTorch <span class="hljs-keyword">bindings, </span>correctness tests, <span class="hljs-keyword">and </span><span class="hljs-keyword">benchmark </span><span class="hljs-keyword">scripts.</span>`,wrap:!1}}),V=new h({props:{code:"QnVpbGQlMjBhbiUyMEgxMDAlMjBSTVNOb3JtJTIwa2VybmVsJTIwZm9yJTIwTFRYLVZpZGVvJTIwaW4lMjBkaWZmdXNlcnMuJTBBUGF0Y2glMjB0aGUlMjBwaXBlbGluZSUyMGNvcnJlY3RseSUyQyUyMGJlbmNobWFyayUyMGl0JTIwYWdhaW5zdCUyMHRoZSUyMFB5VG9yY2glMjBiYXNlbGluZSUyQyUyMGFuZCUyMHJlcG9ydCUyMGVuZC10by1lbmQlMjBpbXBhY3Qu",highlighted:`Build <span class="hljs-keyword">an</span> H100 RMSNorm kernel <span class="hljs-keyword">for</span> LTX-Video <span class="hljs-keyword">in</span> diffusers.
Patch <span class="hljs-keyword">the</span> pipeline correctly, benchmark <span class="hljs-keyword">it</span> against <span class="hljs-keyword">the</span> PyTorch baseline, <span class="hljs-keyword">and</span> report <span class="hljs-keyword">end</span>-<span class="hljs-built_in">to</span>-<span class="hljs-function"><span class="hljs-keyword">end</span> <span class="hljs-title">impact</span>.</span>`,wrap:!1}}),Z=new y({props:{title:"2. Verify that the agent produces a complete kernel project",local:"2-verify-that-the-agent-produces-a-complete-kernel-project",headingTag:"h2"}}),S=new h({props:{code:"ZXhhbXBsZXMlMkZ5b3VyX21vZGVsJTJGJTBBJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwa2VybmVsX3NyYyUyRiUwQSVFMiU5NCU4MiUyMCUyMCUyMCVFMiU5NCU5NCVFMiU5NCU4MCVFMiU5NCU4MCUyMHJtc25vcm0uY3UlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBWZWN0b3JpemVkJTIwQ1VEQSUyMGtlcm5lbCUwQSVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMHRvcmNoLWV4dCUyRiUwQSVFMiU5NCU4MiUyMCUyMCUyMCVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMHlvdXJfa2VybmVscyUyRl9faW5pdF9fLnB5JTBBJUUyJTk0JTgyJTIwJTIwJTIwJUUyJTk0JTk0JUUyJTk0JTgwJUUyJTk0JTgwJTIwdG9yY2hfYmluZGluZy5jcHAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBQeVRvcmNoJTIwQyUyQiUyQiUyMGJpbmRpbmdzJTBBJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwYmVuY2htYXJrX3Jtc25vcm0ucHklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBNaWNyby1iZW5jaG1hcmslMjBzY3JpcHQlMEElRTIlOTQlOUMlRTIlOTQlODAlRTIlOTQlODAlMjBidWlsZC50b21sJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwa2VybmVsLWJ1aWxkZXIlMjBjb25maWclMEElRTIlOTQlOUMlRTIlOTQlODAlRTIlOTQlODAlMjBzZXR1cC5weSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMHBpcCUyMGluc3RhbGwlMjAtZSUyMC4lMEElRTIlOTQlOTQlRTIlOTQlODAlRTIlOTQlODAlMjBweXByb2plY3QudG9tbA==",highlighted:`examples<span class="hljs-regexp">/your_model/</span>
├── kernel_src/
│ └── rmsnorm.cu <span class="hljs-comment"># Vectorized CUDA kernel</span>
├── torch-ext/
│ ├── your_kernels/__init__.py
│ └── torch_binding.cpp <span class="hljs-comment"># PyTorch C++ bindings</span>
├── benchmark_rmsnorm.py <span class="hljs-comment"># Micro-benchmark script</span>
├── build.toml <span class="hljs-comment"># kernel-builder config</span>
├── setup.py <span class="hljs-comment"># pip install -e .</span>
└── pyproject.toml`,wrap:!1}}),D=new h({props:{code:"VmVyaWZ5JTIwdGhlJTIwa2VybmVsJTIwcHJvamVjdCUyMHdvcmtzJTIwd2l0aCUyMGElMjB0cmFuc2Zvcm1lcnMlMjBleGFtcGxlLg==",highlighted:'Verify <span class="hljs-keyword">the</span> kernel project works <span class="hljs-keyword">with</span> <span class="hljs-keyword">a</span> transformers example.',wrap:!1}}),E=new y({props:{title:"3. Review the generated files",local:"3-review-the-generated-files",headingTag:"h2"}}),X=new y({props:{title:"build.toml",local:"buildtoml",headingTag:"h3"}}),F=new h({props:{code:"JTVCZ2VuZXJhbCU1RCUwQW5hbWUlMjAlM0QlMjAlMjJ5b3VyX2tlcm5lbHMlMjIlMEFiYWNrZW5kcyUyMCUzRCUyMCU1QiUyMmN1ZGElMjIlNUQlMEF2ZXJzaW9uJTIwJTNEJTIwMSUwQSUwQSU1QnRvcmNoJTVEJTBBc3JjJTIwJTNEJTIwJTVCJTIydG9yY2gtZXh0JTJGdG9yY2hfYmluZGluZy5jcHAlMjIlNUQlMEElMEElNUJrZXJuZWwucm1zbm9ybSU1RCUwQWJhY2tlbmQlMjAlM0QlMjAlMjJjdWRhJTIyJTBBc3JjJTIwJTNEJTIwJTVCJTIya2VybmVsX3NyYyUyRnJtc25vcm0uY3UlMjIlNUQlMEFkZXBlbmRzJTIwJTNEJTIwJTVCJTIydG9yY2glMjIlNUQlMEFjdWRhLWNhcGFiaWxpdGllcyUyMCUzRCUyMCU1QiUyMjkuMCUyMiU1RCUyMCUyMCUyMyUyMEgxMDA=",highlighted:`<span class="hljs-section">[general]</span>
<span class="hljs-attr">name</span> = <span class="hljs-string">&quot;your_kernels&quot;</span>
<span class="hljs-attr">backends</span> = [<span class="hljs-string">&quot;cuda&quot;</span>]
<span class="hljs-attr">version</span> = <span class="hljs-number">1</span>
<span class="hljs-section">[torch]</span>
<span class="hljs-attr">src</span> = [<span class="hljs-string">&quot;torch-ext/torch_binding.cpp&quot;</span>]
<span class="hljs-section">[kernel.rmsnorm]</span>
<span class="hljs-attr">backend</span> = <span class="hljs-string">&quot;cuda&quot;</span>
<span class="hljs-attr">src</span> = [<span class="hljs-string">&quot;kernel_src/rmsnorm.cu&quot;</span>]
<span class="hljs-attr">depends</span> = [<span class="hljs-string">&quot;torch&quot;</span>]
<span class="hljs-attr">cuda-capabilities</span> = [<span class="hljs-string">&quot;9.0&quot;</span>] <span class="hljs-comment"># H100</span>`,wrap:!1}}),te=new y({props:{title:"Torch bindings",local:"torch-bindings",headingTag:"h3"}}),se=new y({props:{title:"Model integration code",local:"model-integration-code",headingTag:"h3"}}),pe=new y({props:{title:"5. Build and test, and benchmark",local:"5-build-and-test-and-benchmark",headingTag:"h2"}}),de=new h({props:{code:"bml4JTIwZmxha2UlMjB1cGRhdGUlMEFuaXglMjBydW4lMjAuJTIzYnVpbGQtYW5kLWNvcHklMjAtTA==",highlighted:`nix flake update
nix run .#build-and-copy -L`,wrap:!1}}),ue=new h({props:{code:"bml4JTIwcnVuJTIwbml4cGtncyUyM2NhY2hpeCUyMC0tJTIwdXNlJTIwaHVnZ2luZ2ZhY2U=",highlighted:"nix run nixpkgs#cachix -- use huggingface",wrap:!1}}),Me=new y({props:{title:"6. Benchmark",local:"6-benchmark",headingTag:"h2"}}),Te=new h({props:{code:"JTdDJTIwU2hhcGUlMjAlN0MlMjBDdXN0b20lMjAobXMpJTIwJTdDJTIwUHlUb3JjaCUyMChtcyklMjAlN0MlMjBTcGVlZHVwJTIwJTdDJTBBJTdDJTIwJTNBLS0tLSUyMCU3QyUyMCUzQS0tLSUzQSUyMCU3QyUyMCUzQS0tLSUzQSUyMCU3QyUyMCUzQS0tLSUzQSUyMCU3QyUwQSU3QyUyMCU1QjF4MTI4eDQwOTYlNUQlMjAlN0MlMjAwLjA0MCUyMCU3QyUyMDAuMDYyJTIwJTdDJTIwKioxLjU4eCoqJTIwJTdDJTBBJTdDJTIwJTVCMXg1MTJ4NDA5NiU1RCUyMCU3QyUyMDAuMDM4JTIwJTdDJTIwMC4wNjQlMjAlN0MlMjAqKjEuNjl4KiolMjAlN0MlMEElN0MlMjAlNUIxeDEwMjR4NDA5NiU1RCUyMCU3QyUyMDAuMDM3JTIwJTdDJTIwMC4wNzElMjAlN0MlMjAqKjEuOTB4KiolMjAlN0MlMEElN0MlMjAlNUIxeDIwNDh4NDA5NiU1RCUyMCU3QyUyMDAuMDQ1JTIwJTdDJTIwMC4wOTElMjAlN0MlMjAqKjIuMDN4KiolMjAlN0MlMEElN0MlMjAlNUIxeDQwOTZ4NDA5NiU1RCUyMCU3QyUyMDAuMDcxJTIwJTdDJTIwMC4xNTAlMjAlN0MlMjAqKjIuMTJ4KiolMjAlN0MlMEElN0MlMjAlNUI0eDUxMng0MDk2JTVEJTIwJTdDJTIwMC4wNTYlMjAlN0MlMjAwLjA5MyUyMCU3QyUyMCoqMS42N3gqKiUyMCU3QyUwQSU3QyUyMCU1Qjh4MjU2eDQwOTYlNUQlMjAlN0MlMjAwLjA0NSUyMCU3QyUyMDAuMDkyJTIwJTdDJTIwKioyLjA2eCoqJTIwJTdDJTBBJTdDJTIwJTVCMXg4MTkyeDQwOTYlNUQlMjAlN0MlMjAwLjEwOSUyMCU3QyUyMDAuMjY5JTIwJTdDJTIwKioyLjQ3eCoqJTIwJTdD",highlighted:`| Shape | Custom (ms) | PyTorch (ms) | Speedup |
| :---- | :---: | :---: | :---: |
| [1x128x4096] | 0.040 | 0.062 | <span class="hljs-strong">**1.58x**</span> |
| [1x512x4096] | 0.038 | 0.064 | <span class="hljs-strong">**1.69x**</span> |
| [1x1024x4096] | 0.037 | 0.071 | <span class="hljs-strong">**1.90x**</span> |
| [1x2048x4096] | 0.045 | 0.091 | <span class="hljs-strong">**2.03x**</span> |
| [1x4096x4096] | 0.071 | 0.150 | <span class="hljs-strong">**2.12x**</span> |
| [4x512x4096] | 0.056 | 0.093 | <span class="hljs-strong">**1.67x**</span> |
| [8x256x4096] | 0.045 | 0.092 | <span class="hljs-strong">**2.06x**</span> |
| [1x8192x4096] | 0.109 | 0.269 | <span class="hljs-strong">**2.47x**</span> |`,wrap:!1}}),Ue=new y({props:{title:"7. Publish to the Hub",local:"7-publish-to-the-hub",headingTag:"h2"}}),je=new h({props:{code:"JTIzJTIwaW5zdGFsbCUyMHRoZSUyMGhmJTIwQ0xJJTIwdG9vbCUwQWhmJTIwc2tpbGxzJTIwYWRkJTIwJTBBJTBBJTIzJTIwQXV0aGVudGljYXRlJTBBaGYlMjBhdXRoJTIwbG9naW4lMEElMEElMjMlMjBQdXNoJTIwdG8lMjB0aGUlMjBIdWIlMEElM0NhZ2VudC1wcm9tcHQlM0UlMEFQdXNoJTIwdGhlJTIwa2VybmVsJTIwdG8lMjB0aGUlMjBIdWIuJTBBJTNDJTJGYWdlbnQtcHJvbXB0JTNF",highlighted:`<span class="hljs-meta prompt_"># </span><span class="language-bash">install the hf CLI tool</span>
hf skills add
<span class="hljs-meta prompt_">
# </span><span class="language-bash">Authenticate</span>
hf auth login
<span class="hljs-meta prompt_">
# </span><span class="language-bash">Push to the Hub</span>
&lt;agent-prompt&gt;
Push the kernel to the Hub.
&lt;/agent-prompt&gt;`,wrap:!1}}),ge=new h({props:{code:"JTIzJTIwQ3JlYXRlJTIwdGhlJTIwcmVwb3NpdG9yeSUwQWhmJTIwcmVwbyUyMGNyZWF0ZSUyMHlvdXItb3JnJTJGeW91ci1rZXJuZWwlMjAtLXR5cGUlMjBtb2RlbCUwQSUwQSUyMyUyMFVwbG9hZCUyMHRoZSUyMGFydGlmYWN0cyUwQSUyMyUyMFJ1biUyMGluc2lkZSUyMHRoZSUyMG1haW4lMjBrZXJuZWwlMjBkaXJlY3RvcnklMkMlMjB3aGVyZSUyMGJ1aWxkJTJGJTIwaXMuJTBBa2VybmVsLWJ1aWxkZXIlMjB1cGxvYWQ=",highlighted:`<span class="hljs-meta prompt_"># </span><span class="language-bash">Create the repository</span>
hf repo create your-org/your-kernel --type model
<span class="hljs-meta prompt_">
# </span><span class="language-bash">Upload the artifacts</span>
<span class="hljs-meta prompt_"># </span><span class="language-bash">Run inside the main kernel directory, <span class="hljs-built_in">where</span> build/ is.</span>
kernel-builder upload`,wrap:!1}}),ke=new h({props:{code:"ZnJvbSUyMGtlcm5lbHMlMjBpbXBvcnQlMjBnZXRfa2VybmVsJTBBJTBBa2VybmVsJTIwJTNEJTIwZ2V0X2tlcm5lbCglMjJ5b3VyLW9yZyUyRnlvdXIta2VybmVsJTIyJTJDJTIwdmVyc2lvbiUzRDEp",highlighted:`<span class="hljs-keyword">from</span> kernels <span class="hljs-keyword">import</span> get_kernel
kernel = get_kernel(<span class="hljs-string">&quot;your-org/your-kernel&quot;</span>, version=<span class="hljs-number">1</span>)`,wrap:!1}}),xe=new Sl({props:{source:"https://github.com/huggingface/kernels/blob/main/docs/source/builder/agents-guide.md"}}),{c(){f=i("meta"),Ne=n(),Ie=i("p"),Ae=n(),p(U.$$.fragment),Qe=n(),p(b.$$.fragment),Be=n(),j=i("p"),j.textContent=Xt,Le=n(),J=i("p"),J.innerHTML=Yt,Ge=n(),g=i("p"),g.innerHTML=Ft,He=n(),p(C.$$.fragment),Ve=n(),k=i("p"),k.textContent=qt,_e=n(),$=i("ul"),$.innerHTML=zt,Ze=n(),x=i("p"),x.innerHTML=Ot,Re=n(),I=i("p"),I.innerHTML=Kt,Se=n(),p(v.$$.fragment),We=n(),T=i("blockquote"),T.innerHTML=el,De=n(),p(N.$$.fragment),Ee=n(),A=i("p"),A.textContent=tl,Pe=n(),Q=i("ul"),Q.innerHTML=ll,Xe=n(),B=i("p"),B.textContent=sl,Ye=n(),L=i("p"),L.textContent=nl,Fe=n(),p(G.$$.fragment),qe=n(),H=i("p"),H.textContent=al,ze=n(),p(V.$$.fragment),Oe=n(),_=i("p"),_.innerHTML=il,Ke=n(),p(Z.$$.fragment),et=n(),R=i("p"),R.innerHTML=ol,tt=n(),p(S.$$.fragment),lt=n(),W=i("p"),W.textContent=rl,st=n(),p(D.$$.fragment),nt=n(),p(E.$$.fragment),at=n(),P=i("p"),P.textContent=pl,it=n(),p(X.$$.fragment),ot=n(),Y=i("p"),Y.innerHTML=cl,rt=n(),p(F.$$.fragment),pt=n(),q=i("p"),q.textContent=dl,ct=n(),z=i("ul"),z.innerHTML=ml,dt=n(),O=i("p"),O.textContent=ul,mt=n(),K=i("ul"),K.innerHTML=Ml,ut=n(),ee=i("p"),ee.innerHTML=hl,Mt=n(),p(te.$$.fragment),ht=n(),le=i("p"),le.innerHTML=yl,yt=n(),p(se.$$.fragment),ft=n(),ne=i("p"),ne.textContent=fl,Tt=n(),ae=i("ul"),ae.innerHTML=Tl,wt=n(),w=i("blockquote"),w.innerHTML=wl,Ut=n(),ie=i("p"),ie.textContent=Ul,bt=n(),oe=i("ul"),oe.innerHTML=bl,jt=n(),re=i("p"),re.innerHTML=jl,Jt=n(),p(pe.$$.fragment),gt=n(),ce=i("p"),ce.innerHTML=Jl,Ct=n(),p(de.$$.fragment),kt=n(),me=i("p"),me.innerHTML=gl,$t=n(),p(ue.$$.fragment),xt=n(),p(Me.$$.fragment),It=n(),he=i("p"),he.textContent=Cl,vt=n(),ye=i("ol"),ye.innerHTML=kl,Nt=n(),fe=i("p"),fe.innerHTML=$l,At=n(),p(Te.$$.fragment),Qt=n(),we=i("p"),we.innerHTML=xl,Bt=n(),p(Ue.$$.fragment),Lt=n(),be=i("p"),be.innerHTML=Il,Gt=n(),p(je.$$.fragment),Ht=n(),Je=i("p"),Je.textContent=vl,Vt=n(),p(ge.$$.fragment),_t=n(),Ce=i("p"),Ce.textContent=Nl,Zt=n(),p(ke.$$.fragment),Rt=n(),$e=i("p"),$e.textContent=Al,St=n(),p(xe.$$.fragment),Wt=n(),ve=i("p"),this.h()},l(e){const t=_l("svelte-u9bgzb",document.head);f=o(t,"META",{name:!0,content:!0}),t.forEach(l),Ne=a(e),Ie=o(e,"P",{}),Ql(Ie).forEach(l),Ae=a(e),c(U.$$.fragment,e),Qe=a(e),c(b.$$.fragment,e),Be=a(e),j=o(e,"P",{"data-svelte-h":!0}),r(j)!=="svelte-wx8riv"&&(j.textContent=Xt),Le=a(e),J=o(e,"P",{"data-svelte-h":!0}),r(J)!=="svelte-1jfibld"&&(J.innerHTML=Yt),Ge=a(e),g=o(e,"P",{"data-svelte-h":!0}),r(g)!=="svelte-1tjv5at"&&(g.innerHTML=Ft),He=a(e),c(C.$$.fragment,e),Ve=a(e),k=o(e,"P",{"data-svelte-h":!0}),r(k)!=="svelte-fpocgd"&&(k.textContent=qt),_e=a(e),$=o(e,"UL",{"data-svelte-h":!0}),r($)!=="svelte-1dde4tg"&&($.innerHTML=zt),Ze=a(e),x=o(e,"P",{"data-svelte-h":!0}),r(x)!=="svelte-tuxf7"&&(x.innerHTML=Ot),Re=a(e),I=o(e,"P",{"data-svelte-h":!0}),r(I)!=="svelte-1xhaxu6"&&(I.innerHTML=Kt),Se=a(e),c(v.$$.fragment,e),We=a(e),T=o(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),r(T)!=="svelte-1e86mut"&&(T.innerHTML=el),De=a(e),c(N.$$.fragment,e),Ee=a(e),A=o(e,"P",{"data-svelte-h":!0}),r(A)!=="svelte-1l1j2mn"&&(A.textContent=tl),Pe=a(e),Q=o(e,"UL",{"data-svelte-h":!0}),r(Q)!=="svelte-psks7k"&&(Q.innerHTML=ll),Xe=a(e),B=o(e,"P",{"data-svelte-h":!0}),r(B)!=="svelte-xhu8j0"&&(B.textContent=sl),Ye=a(e),L=o(e,"P",{"data-svelte-h":!0}),r(L)!=="svelte-1gkqha7"&&(L.textContent=nl),Fe=a(e),c(G.$$.fragment,e),qe=a(e),H=o(e,"P",{"data-svelte-h":!0}),r(H)!=="svelte-9uonxv"&&(H.textContent=al),ze=a(e),c(V.$$.fragment,e),Oe=a(e),_=o(e,"P",{"data-svelte-h":!0}),r(_)!=="svelte-136z17x"&&(_.innerHTML=il),Ke=a(e),c(Z.$$.fragment,e),et=a(e),R=o(e,"P",{"data-svelte-h":!0}),r(R)!=="svelte-nvltch"&&(R.innerHTML=ol),tt=a(e),c(S.$$.fragment,e),lt=a(e),W=o(e,"P",{"data-svelte-h":!0}),r(W)!=="svelte-1qd6e3e"&&(W.textContent=rl),st=a(e),c(D.$$.fragment,e),nt=a(e),c(E.$$.fragment,e),at=a(e),P=o(e,"P",{"data-svelte-h":!0}),r(P)!=="svelte-qc7s6y"&&(P.textContent=pl),it=a(e),c(X.$$.fragment,e),ot=a(e),Y=o(e,"P",{"data-svelte-h":!0}),r(Y)!=="svelte-19on78x"&&(Y.innerHTML=cl),rt=a(e),c(F.$$.fragment,e),pt=a(e),q=o(e,"P",{"data-svelte-h":!0}),r(q)!=="svelte-a88ner"&&(q.textContent=dl),ct=a(e),z=o(e,"UL",{"data-svelte-h":!0}),r(z)!=="svelte-1iqpkrd"&&(z.innerHTML=ml),dt=a(e),O=o(e,"P",{"data-svelte-h":!0}),r(O)!=="svelte-1yjphxb"&&(O.textContent=ul),mt=a(e),K=o(e,"UL",{"data-svelte-h":!0}),r(K)!=="svelte-ezzwa8"&&(K.innerHTML=Ml),ut=a(e),ee=o(e,"P",{"data-svelte-h":!0}),r(ee)!=="svelte-l5sw96"&&(ee.innerHTML=hl),Mt=a(e),c(te.$$.fragment,e),ht=a(e),le=o(e,"P",{"data-svelte-h":!0}),r(le)!=="svelte-ajpoy6"&&(le.innerHTML=yl),yt=a(e),c(se.$$.fragment,e),ft=a(e),ne=o(e,"P",{"data-svelte-h":!0}),r(ne)!=="svelte-1frq87x"&&(ne.textContent=fl),Tt=a(e),ae=o(e,"UL",{"data-svelte-h":!0}),r(ae)!=="svelte-fkol0c"&&(ae.innerHTML=Tl),wt=a(e),w=o(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),r(w)!=="svelte-1rkvfp"&&(w.innerHTML=wl),Ut=a(e),ie=o(e,"P",{"data-svelte-h":!0}),r(ie)!=="svelte-1n5kowm"&&(ie.textContent=Ul),bt=a(e),oe=o(e,"UL",{"data-svelte-h":!0}),r(oe)!=="svelte-5lzvco"&&(oe.innerHTML=bl),jt=a(e),re=o(e,"P",{"data-svelte-h":!0}),r(re)!=="svelte-10mo6mc"&&(re.innerHTML=jl),Jt=a(e),c(pe.$$.fragment,e),gt=a(e),ce=o(e,"P",{"data-svelte-h":!0}),r(ce)!=="svelte-rncryh"&&(ce.innerHTML=Jl),Ct=a(e),c(de.$$.fragment,e),kt=a(e),me=o(e,"P",{"data-svelte-h":!0}),r(me)!=="svelte-1jmhax9"&&(me.innerHTML=gl),$t=a(e),c(ue.$$.fragment,e),xt=a(e),c(Me.$$.fragment,e),It=a(e),he=o(e,"P",{"data-svelte-h":!0}),r(he)!=="svelte-102wbab"&&(he.textContent=Cl),vt=a(e),ye=o(e,"OL",{"data-svelte-h":!0}),r(ye)!=="svelte-2mf30q"&&(ye.innerHTML=kl),Nt=a(e),fe=o(e,"P",{"data-svelte-h":!0}),r(fe)!=="svelte-qsn61q"&&(fe.innerHTML=$l),At=a(e),c(Te.$$.fragment,e),Qt=a(e),we=o(e,"P",{"data-svelte-h":!0}),r(we)!=="svelte-150j4fc"&&(we.innerHTML=xl),Bt=a(e),c(Ue.$$.fragment,e),Lt=a(e),be=o(e,"P",{"data-svelte-h":!0}),r(be)!=="svelte-ru08f4"&&(be.innerHTML=Il),Gt=a(e),c(je.$$.fragment,e),Ht=a(e),Je=o(e,"P",{"data-svelte-h":!0}),r(Je)!=="svelte-ne6ecm"&&(Je.textContent=vl),Vt=a(e),c(ge.$$.fragment,e),_t=a(e),Ce=o(e,"P",{"data-svelte-h":!0}),r(Ce)!=="svelte-d41u1v"&&(Ce.textContent=Nl),Zt=a(e),c(ke.$$.fragment,e),Rt=a(e),$e=o(e,"P",{"data-svelte-h":!0}),r($e)!=="svelte-454bv6"&&($e.textContent=Al),St=a(e),c(xe.$$.fragment,e),Wt=a(e),ve=o(e,"P",{}),Ql(ve).forEach(l),this.h()},h(){Et(f,"name","hf:doc:metadata"),Et(f,"content",Dl),Et(T,"class","note"),Et(w,"class","note")},m(e,t){Zl(document.head,f),s(e,Ne,t),s(e,Ie,t),s(e,Ae,t),d(U,e,t),s(e,Qe,t),d(b,e,t),s(e,Be,t),s(e,j,t),s(e,Le,t),s(e,J,t),s(e,Ge,t),s(e,g,t),s(e,He,t),d(C,e,t),s(e,Ve,t),s(e,k,t),s(e,_e,t),s(e,$,t),s(e,Ze,t),s(e,x,t),s(e,Re,t),s(e,I,t),s(e,Se,t),d(v,e,t),s(e,We,t),s(e,T,t),s(e,De,t),d(N,e,t),s(e,Ee,t),s(e,A,t),s(e,Pe,t),s(e,Q,t),s(e,Xe,t),s(e,B,t),s(e,Ye,t),s(e,L,t),s(e,Fe,t),d(G,e,t),s(e,qe,t),s(e,H,t),s(e,ze,t),d(V,e,t),s(e,Oe,t),s(e,_,t),s(e,Ke,t),d(Z,e,t),s(e,et,t),s(e,R,t),s(e,tt,t),d(S,e,t),s(e,lt,t),s(e,W,t),s(e,st,t),d(D,e,t),s(e,nt,t),d(E,e,t),s(e,at,t),s(e,P,t),s(e,it,t),d(X,e,t),s(e,ot,t),s(e,Y,t),s(e,rt,t),d(F,e,t),s(e,pt,t),s(e,q,t),s(e,ct,t),s(e,z,t),s(e,dt,t),s(e,O,t),s(e,mt,t),s(e,K,t),s(e,ut,t),s(e,ee,t),s(e,Mt,t),d(te,e,t),s(e,ht,t),s(e,le,t),s(e,yt,t),d(se,e,t),s(e,ft,t),s(e,ne,t),s(e,Tt,t),s(e,ae,t),s(e,wt,t),s(e,w,t),s(e,Ut,t),s(e,ie,t),s(e,bt,t),s(e,oe,t),s(e,jt,t),s(e,re,t),s(e,Jt,t),d(pe,e,t),s(e,gt,t),s(e,ce,t),s(e,Ct,t),d(de,e,t),s(e,kt,t),s(e,me,t),s(e,$t,t),d(ue,e,t),s(e,xt,t),d(Me,e,t),s(e,It,t),s(e,he,t),s(e,vt,t),s(e,ye,t),s(e,Nt,t),s(e,fe,t),s(e,At,t),d(Te,e,t),s(e,Qt,t),s(e,we,t),s(e,Bt,t),d(Ue,e,t),s(e,Lt,t),s(e,be,t),s(e,Gt,t),d(je,e,t),s(e,Ht,t),s(e,Je,t),s(e,Vt,t),d(ge,e,t),s(e,_t,t),s(e,Ce,t),s(e,Zt,t),d(ke,e,t),s(e,Rt,t),s(e,$e,t),s(e,St,t),d(xe,e,t),s(e,Wt,t),s(e,ve,t),Dt=!0},p:Ll,i(e){Dt||(m(U.$$.fragment,e),m(b.$$.fragment,e),m(C.$$.fragment,e),m(v.$$.fragment,e),m(N.$$.fragment,e),m(G.$$.fragment,e),m(V.$$.fragment,e),m(Z.$$.fragment,e),m(S.$$.fragment,e),m(D.$$.fragment,e),m(E.$$.fragment,e),m(X.$$.fragment,e),m(F.$$.fragment,e),m(te.$$.fragment,e),m(se.$$.fragment,e),m(pe.$$.fragment,e),m(de.$$.fragment,e),m(ue.$$.fragment,e),m(Me.$$.fragment,e),m(Te.$$.fragment,e),m(Ue.$$.fragment,e),m(je.$$.fragment,e),m(ge.$$.fragment,e),m(ke.$$.fragment,e),m(xe.$$.fragment,e),Dt=!0)},o(e){u(U.$$.fragment,e),u(b.$$.fragment,e),u(C.$$.fragment,e),u(v.$$.fragment,e),u(N.$$.fragment,e),u(G.$$.fragment,e),u(V.$$.fragment,e),u(Z.$$.fragment,e),u(S.$$.fragment,e),u(D.$$.fragment,e),u(E.$$.fragment,e),u(X.$$.fragment,e),u(F.$$.fragment,e),u(te.$$.fragment,e),u(se.$$.fragment,e),u(pe.$$.fragment,e),u(de.$$.fragment,e),u(ue.$$.fragment,e),u(Me.$$.fragment,e),u(Te.$$.fragment,e),u(Ue.$$.fragment,e),u(je.$$.fragment,e),u(ge.$$.fragment,e),u(ke.$$.fragment,e),u(xe.$$.fragment,e),Dt=!1},d(e){e&&(l(Ne),l(Ie),l(Ae),l(Qe),l(Be),l(j),l(Le),l(J),l(Ge),l(g),l(He),l(Ve),l(k),l(_e),l($),l(Ze),l(x),l(Re),l(I),l(Se),l(We),l(T),l(De),l(Ee),l(A),l(Pe),l(Q),l(Xe),l(B),l(Ye),l(L),l(Fe),l(qe),l(H),l(ze),l(Oe),l(_),l(Ke),l(et),l(R),l(tt),l(lt),l(W),l(st),l(nt),l(at),l(P),l(it),l(ot),l(Y),l(rt),l(pt),l(q),l(ct),l(z),l(dt),l(O),l(mt),l(K),l(ut),l(ee),l(Mt),l(ht),l(le),l(yt),l(ft),l(ne),l(Tt),l(ae),l(wt),l(w),l(Ut),l(ie),l(bt),l(oe),l(jt),l(re),l(Jt),l(gt),l(ce),l(Ct),l(kt),l(me),l($t),l(xt),l(It),l(he),l(vt),l(ye),l(Nt),l(fe),l(At),l(Qt),l(we),l(Bt),l(Lt),l(be),l(Gt),l(Ht),l(Je),l(Vt),l(_t),l(Ce),l(Zt),l(Rt),l($e),l(St),l(Wt),l(ve)),l(f),M(U,e),M(b,e),M(C,e),M(v,e),M(N,e),M(G,e),M(V,e),M(Z,e),M(S,e),M(D,e),M(E,e),M(X,e),M(F,e),M(te,e),M(se,e),M(pe,e),M(de,e),M(ue,e),M(Me,e),M(Te,e),M(Ue,e),M(je,e),M(ge,e),M(ke,e),M(xe,e)}}}const Dl='{"title":"Writing custom kernels with code agents","local":"writing-custom-kernels-with-code-agents","sections":[{"title":"Before you start","local":"before-you-start","sections":[],"depth":2},{"title":"1. Give the agent a precise task prompt","local":"1-give-the-agent-a-precise-task-prompt","sections":[],"depth":2},{"title":"2. Verify that the agent produces a complete kernel project","local":"2-verify-that-the-agent-produces-a-complete-kernel-project","sections":[],"depth":2},{"title":"3. Review the generated files","local":"3-review-the-generated-files","sections":[{"title":"build.toml","local":"buildtoml","sections":[],"depth":3},{"title":"Torch bindings","local":"torch-bindings","sections":[],"depth":3},{"title":"Model integration code","local":"model-integration-code","sections":[],"depth":3}],"depth":2},{"title":"5. Build and test, and benchmark","local":"5-build-and-test-and-benchmark","sections":[],"depth":2},{"title":"6. Benchmark","local":"6-benchmark","sections":[],"depth":2},{"title":"7. Publish to the Hub","local":"7-publish-to-the-hub","sections":[],"depth":2}],"depth":1}';function El(Pt){return Gl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zl extends Hl{constructor(f){super(),Vl(this,f,El,Wl,Bl,{})}}export{zl as component};

Xet Storage Details

Size:
30.8 kB
·
Xet hash:
03b895e757b3a86a1f0d546788714d64959f2744d2f2d3c125e2bac06979b566

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.