Buckets:
| import"../chunks/DsnmJJEf.js";import{i as ne,h as oe,C as re,H as n,D as o,E as y,a as te,s as ae,b as T}from"../chunks/Boe5hxto.js";import{p as le,o as se,s as e,f as p,a as c,b as de,c as r,d as M,r as t,n as s}from"../chunks/CMKpKl_X.js";const ie='{"title":"Kernels API Reference","local":"kernels-api-reference","sections":[{"title":"Main Functions","local":"main-functions","sections":[{"title":"get_kernel","local":"kernels.get_kernel","sections":[],"depth":3},{"title":"get_local_kernel","local":"kernels.get_local_kernel","sections":[],"depth":3},{"title":"has_kernel","local":"kernels.has_kernel","sections":[],"depth":3},{"title":"get_kernel_variants","local":"kernels.get_kernel_variants","sections":[],"depth":3},{"title":"get_loaded_kernels","local":"kernels.get_loaded_kernels","sections":[],"depth":3}],"depth":2},{"title":"Loading locked kernels","local":"loading-locked-kernels","sections":[{"title":"load_kernel","local":"kernels.load_kernel","sections":[],"depth":3},{"title":"get_locked_kernel","local":"kernels.get_locked_kernel","sections":[],"depth":3}],"depth":2},{"title":"Classes","local":"classes","sections":[{"title":"LoadedKernel","local":"kernels.LoadedKernel","sections":[],"depth":3},{"title":"RepoInfo","local":"kernels.RepoInfo","sections":[],"depth":3}],"depth":2}],"depth":1}';var ce=M('<meta name="hf:doc:metadata"/>'),w=M("<p>Example:</p> <!>",1),pe=M(`<p></p> <!> <!> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load a kernel from the kernel hub.</p> <p>This function downloads a kernel to the local Hugging Face Hub cache directory (if it was not downloaded before) | |
| and then loads the kernel.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Import a kernel from a local kernel repository path.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Check whether a kernel build exists for the current environment (Torch version and compute framework).</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Resolve all build variants of a kernel against the current environment.</p> <p>The decisions are sorted with compatible variants first, the most preferred | |
| variant leading.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Return a snapshot of every kernel that has been loaded into the current process.</p> <p>The returned list is a new list; mutating it does not affect the registry.</p> <!></div> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get a pre-downloaded, locked kernel.</p> <p>If <code>lockfile</code> is not specified, the lockfile will be loaded from the caller’s package metadata.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get a kernel using a lock file.</p></div> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This dataclass provides information about a loaded kernel:</p> <ul><li><code>metadata</code> (<code>Metadata</code>): kernel metadata.</li> <li><code>module</code> (<code>ModuleType</code>): the imported kernel module.</li> <li><code>repo_info</code> (<code>kernels.hf_hub.RepoInfo | None</code>): populated only for | |
| kernels loaded via <code>get_kernel</code>. Loaders that work from a local path | |
| (<code>get_local_kernel</code>) or a lockfile (<code>get_locked_kernel</code>, <code>load_kernel</code>) | |
| leave this as <code>None</code>.</li></ul> <p>The metadata includes the following properties that describe a kernel:</p> <ul><li><code>id</code> (<code>str</code>): kernel identifier that is unique to the kernel version + backend.</li> <li><code>name</code> (<code>str</code>): the name of the kernel.</li> <li><code>version</code> (<code>int</code>): the version of the kernel.</li> <li><code>license</code> (<code>str</code>): the license of the kernel.</li> <li><code>upstream</code> (<code>str | None</code>): the original upstream repository of the kernel.</li> <li><code>source</code> (<code>str | None</code>): the kernel-builder formatted source repository.</li> <li><code>python_depends</code> (<code>list[str]</code>): required Python dependencies.</li> <li><code>backend</code>: information about the kernel’s backend.</li></ul></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This dataclass stores the origin of the kernel.</p> <p>The following fields are available:</p> <ul><li><code>repo_id</code> (<code>str</code>): the Hub repository containing the kernel.</li> <li><code>revision</code> (<code>str</code>): the specific revision of the kernel.</li></ul></div> <!> <p></p>`,1);function ge(D,Q){le(Q,!1),se(()=>{new URLSearchParams(window.location.search).get("fw")}),ne();var x=pe();oe("dnj0ke",a=>{var d=ce();ae(d,"content",ie),c(a,d)});var j=e(p(x),2);re(j,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var J=e(j,2);n(J,{title:"Kernels API Reference",local:"kernels-api-reference",headingTag:"h1"});var I=e(J,2);n(I,{title:"Main Functions",local:"main-functions",headingTag:"h2"});var N=e(I,2);n(N,{title:"get_kernel",local:"kernels.get_kernel",headingTag:"h3"});var m=e(N,2),Z=r(m);o(Z,{name:"kernels.get_kernel",anchor:"kernels.get_kernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/load.py#L47",parameters:[{name:"repo_id",val:": str"},{name:"revision",val:": str | None = None"},{name:"version",val:": int | None = None"},{name:"backend",val:": str | None = None"},{name:"user_agent",val:": str | dict | None = None"},{name:"trust_remote_code",val:": bool | list[str] = False"}],parametersDescription:[{anchor:"kernels.get_kernel.repo_id",description:`<strong>repo_id</strong> (<em>str</em>) — | |
| The Hub repository containing the kernel.`,name:"repo_id"},{anchor:"kernels.get_kernel.revision",description:`<strong>revision</strong> (<em>str</em>, <em>optional</em>) — | |
| The specific revision (branch, tag, or commit) to download. Cannot be used together with <em>version</em>.`,name:"revision"},{anchor:"kernels.get_kernel.version",description:`<strong>version</strong> (<em>int</em>, <em>optional</em>) — | |
| The kernel version to download. Cannot be used together with <em>revision</em>. | |
| Either <em>version</em> or <em>revision</em> must be specified.`,name:"version"},{anchor:"kernels.get_kernel.backend",description:`<strong>backend</strong> (<em>str</em>, <em>optional</em>) — | |
| The backend to load the kernel for. Can only be <em>cpu</em> or the backend that Torch is compiled for. | |
| The backend will be detected automatically if not provided.`,name:"backend"},{anchor:"kernels.get_kernel.user_agent",description:`<strong>user_agent</strong> (<em>Union[str, dict]</em>, <em>optional</em>) — | |
| The <em>user_agent</em> info to pass to <em>snapshot_download()</em> for internal telemetry.`,name:"user_agent"},{anchor:"kernels.get_kernel.trust_remote_code",description:`<strong>trust_remote_code</strong> (<em>bool | list[str]</em>, <em>optional</em>, defaults to <em>False</em>) — | |
| Whether to allow loading kernels from untrusted organisations. When <code>False</code>, | |
| only kernels from trusted organisations are allowed. When <code>True</code>, all | |
| repositories are allowed. A list of strings will be used to verify signing | |
| identities in a future release; for now it emits a warning and falls | |
| back to the default trust check.`,name:"trust_remote_code"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The imported kernel module.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><em>ModuleType</em></p> | |
| `});var A=e(Z,6);y(A,{anchor:"kernels.get_kernel.example",children:(a,d)=>{var l=w(),i=e(p(l),2);T(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwa2VybmVscyUyMGltcG9ydCUyMGdldF9rZXJuZWwlMEElMEFhY3RpdmF0aW9uJTIwJTNEJTIwZ2V0X2tlcm5lbCglMjJrZXJuZWxzLWNvbW11bml0eSUyRnJlbHUlMjIlMkMlMjB2ZXJzaW9uJTNEMSklMEF4JTIwJTNEJTIwdG9yY2gucmFuZG4oMTAlMkMlMjAyMCUyQyUyMGRldmljZSUzRCUyMmN1ZGElMjIpJTBBb3V0JTIwJTNEJTIwdG9yY2guZW1wdHlfbGlrZSh4KSUwQXJlc3VsdCUyMCUzRCUyMGFjdGl2YXRpb24ucmVsdShvdXQlMkMlMjB4KQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> kernels <span class="hljs-keyword">import</span> get_kernel | |
| activation = get_kernel(<span class="hljs-string">"kernels-community/relu"</span>, version=<span class="hljs-number">1</span>) | |
| x = torch.randn(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, device=<span class="hljs-string">"cuda"</span>) | |
| out = torch.empty_like(x) | |
| result = activation.relu(out, x)`,lang:"python",wrap:!1}),c(a,l)},$$slots:{default:!0}}),t(m);var B=e(m,2);n(B,{title:"get_local_kernel",local:"kernels.get_local_kernel",headingTag:"h3"});var h=e(B,2),Y=r(h);o(Y,{name:"kernels.get_local_kernel",anchor:"kernels.get_local_kernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/load.py#L126",parameters:[{name:"repo_path",val:": Path"},{name:"backend",val:": str | None = None"}],parametersDescription:[{anchor:"kernels.get_local_kernel.repo_path",description:`<strong>repo_path</strong> (<code>Path</code>) — | |
| The local path to the kernel repository.`,name:"repo_path"},{anchor:"kernels.get_local_kernel.backend",description:`<strong>backend</strong> (<code>str</code>, <em>optional</em>) — | |
| The backend to load the kernel for. Can only be <code>cpu</code> or the backend that Torch is compiled for. | |
| The backend will be detected automatically if not provided.`,name:"backend"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The imported kernel module.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>ModuleType</code></p> | |
| `}),s(2),t(h);var U=e(h,2);n(U,{title:"has_kernel",local:"kernels.has_kernel",headingTag:"h3"});var k=e(U,2),z=r(k);o(z,{name:"kernels.has_kernel",anchor:"kernels.has_kernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/load.py#L162",parameters:[{name:"repo_id",val:": str"},{name:"revision",val:": str | None = None"},{name:"version",val:": int | None = None"},{name:"backend",val:": str | None = None"}],parametersDescription:[{anchor:"kernels.has_kernel.repo_id",description:`<strong>repo_id</strong> (<code>str</code>) — | |
| The Hub repository containing the kernel.`,name:"repo_id"},{anchor:"kernels.has_kernel.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>) — | |
| The specific revision (branch, tag, or commit) to download. Cannot be used together with <code>version</code>.`,name:"revision"},{anchor:"kernels.has_kernel.version",description:`<strong>version</strong> (<code>int</code>, <em>optional</em>) — | |
| The kernel version to download. Cannot be used together with <code>revision</code>. | |
| Either <code>version</code> or <code>revision</code> must be specified.`,name:"version"},{anchor:"kernels.has_kernel.backend",description:`<strong>backend</strong> (<code>str</code>, <em>optional</em>) — | |
| The backend to load the kernel for. Can only be <code>cpu</code> or the backend that Torch is compiled for. | |
| The backend will be detected automatically if not provided.`,name:"backend"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>True</code> if a kernel is available for the current environment.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>bool</code></p> | |
| `}),s(2),t(k);var C=e(k,2);n(C,{title:"get_kernel_variants",local:"kernels.get_kernel_variants",headingTag:"h3"});var g=e(C,2),R=r(g);o(R,{name:"kernels.get_kernel_variants",anchor:"kernels.get_kernel_variants",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/variants.py#L558",parameters:[{name:"repo_id",val:": str"},{name:"revision",val:": str | None = None"},{name:"version",val:": int | None = None"},{name:"backend",val:": str | None = None"}],parametersDescription:[{anchor:"kernels.get_kernel_variants.repo_id",description:`<strong>repo_id</strong> (<code>str</code>) — | |
| The Hub repository containing the kernel.`,name:"repo_id"},{anchor:"kernels.get_kernel_variants.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>) — | |
| The specific revision (branch, tag, or commit) to inspect. Cannot be used together with <code>version</code>.`,name:"revision"},{anchor:"kernels.get_kernel_variants.version",description:`<strong>version</strong> (<code>int</code>, <em>optional</em>) — | |
| The kernel version to inspect. Cannot be used together with <code>revision</code>. | |
| Either <code>version</code> or <code>revision</code> must be specified.`,name:"version"},{anchor:"kernels.get_kernel_variants.backend",description:`<strong>backend</strong> (<code>str</code>, <em>optional</em>) — | |
| The backend to resolve variants for. Can only be <code>cpu</code> or the backend that Torch is compiled for. | |
| The backend will be detected automatically if not provided.`,name:"backend"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>One <code>VariantAccepted</code> or <code>VariantRejected</code> per build variant | |
| in the repository, compatible variants first.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>list[Decision]</code></p> | |
| `});var S=e(R,6);y(S,{anchor:"kernels.get_kernel_variants.example",children:(a,d)=>{var l=w(),i=e(p(l),2);T(i,{code:"ZnJvbSUyMGtlcm5lbHMlMjBpbXBvcnQlMjBnZXRfa2VybmVsX3ZhcmlhbnRzJTJDJTIwVmFyaWFudEFjY2VwdGVkJTBBJTBBZm9yJTIwZGVjaXNpb24lMjBpbiUyMGdldF9rZXJuZWxfdmFyaWFudHMoJTIya2VybmVscy1jb21tdW5pdHklMkZhY3RpdmF0aW9uJTIyJTJDJTIwdmVyc2lvbiUzRDEpJTNBJTBBJTIwJTIwJTIwJTIwbmFtZSUyMCUzRCUyMGRlY2lzaW9uLnZhcmlhbnQudmFyaWFudF9zdHIlMEElMjAlMjAlMjAlMjBpZiUyMGlzaW5zdGFuY2UoZGVjaXNpb24lMkMlMjBWYXJpYW50QWNjZXB0ZWQpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiU3Qm5hbWUlN0QlM0ElMjBjb21wYXRpYmxlJTIyKSUwQSUyMCUyMCUyMCUyMGVsc2UlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChmJTIyJTdCbmFtZSU3RCUzQSUyMHJlamVjdGVkJTIwKCU3QmRlY2lzaW9uLnJlYXNvbiU3RCklMjIpJTBB",highlighted:`<span class="hljs-keyword">from</span> kernels <span class="hljs-keyword">import</span> get_kernel_variants, VariantAccepted | |
| <span class="hljs-keyword">for</span> decision <span class="hljs-keyword">in</span> get_kernel_variants(<span class="hljs-string">"kernels-community/activation"</span>, version=<span class="hljs-number">1</span>): | |
| name = decision.variant.variant_str | |
| <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(decision, VariantAccepted): | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{name}</span>: compatible"</span>) | |
| <span class="hljs-keyword">else</span>: | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{name}</span>: rejected (<span class="hljs-subst">{decision.reason}</span>)"</span>) | |
| `,lang:"python",wrap:!1}),c(a,l)},$$slots:{default:!0}}),t(g);var W=e(g,2);n(W,{title:"get_loaded_kernels",local:"kernels.get_loaded_kernels",headingTag:"h3"});var u=e(W,2),F=r(u);o(F,{name:"kernels.get_loaded_kernels",anchor:"kernels.get_loaded_kernels",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/importer.py#L45",parameters:[],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>One <a | |
| href="/docs/kernels/pr_779/en/api/kernels#kernels.LoadedKernel" | |
| >LoadedKernel</a> per distinct kernel variant path | |
| loaded in this process.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>list[LoadedKernel]</code></p> | |
| `});var K=e(F,6);y(K,{anchor:"kernels.get_loaded_kernels.example",children:(a,d)=>{var l=w(),i=e(p(l),2);T(i,{code:"ZnJvbSUyMGtlcm5lbHMlMjBpbXBvcnQlMjBnZXRfa2VybmVsJTJDJTIwZ2V0X2xvYWRlZF9rZXJuZWxzJTBBJTBBZ2V0X2tlcm5lbCglMjJrZXJuZWxzLWNvbW11bml0eSUyRmFjdGl2YXRpb24lMjIlMkMlMjB2ZXJzaW9uJTNEMSklMEFmb3IlMjBsb2FkZWQlMjBpbiUyMGdldF9sb2FkZWRfa2VybmVscygpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQobG9hZGVkLm1ldGFkYXRhLm5hbWUlMkMlMjBsb2FkZWQucmVwb19pbmZvKQ==",highlighted:`<span class="hljs-keyword">from</span> kernels <span class="hljs-keyword">import</span> get_kernel, get_loaded_kernels | |
| get_kernel(<span class="hljs-string">"kernels-community/activation"</span>, version=<span class="hljs-number">1</span>) | |
| <span class="hljs-keyword">for</span> loaded <span class="hljs-keyword">in</span> get_loaded_kernels(): | |
| <span class="hljs-built_in">print</span>(loaded.metadata.name, loaded.repo_info)`,lang:"python",wrap:!1}),c(a,l)},$$slots:{default:!0}}),t(u);var G=e(u,2);n(G,{title:"Loading locked kernels",local:"loading-locked-kernels",headingTag:"h2"});var L=e(G,2);n(L,{title:"load_kernel",local:"kernels.load_kernel",headingTag:"h3"});var _=e(L,2),q=r(_);o(q,{name:"kernels.load_kernel",anchor:"kernels.load_kernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/load.py#L208",parameters:[{name:"repo_id",val:": str"},{name:"lockfile",val:": pathlib.Path | None"},{name:"backend",val:": str | None = None"}],parametersDescription:[{anchor:"kernels.load_kernel.repo_id",description:`<strong>repo_id</strong> (<code>str</code>) — | |
| The Hub repository containing the kernel.`,name:"repo_id"},{anchor:"kernels.load_kernel.lockfile",description:`<strong>lockfile</strong> (<code>Path</code>, <em>optional</em>) — | |
| Path to the lockfile. If not provided, the lockfile will be loaded from the caller’s package metadata.`,name:"lockfile"},{anchor:"kernels.load_kernel.backend",description:`<strong>backend</strong> (<code>str</code>, <em>optional</em>) — | |
| The backend to load the kernel for. Can only be <code>cpu</code> or the backend that Torch is compiled for. | |
| The backend will be detected automatically if not provided.`,name:"backend"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The imported kernel module.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>ModuleType</code></p> | |
| `}),s(4),t(_);var V=e(_,2);n(V,{title:"get_locked_kernel",local:"kernels.get_locked_kernel",headingTag:"h3"});var b=e(V,2),P=r(b);o(P,{name:"kernels.get_locked_kernel",anchor:"kernels.get_locked_kernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/load.py#L253",parameters:[{name:"repo_id",val:": str"}],parametersDescription:[{anchor:"kernels.get_locked_kernel.repo_id",description:`<strong>repo_id</strong> (<code>str</code>) — | |
| The Hub repository containing the kernel.`,name:"repo_id"},{anchor:"kernels.get_locked_kernel.local_files_only",description:`<strong>local_files_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to only use local files and not download from the Hub.`,name:"local_files_only"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The imported kernel module.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>ModuleType</code></p> | |
| `}),s(2),t(b);var E=e(b,2);n(E,{title:"Classes",local:"classes",headingTag:"h2"});var X=e(E,2);n(X,{title:"LoadedKernel",local:"kernels.LoadedKernel",headingTag:"h3"});var v=e(X,2),$=r(v);o($,{name:"class kernels.LoadedKernel",anchor:"kernels.LoadedKernel",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/importer.py#L14",parameters:[{name:"metadata",val:": Metadata"},{name:"module",val:": module"},{name:"repo_info",val:": kernels.hf_hub.RepoInfo | None"}]}),s(8),t(v);var H=e(v,2);n(H,{title:"RepoInfo",local:"kernels.RepoInfo",headingTag:"h3"});var f=e(H,2),O=r(f);o(O,{name:"class kernels.RepoInfo",anchor:"kernels.RepoInfo",source:"https://github.com/huggingface/kernels/blob/vr_779/kernels/src/kernels/hf_hub.py#L81",parameters:[{name:"repo_id",val:": str"},{name:"revision",val:": str"}]}),s(6),t(f);var ee=e(f,2);te(ee,{source:"https://github.com/huggingface/kernels/blob/main/docs/source/api/kernels.md"}),s(2),c(D,x),de()}export{ge as component}; | |
Xet Storage Details
- Size:
- 20.8 kB
- Xet hash:
- 35cd4306a9bc7a48c5ae3262f6bca501f201097994af93248bdc6941e86051b7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.