Buckets:

rtrm's picture
download
raw
15.4 kB
import{s as nt,n as it,o as st}from"../chunks/scheduler.f3b1e791.js";import{S as at,i as pt,e as a,s as i,c as r,h as rt,a as p,d as l,b as s,f as tt,g as o,j as d,k as lt,l as ot,m as n,n as m,t as c,o as h,p as u}from"../chunks/index.023a9934.js";import{C as dt}from"../chunks/CopyLLMTxtMenu.c8fa3394.js";import{C as M}from"../chunks/CodeBlock.188f1643.js";import{H as q,E as mt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.607c48e8.js";function ct(Be){let f,ee,D,te,y,le,$,ne,w,Se=`The kernel builder uses Nix for building kernels. You can build or
run the kernels directly if you have Nix installed on your system.
We recommend installing Nix in the following way:`,ie,g,_e=`<li>Linux: use the <a href="https://nixos.org/download/" rel="nofollow">official Nix installer</a>.</li> <li>macOS: use the <a href="https://docs.determinate.systems/determinate-nix/" rel="nofollow">Determinate Nix installer</a>.
In addition, Xcode 16.x is currently required to build kernels.</li>`,se,T,ae,b,We=`The easiest way get all the Nix functionality is by putting a
<code>flake.nix</code> in your kernel repository. To do so, copy
<a href="https://github.com/huggingface/kernels/blob/main/examples/kernels/relu/flake.nix" rel="nofollow"><code>examples/relu/flake.nix</code></a> into the
same directory as your <code>build.toml</code> file. Then run <code>nix flake update</code>.
This generates a <code>flake.lock</code> file that pins the kernel builder
and <em>all</em> its transitive dependencies. Commit both <code>flake.nix</code>
and <code>flake.lock</code> to your repository, this will ensure that kernel
builds are reproducible.`,pe,k,Ve=`Since the kernel builder depends on many packages (e.g. every supported
PyTorch version), it is recommended to enable the huggingface cache
to avoid expensive rebuilds.`,re,x,Qe="To use the cache, you can either install cachix and configure it:",oe,v,de,U,Ee="Or run it once without installing cachix permanently:",me,C,ce,J,Pe=`The kernel builder also provides Nix development shells with all Torch
and CUDA/ROCm dependencies needed to develop kernels (see below). If
you want to test your kernels inside a Nix development shell and you
are not using NixOS, <a href="https://danieldk.eu/Nix-CUDA-on-non-NixOS-systems#make-runopengl-driverlib-and-symlink-the-driver-library" rel="nofollow">make sure that the CUDA driver is visible</a> to Torch.`,he,j,ue,I,Ye=`A kernel that has a <code>flake.nix</code> file can be built with the <code>build-and-copy</code>
command. For example:`,fe,G,Me,N,ze="The compiled kernel will then be in the local <code>build/</code> directory.",ye,A,$e,H,Fe=`<code>kernel-builder</code> provides shells for developing kernels. In such a shell,
all required dependencies are available, as well as <code>kernel-builder</code> for generating
project files. For example:`,we,Z,ge,L,Re=`If you want to test the kernel as a Python package, you can do so.
<code>nix develop</code> will automatically create a virtual environment in the
<code>.venv</code> and activate it. You can install the kernel as a regular
Python package in this virtual environment:`,Te,B,be,S,Xe=`Development shells are available for every build configuration. For
instance, you can get a Torch 2.7 development shell for ROCm extensions
using:`,ke,_,xe,W,ve,V,Oe=`You can also start a development shell. This will give you a Python interpreter
with the kernel in Python’s search path. This makes it more convenient to run
tests:`,Ue,Q,Ce,E,Je,P,qe=`You can add test dependencies to a development or testing shell. Adapt
the kernel’s <code>flake.nix</code> to use the <code>pythonCheckInputs</code> option:`,je,Y,Ie,z,De='The available packages can be found on <a href="https://search.nixos.org/packages?channel=25.05&amp;query=python312Packages" rel="nofollow">search.nixos.org</a>.',Ge,F,Ke=`Keep in mind that these additional dependencies will only be available to
the Nix shells, not the final kernel uploaded to the Hub.`,Ne,R,Ae,X,et=`<code>kernel-builder</code> verifies that a kernel can be
imported with the <a href="https://github.com/huggingface/kernels" rel="nofollow"><code>kernels</code></a>
package. This check can be disabled by passing <code>doGetKernelCheck = false</code>
to <code>genKernelFlakeOutputs</code>. <strong>Warning:</strong> it is strongly recommended to keep
this check enabled, as it is one of the checks that validates that a kernel
is compliant. This option is primarily intended for kernels with
<code>triton.autotune</code> decorators, which can fail because there is no GPU available
in the build sandbox.`,He,O,Ze,K,Le;return y=new dt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),$=new q({props:{title:"Using the kernel builder with Nix",local:"using-the-kernel-builder-with-nix",headingTag:"h1"}}),T=new q({props:{title:"Getting started",local:"getting-started",headingTag:"h2"}}),v=new M({props:{code:"JTIzJTIwSW5zdGFsbCUyMGNhY2hpeCUyMGFuZCUyMGNvbmZpZ3VyZSUyMHRoZSUyMGNhY2hlJTBBY2FjaGl4JTIwdXNlJTIwaHVnZ2luZ2ZhY2U=",highlighted:`<span class="hljs-comment"># Install cachix and configure the cache</span>
cachix use huggingface`,wrap:!1}}),C=new M({props:{code:"JTIzJTIwVXNlJTIwY2FjaGl4JTIwd2l0aG91dCUyMGluc3RhbGxpbmclMjBpdCUwQW5peCUyMHJ1biUyMG5peHBrZ3MlMjNjYWNoaXglMjAtLSUyMHVzZSUyMGh1Z2dpbmdmYWNl",highlighted:`<span class="hljs-comment"># Use cachix without installing it</span>
nix run nixpkgs<span class="hljs-comment">#cachix -- use huggingface</span>`,wrap:!1}}),j=new q({props:{title:"Building kernels with Nix",local:"building-kernels-with-nix",headingTag:"h2"}}),G=new M({props:{code:"Y2QlMjBleGFtcGxlcyUyRnJlbHUlMEFuaXglMjBydW4lMjAuJTIzYnVpbGQtYW5kLWNvcHklMjAtTA==",highlighted:`<span class="hljs-built_in">cd</span> examples/relu
nix run .<span class="hljs-comment">#build-and-copy -L</span>`,wrap:!1}}),A=new q({props:{title:"Shell for local development",local:"shell-for-local-development",headingTag:"h2"}}),Z=new M({props:{code:"JTI0JTIwbml4JTIwZGV2ZWxvcCUwQSUyNCUyMGtlcm5lbC1idWlsZGVyJTIwY3JlYXRlLXB5cHJvamVjdCUwQSUyNCUyMGNtYWtlJTIwLUIlMjBidWlsZC1leHQlMEElMjQlMjBjbWFrZSUyMC0tYnVpbGQlMjBidWlsZC1leHQ=",highlighted:`$ nix develop
$ kernel-builder create-pyproject
$ cmake -B build-ext
$ cmake --build build-ext`,wrap:!1}}),B=new M({props:{code:"JTI0JTIwbml4JTIwZGV2ZWxvcCUwQSUyNCUyMGtlcm5lbC1idWlsZGVyJTIwY3JlYXRlLXB5cHJvamVjdCUwQSUyNCUyMHBpcCUyMGluc3RhbGwlMjAtLW5vLWJ1aWxkLWlzb2xhdGlvbiUyMC1lJTIwLg==",highlighted:`$ nix develop
$ kernel-builder create-pyproject
$ pip install --no-build-isolation -e .`,wrap:!1}}),_=new M({props:{code:"JTI0JTIwcm0lMjAtcmYlMjAudmVudiUyMCUyMCUyMyUyMFJlbW92ZSUyMGV4aXN0aW5nJTIwdmVudiUyMGlmJTIwYW55LiUwQSUyNCUyMG5peCUyMGRldmVsb3AlMjAuJTIzZGV2U2hlbGxzLnRvcmNoMjktY3h4MTEtcm9jbTY0LXg4Nl82NC1saW51eA==",highlighted:`$ <span class="hljs-built_in">rm</span> -rf .venv <span class="hljs-comment"># Remove existing venv if any.</span>
$ nix develop .<span class="hljs-comment">#devShells.torch29-cxx11-rocm64-x86_64-linux</span>`,wrap:!1}}),W=new q({props:{title:"Shell for testing a kernel",local:"shell-for-testing-a-kernel",headingTag:"h2"}}),Q=new M({props:{code:"Y2QlMjBleGFtcGxlcyUyRnJlbHUlMEFuaXglMjBkZXZlbG9wJTIwLUwlMjAuJTIzdGVzdCUwQXB5dGhvbiUyMC1tJTIwcHl0ZXN0JTIwdGVzdHM=",highlighted:`<span class="hljs-built_in">cd</span> examples/relu
nix develop -L .<span class="hljs-comment">#test</span>
python -m pytest tests`,wrap:!1}}),E=new q({props:{title:"Adding test dependencies to development shells",local:"adding-test-dependencies-to-development-shells",headingTag:"h2"}}),Y=new M({props:{code:"JTdCJTBBJTIwJTIwZGVzY3JpcHRpb24lMjAlM0QlMjAlMjJGbGFrZSUyMGZvciUyMG15JTIwa2VybmVsJTIyJTNCJTBBJTBBJTIwJTIwaW5wdXRzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwYnVpbGRlci51cmwlMjAlM0QlMjAlMjJnaXRodWIlM0FodWdnaW5nZmFjZSUyRmtlcm5lbHMlMjIlM0IlMEElMjAlMjAlN0QlM0IlMEElMEElMjAlMjBvdXRwdXRzJTIwJTNEJTBBJTIwJTIwJTIwJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwc2VsZiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMGJ1aWxkZXIlMkMlMEElMjAlMjAlMjAlMjAlN0QlM0ElMEElMjAlMjAlMjAlMjBidWlsZGVyLmxpYi5nZW5LZXJuZWxGbGFrZU91dHB1dHMlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjBpbmhlcml0JTIwc2VsZiUzQiUwQSUyMCUyMCUyMCUyMCUyMCUyMHBhdGglMjAlM0QlMjAuJTJGLiUzQiUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMFRoZSUyMGVpbm9wcyUyMGFuZCUyMG51bXB5JTIwdGVzdCUyMGRlcGVuZGVuY2llcyUyMGFyZSUyMGFkZGVkJTIwaGVyZSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMHB5dGhvbkNoZWNrSW5wdXRzJTIwJTNEJTIwcGtncyUzQSUyMHdpdGglMjBwa2dzJTNCJTIwJTVCJTIwZWlub3BzJTIwbnVtcHklMjAlNUQlM0IlMEElMjAlMjAlMjAlMjAlN0QlM0IlMEElN0Q=",highlighted:`{
<span class="hljs-attr">description</span> = <span class="hljs-string">&quot;Flake for my kernel&quot;</span>;
<span class="hljs-attr">inputs</span> = {
builder.<span class="hljs-attr">url</span> = <span class="hljs-string">&quot;github:huggingface/kernels&quot;</span>;
};
<span class="hljs-attr">outputs</span> =
{
self,
builder,
}:
builder.lib.genKernelFlakeOutputs {
<span class="hljs-keyword">inherit</span> self;
<span class="hljs-attr">path</span> = ./.;
<span class="hljs-comment"># The einops and numpy test dependencies are added here:</span>
<span class="hljs-attr">pythonCheckInputs</span> = pkgs: <span class="hljs-keyword">with</span> pkgs; [ einops numpy ];
};
}`,wrap:!1}}),R=new q({props:{title:"Skipping the get_kernel check",local:"skipping-the-getkernel-check",headingTag:"h2"}}),O=new mt({props:{source:"https://github.com/huggingface/kernels/blob/main/docs/source/builder/nix.md"}}),{c(){f=a("meta"),ee=i(),D=a("p"),te=i(),r(y.$$.fragment),le=i(),r($.$$.fragment),ne=i(),w=a("p"),w.textContent=Se,ie=i(),g=a("ul"),g.innerHTML=_e,se=i(),r(T.$$.fragment),ae=i(),b=a("p"),b.innerHTML=We,pe=i(),k=a("p"),k.textContent=Ve,re=i(),x=a("p"),x.textContent=Qe,oe=i(),r(v.$$.fragment),de=i(),U=a("p"),U.textContent=Ee,me=i(),r(C.$$.fragment),ce=i(),J=a("p"),J.innerHTML=Pe,he=i(),r(j.$$.fragment),ue=i(),I=a("p"),I.innerHTML=Ye,fe=i(),r(G.$$.fragment),Me=i(),N=a("p"),N.innerHTML=ze,ye=i(),r(A.$$.fragment),$e=i(),H=a("p"),H.innerHTML=Fe,we=i(),r(Z.$$.fragment),ge=i(),L=a("p"),L.innerHTML=Re,Te=i(),r(B.$$.fragment),be=i(),S=a("p"),S.textContent=Xe,ke=i(),r(_.$$.fragment),xe=i(),r(W.$$.fragment),ve=i(),V=a("p"),V.textContent=Oe,Ue=i(),r(Q.$$.fragment),Ce=i(),r(E.$$.fragment),Je=i(),P=a("p"),P.innerHTML=qe,je=i(),r(Y.$$.fragment),Ie=i(),z=a("p"),z.innerHTML=De,Ge=i(),F=a("p"),F.textContent=Ke,Ne=i(),r(R.$$.fragment),Ae=i(),X=a("p"),X.innerHTML=et,He=i(),r(O.$$.fragment),Ze=i(),K=a("p"),this.h()},l(e){const t=rt("svelte-u9bgzb",document.head);f=p(t,"META",{name:!0,content:!0}),t.forEach(l),ee=s(e),D=p(e,"P",{}),tt(D).forEach(l),te=s(e),o(y.$$.fragment,e),le=s(e),o($.$$.fragment,e),ne=s(e),w=p(e,"P",{"data-svelte-h":!0}),d(w)!=="svelte-5zbxl"&&(w.textContent=Se),ie=s(e),g=p(e,"UL",{"data-svelte-h":!0}),d(g)!=="svelte-yt841z"&&(g.innerHTML=_e),se=s(e),o(T.$$.fragment,e),ae=s(e),b=p(e,"P",{"data-svelte-h":!0}),d(b)!=="svelte-pot28s"&&(b.innerHTML=We),pe=s(e),k=p(e,"P",{"data-svelte-h":!0}),d(k)!=="svelte-1gt1gp0"&&(k.textContent=Ve),re=s(e),x=p(e,"P",{"data-svelte-h":!0}),d(x)!=="svelte-ephjfc"&&(x.textContent=Qe),oe=s(e),o(v.$$.fragment,e),de=s(e),U=p(e,"P",{"data-svelte-h":!0}),d(U)!=="svelte-vbvwso"&&(U.textContent=Ee),me=s(e),o(C.$$.fragment,e),ce=s(e),J=p(e,"P",{"data-svelte-h":!0}),d(J)!=="svelte-1edfy9h"&&(J.innerHTML=Pe),he=s(e),o(j.$$.fragment,e),ue=s(e),I=p(e,"P",{"data-svelte-h":!0}),d(I)!=="svelte-1rxsg0s"&&(I.innerHTML=Ye),fe=s(e),o(G.$$.fragment,e),Me=s(e),N=p(e,"P",{"data-svelte-h":!0}),d(N)!=="svelte-19cfesj"&&(N.innerHTML=ze),ye=s(e),o(A.$$.fragment,e),$e=s(e),H=p(e,"P",{"data-svelte-h":!0}),d(H)!=="svelte-z48w5c"&&(H.innerHTML=Fe),we=s(e),o(Z.$$.fragment,e),ge=s(e),L=p(e,"P",{"data-svelte-h":!0}),d(L)!=="svelte-1k3n6o8"&&(L.innerHTML=Re),Te=s(e),o(B.$$.fragment,e),be=s(e),S=p(e,"P",{"data-svelte-h":!0}),d(S)!=="svelte-17n211x"&&(S.textContent=Xe),ke=s(e),o(_.$$.fragment,e),xe=s(e),o(W.$$.fragment,e),ve=s(e),V=p(e,"P",{"data-svelte-h":!0}),d(V)!=="svelte-28aru6"&&(V.textContent=Oe),Ue=s(e),o(Q.$$.fragment,e),Ce=s(e),o(E.$$.fragment,e),Je=s(e),P=p(e,"P",{"data-svelte-h":!0}),d(P)!=="svelte-1f12544"&&(P.innerHTML=qe),je=s(e),o(Y.$$.fragment,e),Ie=s(e),z=p(e,"P",{"data-svelte-h":!0}),d(z)!=="svelte-1yhwali"&&(z.innerHTML=De),Ge=s(e),F=p(e,"P",{"data-svelte-h":!0}),d(F)!=="svelte-1p7pfs6"&&(F.textContent=Ke),Ne=s(e),o(R.$$.fragment,e),Ae=s(e),X=p(e,"P",{"data-svelte-h":!0}),d(X)!=="svelte-czbbir"&&(X.innerHTML=et),He=s(e),o(O.$$.fragment,e),Ze=s(e),K=p(e,"P",{}),tt(K).forEach(l),this.h()},h(){lt(f,"name","hf:doc:metadata"),lt(f,"content",ht)},m(e,t){ot(document.head,f),n(e,ee,t),n(e,D,t),n(e,te,t),m(y,e,t),n(e,le,t),m($,e,t),n(e,ne,t),n(e,w,t),n(e,ie,t),n(e,g,t),n(e,se,t),m(T,e,t),n(e,ae,t),n(e,b,t),n(e,pe,t),n(e,k,t),n(e,re,t),n(e,x,t),n(e,oe,t),m(v,e,t),n(e,de,t),n(e,U,t),n(e,me,t),m(C,e,t),n(e,ce,t),n(e,J,t),n(e,he,t),m(j,e,t),n(e,ue,t),n(e,I,t),n(e,fe,t),m(G,e,t),n(e,Me,t),n(e,N,t),n(e,ye,t),m(A,e,t),n(e,$e,t),n(e,H,t),n(e,we,t),m(Z,e,t),n(e,ge,t),n(e,L,t),n(e,Te,t),m(B,e,t),n(e,be,t),n(e,S,t),n(e,ke,t),m(_,e,t),n(e,xe,t),m(W,e,t),n(e,ve,t),n(e,V,t),n(e,Ue,t),m(Q,e,t),n(e,Ce,t),m(E,e,t),n(e,Je,t),n(e,P,t),n(e,je,t),m(Y,e,t),n(e,Ie,t),n(e,z,t),n(e,Ge,t),n(e,F,t),n(e,Ne,t),m(R,e,t),n(e,Ae,t),n(e,X,t),n(e,He,t),m(O,e,t),n(e,Ze,t),n(e,K,t),Le=!0},p:it,i(e){Le||(c(y.$$.fragment,e),c($.$$.fragment,e),c(T.$$.fragment,e),c(v.$$.fragment,e),c(C.$$.fragment,e),c(j.$$.fragment,e),c(G.$$.fragment,e),c(A.$$.fragment,e),c(Z.$$.fragment,e),c(B.$$.fragment,e),c(_.$$.fragment,e),c(W.$$.fragment,e),c(Q.$$.fragment,e),c(E.$$.fragment,e),c(Y.$$.fragment,e),c(R.$$.fragment,e),c(O.$$.fragment,e),Le=!0)},o(e){h(y.$$.fragment,e),h($.$$.fragment,e),h(T.$$.fragment,e),h(v.$$.fragment,e),h(C.$$.fragment,e),h(j.$$.fragment,e),h(G.$$.fragment,e),h(A.$$.fragment,e),h(Z.$$.fragment,e),h(B.$$.fragment,e),h(_.$$.fragment,e),h(W.$$.fragment,e),h(Q.$$.fragment,e),h(E.$$.fragment,e),h(Y.$$.fragment,e),h(R.$$.fragment,e),h(O.$$.fragment,e),Le=!1},d(e){e&&(l(ee),l(D),l(te),l(le),l(ne),l(w),l(ie),l(g),l(se),l(ae),l(b),l(pe),l(k),l(re),l(x),l(oe),l(de),l(U),l(me),l(ce),l(J),l(he),l(ue),l(I),l(fe),l(Me),l(N),l(ye),l($e),l(H),l(we),l(ge),l(L),l(Te),l(be),l(S),l(ke),l(xe),l(ve),l(V),l(Ue),l(Ce),l(Je),l(P),l(je),l(Ie),l(z),l(Ge),l(F),l(Ne),l(Ae),l(X),l(He),l(Ze),l(K)),l(f),u(y,e),u($,e),u(T,e),u(v,e),u(C,e),u(j,e),u(G,e),u(A,e),u(Z,e),u(B,e),u(_,e),u(W,e),u(Q,e),u(E,e),u(Y,e),u(R,e),u(O,e)}}}const ht='{"title":"Using the kernel builder with Nix","local":"using-the-kernel-builder-with-nix","sections":[{"title":"Getting started","local":"getting-started","sections":[],"depth":2},{"title":"Building kernels with Nix","local":"building-kernels-with-nix","sections":[],"depth":2},{"title":"Shell for local development","local":"shell-for-local-development","sections":[],"depth":2},{"title":"Shell for testing a kernel","local":"shell-for-testing-a-kernel","sections":[],"depth":2},{"title":"Adding test dependencies to development shells","local":"adding-test-dependencies-to-development-shells","sections":[],"depth":2},{"title":"Skipping the get_kernel check","local":"skipping-the-getkernel-check","sections":[],"depth":2}],"depth":1}';function ut(Be){return st(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gt extends at{constructor(f){super(),pt(this,f,ut,ct,nt,{})}}export{gt as component};

Xet Storage Details

Size:
15.4 kB
·
Xet hash:
baac10d1a92c5a1fb154b8985cabd5b2bcdd556804dcf5eea512feb897b43f78

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