Buckets:
| import"../chunks/DsnmJJEf.js";import{i as K,h as $,C as ee,H as s,a,E as se,s as ae}from"../chunks/CKEMnrQO.js";import{p as le,o as ne,s as e,f as te,a as z,b as oe,c as H,d as F,n,r as Y}from"../chunks/Bb-LL0eD.js";const ie='{"title":"Kernel requirements","local":"kernel-requirements","sections":[{"title":"Repository type","local":"repository-type","sections":[],"depth":2},{"title":"Trusted publishers","local":"trusted-publishers","sections":[],"depth":2},{"title":"Directory layout","local":"directory-layout","sections":[],"depth":2},{"title":"Build variants","local":"build-variants","sections":[],"depth":2},{"title":"Kernel metadata","local":"kernel-metadata","sections":[],"depth":2},{"title":"Backend","local":"backend","sections":[{"title":"Python dependencies","local":"python-dependencies","sections":[{"title":"General dependencies","local":"general-dependencies","sections":[],"depth":4},{"title":"Backend-specific dependencies","local":"backend-specific-dependencies","sections":[],"depth":4},{"title":"Combined example","local":"combined-example","sections":[],"depth":4},{"title":"Allowed dependencies","local":"allowed-dependencies","sections":[],"depth":4}],"depth":3}],"depth":2},{"title":"Versioning","local":"versioning","sections":[],"depth":2},{"title":"Native Python module","local":"native-python-module","sections":[],"depth":2},{"title":"Compatibility with torch.compile","local":"compatibility-with-torchcompile","sections":[{"title":"Linux","local":"linux","sections":[],"depth":3},{"title":"macOS","local":"macos","sections":[],"depth":3},{"title":"ABI checker","local":"abi-checker","sections":[],"depth":3}],"depth":2},{"title":"Torch extension","local":"torch-extension","sections":[],"depth":2},{"title":"Layers","local":"layers","sections":[{"title":"Writing layers","local":"writing-layers","sections":[],"depth":3},{"title":"Exporting layers","local":"exporting-layers","sections":[],"depth":3}],"depth":2},{"title":"Python requirements","local":"python-requirements","sections":[],"depth":2}],"depth":1}';var ce=F('<meta name="hf:doc:metadata"/>'),pe=F(`<p></p> <!> <!> <p>Kernels on the Hub must fulfill the requirements outlined on this page. By | |
| ensuring kernels are compliant, they can be used on a wide range of Linux | |
| systems and Torch builds.</p> <p><a href="https://github.com/huggingface/kernels/discussions/categories/kernel-builder" rel="nofollow">Join us on GitHub Discussions</a> for questions and discussions about building kernels!</p> <!> <p>Compliant kernels are published as <code>kernel</code>-type repositories on the Hub | |
| (the first-class kernel repository type). New uploads via <code>kernel-builder</code> default to this type; see the <a href="migration">migration guide</a> if you | |
| maintain an older <code>model</code>-type kernel repository.</p> <!> <p><code>kernels</code> only loads kernels from a curated set of trusted publishers by | |
| default. Loading from any other publisher raises an error unless the caller | |
| opts in with <code>trust_remote_code=True</code>:</p> <!> <p>The Hub also exposes a <code>trustedKernelPublisher</code> flag on the kernel API and | |
| displays a corresponding badge in the UI.</p> <!> <p>A kernel repository on the Hub must contain a <code>build</code> directory. This | |
| directory contains build variants of a kernel in the form of directories | |
| following the template <code><framework><version>-cxx<abiver>-<cu><cudaver>-<arch>-<os></code>. | |
| For example <code>build/torch26-cxx98-cu118-x86_64-linux</code>.</p> <p>The kernel is in the build variant directory and must contain a <code>__init__.py</code> file. For compatibility with older versions of the <code>kernels</code> package, each variant directory must also contain a single | |
| directory with the same name as the repository (replacing <code>-</code> by <code>_</code>). | |
| For instance, kernels in the <code>kernels-community/activation</code> repository | |
| have a directory like <code>build/<variant>/activation</code>. This directory | |
| must contain an <code>__init__.py</code> file that exports the same symbols as <code>__init__.py</code> in the build variant directory <code>build/<variant></code>. <a href="https://huggingface.co/kernels-test/flattened-build/blob/main/build/torch-universal/flattened_build/__init__.py" rel="nofollow">This example</a> shows how this can be done. This compatibility directory is | |
| automatically created by <code>kernel-builder</code>.</p> <!> <p>A kernel can be compliant for a specific compute framework (e.g. CUDA) or | |
| architecture (e.g. x86_64). For compliance with a compute framework and | |
| architecture combination, all the variants from the <a href="builder/build-variants">build variant list</a> must be available for that combination.</p> <!> <p>The build variant directory must contain a <code>metadata.json</code> file with kernel | |
| metadata. Currently the following top-level keys are supported:</p> <ul><li><p><code>id</code> (<code>str</code>, required): a unique identifier for the kernel. This | |
| identifier must also be a valid Python module name. If the kernel | |
| registers Torch ops, they must be registered as <code>torch.ops.<id></code></p></li> <li><p><code>name</code> (<code>str</code>, required): then name of the kernel. Replacing dashes | |
| by underscores should result in the module name of the kernel.</p></li> <li><p><code>version</code> (<code>int</code>, required): the kernel version number.</p></li> <li><p><code>license</code> (<code>str</code>, required): the kernel license in. Refer to the | |
| list of <a href="https://huggingface.co/docs/hub/repositories-licenses" rel="nofollow">supported license identifiers</a>.</p></li> <li><p><code>upstream</code> (<code>str</code>, optional): Git-compatible URL (passable to <code>git clone</code>) | |
| of the original upstream repository where the kernel source code comes from.</p></li> <li><p><code>source</code> (<code>str</code>, optional): Git-compatible URL (passable to <code>git clone</code>) | |
| of the kernel-builder formatted source repository (must contain <code>build.toml</code> and <code>flake.nix</code>).</p></li> <li><p><code>backend</code> (<code>dict</code>, required): information about the compute backend that | |
| this build variant supports.</p></li> <li><p><code>digest</code> (<code>Digest</code>, required): hash digest of the kernel files.</p></li> <li><p><code>python-depends</code> (<code>list[str]</code>, optional): list of Python dependencies | |
| from a curated set of Python dependencies.</p></li> <li><p><code>provenance</code> (<code>dict</code>, optional): provenance of the build, used to flag | |
| non-reproducible (dirty) builds. It contains two optional sub-objects:</p> <ul><li><code>kernel-builder</code>: the <code>kernel-builder</code> that produced the build, with its <code>version</code> (<code>str</code>), the <code>sha</code> (<code>str</code>) of the <code>kernel-builder</code> source it was | |
| built from (when known), and a <code>dirty</code> (<code>bool</code>) flag that is <code>true</code> when <code>kernel-builder</code> was built from a source tree with uncommitted changes.</li> <li><code>kernel</code>: the kernel source that was built, with its commit <code>sha</code> (<code>str</code>) | |
| and a <code>dirty</code> (<code>bool</code>) flag that is <code>true</code> when the kernel source had | |
| uncommitted changes.</li></ul> <p>When either <code>dirty</code> flag is set, the kernel was built from uncommitted | |
| sources and cannot be reliably reproduced.</p> <blockquote><p><strong>Note:</strong> For Nix builds, dirtiness follows Nixโs flake tree status, which | |
| also counts <strong>untracked</strong> files (including an uncommitted <code>flake.lock</code>). | |
| Commit your <code>flake.lock</code> (and avoid stray untracked files) so that clean | |
| builds are not flagged as dirty. Local <code>create-pyproject</code> runs only | |
| consider changes to tracked files.</p></blockquote> <blockquote><p><strong>Note:</strong> The kernel <code>sha</code>/<code>dirty</code> are captured at the moment <code>create-pyproject</code> runs, so they describe the source tree as it was <em>then</em>. | |
| Running <code>create-pyproject</code> and committing afterwards is bad practice: the | |
| recorded provenance keeps pointing at the pre-commit state (a stale <code>sha</code>, | |
| and <code>dirty: true</code> if the tree was dirty) even though the committed source | |
| differs. Generate the metadata from the final, committed source instead.</p></blockquote></li></ul> <p>Example <code>metadata.json</code>:</p> <!> <p>The <code>metadata.json</code> file is generated automatically by <code>kernel-builder</code>.</p> <!> <p>The <code>backend</code> specifies a dictionary of the following form:</p> <!> <p>The backend <code>type</code> must be one of <code>cann</code>, <code>cpu</code>, <code>cuda</code>, <code>metal</code>, <code>neuron</code>, <code>rocm</code>, <code>tpu</code>, or <code>xpu</code>. For CUDA and ROCm, the supported architectures must | |
| be specified in the <code>archs</code> field.</p> <!> <p>You can specify Python dependencies that your kernel requires. Dependencies can be either general (required for all backends) or backend-specific (required only for certain compute backends like CUDA, ROCm, XPU, Metal, or CPU).</p> <!> <p>For dependencies required regardless of the backend, use the <code>python-depends</code> field:</p> <!> <!> <p>For dependencies that are only needed for specific backends, use the <code>python-depends-backends</code> field:</p> <!> <!> <p>You can specify both general and backend-specific dependencies:</p> <!> <!> <p>The following dependencies are currently allowed:</p> <p><strong>General dependencies:</strong></p> <ul><li><code>einops</code></li> <li><code>helion</code></li></ul> <p><strong>Backend-specific dependencies:</strong></p> <ul><li>CUDA: <code>nvidia-cutlass-dsl</code></li> <li>XPU: <code>onednn</code></li></ul> <p>Dependencies are validated based on the backend being used. When a kernel is loaded, only the dependencies relevant to the active backend are checked.</p> <!> <p>Kernels are versioned using a major version. The kernel revisions of a | |
| version are stored in a branch of the form <code>v<version></code>. Each build | |
| variant will also have the kernel version in <code>metadata.json</code>.</p> <p>The version <strong>must</strong> be bumped in the following cases:</p> <ul><li>The kernel API is changed in an incompatible way.</li> <li>The API is extended in a compatible way, but not all build variants | |
| receive the extension (e.g. because they are for older Torch versions | |
| that are not supported by <code>kernel-builder</code> anymore).</li></ul> <p>In both cases, build variants that are not updated must be removed from | |
| the new versionโs branch.</p> <blockquote class="important"><p>The <em>kernel API</em> covered by these versioning guarantees is only the | |
| public API: the symbols listed in the <code>__all__</code> of the kernelโs | |
| top-level <code>__init__.py</code>. Anything not in <code>__all__</code> (e.g. internal | |
| helpers or names prefixed with <code>_</code>) is considered private and may | |
| change or be removed at any time without a version bump. Export every | |
| symbol you intend consumers to rely on in <code>__all__</code>.</p></blockquote> <blockquote class="note"><p>By convention, we reserve version <code>0</code> for kernels that are still in | |
| alpha or beta stage and are not recommended for production use (e.g. | |
| because the API is still changing regularly or there are still too | |
| many issues).</p></blockquote> <!> <p>Kernels will typically contain a native Python module with precompiled | |
| compute kernels and bindings. This module must fulfill the requirements | |
| outlined in this section. For all operating systems, a kernel must not | |
| have dynamic library dependencies outside:</p> <ul><li>Torch;</li> <li>CUDA/ROCm libraries installed as dependencies of Torch.</li></ul> <!> <p>The Kernel Hub also encourages to write the kernels in a <code>torch.compile</code> compliant way. This helps to ensure that the kernels are compatible with <code>torch.compile</code> without introducing any graph breaks and triggering | |
| recompilation which can limit the benefits of compilation.</p> <p><a href="https://github.com/huggingface/kernels/blob/f83b4da6b7f6b171b47bb9bf96271ae2273bc9d3/builder/examples/relu-backprop-compile/tests/test_relu.py#L162" rel="nofollow">Here</a> is a simple test example which checks for graph breaks and | |
| recompilation triggers during <code>torch.compile</code>.</p> <!> <ul><li>Use <a href="https://docs.python.org/3/c-api/stable.html#stable-application-binary-interface" rel="nofollow">ABI3/Limited API</a> for compatibility with Python 3.9 and later.</li> <li>Compatible with <a href="https://github.com/pypa/manylinux?tab=readme-ov-file#manylinux_2_28-almalinux-8-based" rel="nofollow"><code>manylinux_2_28</code></a>. | |
| This means that the extension <strong>must not</strong> use symbols versions higher than: <ul><li>GLIBC 2.28</li> <li>GLIBCXX 3.4.24</li> <li>CXXABI 1.3.11</li> <li>GCC 7.0.0</li></ul></li></ul> <p>These requirements can be checked with the ABI checker (see below).</p> <!> <ul><li>Use <a href="https://docs.python.org/3/c-api/stable.html#stable-application-binary-interface" rel="nofollow">ABI3/Limited API</a> for compatibility with Python 3.9 and later.</li> <li>macOS deployment target 15.0.</li> <li>Metal 3.0 (<code>-std=metal3.0</code>).</li></ul> <p>The ABI3 requirement can be checked with the ABI checker (see below).</p> <!> <p>The manylinux_2_28 and Python ABI 3.9 version requirements can be checked with <code>kernel-builder check-abi</code>:</p> <!> <!> <p>Torch native extension functions must be <a href="https://pytorch.org/tutorials/advanced/cpp_custom_ops.html#cpp-custom-ops-tutorial" rel="nofollow">registered</a> in <code>torch.ops.<namespace></code>. Since we allow loading of multiple versions of | |
| a module in the same Python process, <code>namespace</code> must be unique for each | |
| version of a kernel. Failing to do so will create clashes when different | |
| versions of the same kernel are loaded. Two suggested ways of doing this | |
| are:</p> <ul><li>Appending a truncated SHA-1 hash of the git commit that the kernel was | |
| built from to the name of the extension.</li> <li>Appending random material to the name of the extension.</li></ul> <p><strong>Note:</strong> we recommend against appending a version number or git tag. | |
| Version numbers are typically not bumped on each commit, so users | |
| might use two different commits that happen to have the same version | |
| number. Git tags are not stable, so they do not provide a good way | |
| of guaranteeing uniqueness of the namespace.</p> <!> <p>A kernel can provide layers in addition to kernel functions. A layer from | |
| the Hub can replace the <code>forward</code> method of an existing layer for a certain | |
| device type. This makes it possible to provide more performant kernels for | |
| existing layers. See the <a href="layers">layers documentation</a> for more information | |
| on how to use layers.</p> <!> <p>To make the extension of layers safe, the layers must fulfill the following | |
| requirements:</p> <ul><li>The layers are subclasses of <code>torch.nn.Module</code>.</li> <li>The layers are pure, meaning that they do not have their own state. This | |
| means that: <ul><li>The layer must not define its own constructor.</li> <li>The layer must not use class variables.</li></ul></li> <li>No other methods must be defined than <code>forward</code>.</li> <li>The <code>forward</code> method has a signature that is compatible with the <code>forward</code> method that it is extending.</li></ul> <p>There are two exceptions to the <em>no class variables rule</em>:</p> <ol><li>The <code>has_backward</code> variable can be used to indicate whether the layer has | |
| a backward pass implemented (<code>True</code> when absent).</li> <li>The <code>can_torch_compile</code> variable can be used to indicate whether the layer | |
| supports <code>torch.compile</code> (<code>False</code> when absent).</li></ol> <p>This is an example of a pure layer:</p> <!> <p>For some layers, the <code>forward</code> method has to use state from the adopting class. | |
| In these cases, we recommend to use type annotations to indicate what member | |
| variables are expected. For instance:</p> <!> <p>This layer expects the adopting layer to have <code>weight</code> and <code>variance_epsilon</code> member variables and uses them in the <code>forward</code> method.</p> <!> <p>To accommodate portable loading, <code>layers</code> must be defined in the main <code>__init__.py</code> file. For example:</p> <!> <blockquote class="important"><p>Only symbols listed in <code>__all__</code> are treated as the kernelโs public | |
| API. This is the surface that consumers can rely on and that the <a href="#versioning">versioning guarantees</a> apply to, so be sure to export | |
| every function, class, and <code>layers</code> module you want to expose.</p></blockquote> <!> <ul><li><p>Python code must be compatible with Python 3.9 and later.</p></li> <li><p>All Python code imports from the kernel itself must be relative. So, | |
| for instance if in the example kernel <code>example</code>, <code>module_b</code> needs a function from <code>module_a</code>, import as:</p> <!> <p><strong>Never use:</strong></p> <!> <p>The latter would import from the module <code>example</code> that is in Pythonโs | |
| global module dict. However, since we allow loading multiple versions | |
| of a module, we uniquely name the module.</p></li> <li><p>Only modules from the Python standard library, Torch, or the kernel itself | |
| can be imported.</p></li></ul> <!> <p></p>`,1);function ue(L,D){le(D,!1),ne(()=>{new URLSearchParams(window.location.search).get("fw")}),K();var t=pe();$("1vjlsir",S=>{var X=ce();ae(X,"content",ie),z(S,X)});var o=e(te(t),2);ee(o,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var i=e(o,2);s(i,{title:"Kernel requirements",local:"kernel-requirements",headingTag:"h1"});var c=e(i,6);s(c,{title:"Repository type",local:"repository-type",headingTag:"h2"});var p=e(c,4);s(p,{title:"Trusted publishers",local:"trusted-publishers",headingTag:"h2"});var r=e(p,4);a(r,{code:"JTIzJTIwVHJ1c3RlZCUyMHB1Ymxpc2hlciUzQSUyMHdvcmtzJTIwd2l0aG91dCUyMG9wdC1pbi4lMEFnZXRfa2VybmVsKCUyMmtlcm5lbHMtY29tbXVuaXR5JTJGYWN0aXZhdGlvbiUyMiUyQyUyMHZlcnNpb24lM0QxKSUwQSUwQSUyMyUyMFVudHJ1c3RlZCUyMHB1Ymxpc2hlciUzQSUyMG11c3QlMjBvcHQlMjBpbiUyMGV4cGxpY2l0bHkuJTBBZ2V0X2tlcm5lbCglMjJzb21lLW90aGVyLW9yZyUyRm15LWtlcm5lbCUyMiUyQyUyMHZlcnNpb24lM0QxJTJDJTIwdHJ1c3RfcmVtb3RlX2NvZGUlM0RUcnVlKQ==",highlighted:`<span class="hljs-comment"># Trusted publisher: works without opt-in.</span> | |
| get_kernel(<span class="hljs-string">"kernels-community/activation"</span>, version=<span class="hljs-number">1</span>) | |
| <span class="hljs-comment"># Untrusted publisher: must opt in explicitly.</span> | |
| get_kernel(<span class="hljs-string">"some-other-org/my-kernel"</span>, version=<span class="hljs-number">1</span>, trust_remote_code=<span class="hljs-literal">True</span>)`,lang:"python",wrap:!1});var d=e(r,4);s(d,{title:"Directory layout",local:"directory-layout",headingTag:"h2"});var h=e(d,6);s(h,{title:"Build variants",local:"build-variants",headingTag:"h2"});var u=e(h,4);s(u,{title:"Kernel metadata",local:"kernel-metadata",headingTag:"h2"});var y=e(u,8);a(y,{code:"JTdCJTBBJTIwJTIwJTIybmFtZSUyMiUzQSUyMCUyMm15a2VybmVsJTIyJTJDJTBBJTIwJTIwJTIyaWQlMjIlM0ElMjAlMjJfbXlrZXJuZWxfY3VkYV83YTRlNWE3JTIyJTJDJTBBJTIwJTIwJTIydmVyc2lvbiUyMiUzQSUyMDElMkMlMEElMjAlMjAlMjJsaWNlbnNlJTIyJTNBJTIwJTIyQXBhY2hlLTIuMCUyMiUyQyUwQSUyMCUyMCUyMnB5dGhvbi1kZXBlbmRzJTIyJTNBJTI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Y4bjBTbVdHWlY4TkZtbDVEUGhNaktmdjk4R1klM0QlMjIlMEElMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlN0QlMEElN0Q=",highlighted:`<span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"mykernel"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"_mykernel_cuda_7a4e5a7"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"license"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Apache-2.0"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"python-depends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"einops"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"backend"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"cuda"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"archs"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"7.0"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"7.2"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"7.5"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.0"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.6"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.7"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.9"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"9.0+PTX"</span><span class="hljs-punctuation">]</span> | |
| <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"digest"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"algorithm"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"sha256"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"files"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"__init__.py"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"xLMbARTcTl8L/m1kJLc/h/QL4Kzt772F872a46pfRGI="</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"_mykernel_cuda_7645816_dirty.abi3.so"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"vtdzzToloH38HZkVs7sFEf69QFDxROuPsBAond3Jic0="</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"_ops.py"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Hrp5aF4o0eHSttw4sQGsbBAXFqvLJ42Y9YJ2KkqvZhg="</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"mykernel/__init__.py"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span>`,lang:"json",wrap:!1});var M=e(y,4);s(M,{title:"Backend",local:"backend",headingTag:"h2"});var m=e(M,4);a(m,{code:"JTdCJTBBJTIwJTIwJTIzJTIwLi4uJTBBJTIwJTIwJTIyYmFja2VuZCUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMnR5cGUlMjIlM0ElMjAlMjJjdWRhJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyYXJjaHMlMjIlM0ElMjAlNUIlMjI3LjAlMjIlMkMlMjAlMjI3LjIlMjIlMkMlMjAlMjI3LjUlMjIlMkMlMjAlMjI4LjAlMjIlMkMlMjAlMjI4LjYlMjIlMkMlMjAlMjI4LjclMjIlMkMlMjAlMjI4LjklMjIlMkMlMjAlMjI5LjAlMkJQVFglMjIlNUQlMEElMjAlMjAlN0QlMEElN0Q=",highlighted:`<span class="hljs-punctuation">{</span> | |
| # ... | |
| <span class="hljs-attr">"backend"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"cuda"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"archs"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"7.0"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"7.2"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"7.5"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.0"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.6"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.7"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"8.9"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"9.0+PTX"</span><span class="hljs-punctuation">]</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span>`,lang:"json",wrap:!1});var j=e(m,4);s(j,{title:"Python dependencies",local:"python-dependencies",headingTag:"h3"});var T=e(j,4);s(T,{title:"General dependencies",local:"general-dependencies",headingTag:"h4"});var J=e(T,4);a(J,{code:"JTdCJTBBJTIwJTIwJTIycHl0aG9uLWRlcGVuZHMlMjIlM0ElMjAlNUIlMjJlaW5vcHMlMjIlNUQlMEElN0Q=",highlighted:`<span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"python-depends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"einops"</span><span class="hljs-punctuation">]</span> | |
| <span class="hljs-punctuation">}</span>`,lang:"json",wrap:!1});var b=e(J,2);s(b,{title:"Backend-specific dependencies",local:"backend-specific-dependencies",headingTag:"h4"});var w=e(b,4);a(w,{code:"JTdCJTBBJTIwJTIwJTIycHl0aG9uLWRlcGVuZHMtYmFja2VuZHMlMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjJjdWRhJTIyJTNBJTIwJTVCJTIybnZpZGlhLWN1dGxhc3MtZHNsJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIyeHB1JTIyJTNBJTIwJTVCJTIyb25lZG5uJTIyJTVEJTBBJTIwJTIwJTdEJTBBJTdE",highlighted:`<span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"python-depends-backends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"cuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"nvidia-cutlass-dsl"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"xpu"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"onednn"</span><span class="hljs-punctuation">]</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span>`,lang:"json",wrap:!1});var g=e(w,2);s(g,{title:"Combined example",local:"combined-example",headingTag:"h4"});var U=e(g,4);a(U,{code:"JTdCJTBBJTIwJTIwJTIycHl0aG9uLWRlcGVuZHMlMjIlM0ElMjAlNUIlMjJlaW5vcHMlMjIlNUQlMkMlMEElMjAlMjAlMjJweXRob24tZGVwZW5kcy1iYWNrZW5kcyUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMmN1ZGElMjIlM0ElMjAlNUIlMjJudmlkaWEtY3V0bGFzcy1kc2wlMjIlNUQlMEElMjAlMjAlN0QlMkMlMEElMjAlMjAlMjJ2ZXJzaW9uJTIyJTNBJTIwMSUwQSU3RA==",highlighted:`<span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"python-depends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"einops"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"python-depends-backends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"cuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"nvidia-cutlass-dsl"</span><span class="hljs-punctuation">]</span> | |
| <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span> | |
| <span class="hljs-punctuation">}</span>`,lang:"json",wrap:!1});var I=e(U,2);s(I,{title:"Allowed dependencies",local:"allowed-dependencies",headingTag:"h4"});var k=e(I,14);s(k,{title:"Versioning",local:"versioning",headingTag:"h2"});var f=e(k,14);s(f,{title:"Native Python module",local:"native-python-module",headingTag:"h2"});var v=e(f,6);s(v,{title:"Compatibility with torch.compile",local:"compatibility-with-torchcompile",headingTag:"h2"});var C=e(v,6);s(C,{title:"Linux",local:"linux",headingTag:"h3"});var _=e(C,6);s(_,{title:"macOS",local:"macos",headingTag:"h3"});var B=e(_,6);s(B,{title:"ABI checker",local:"abi-checker",headingTag:"h3"});var q=e(B,4);a(q,{code:"JTI0JTIwa2VybmVsLWJ1aWxkZXIlMjBjaGVjay1hYmklMjBleGFtcGxlcyUyRmtlcm5lbHMlMkZyZWx1JTBBJUYwJTlGJTkwJThEJTIwQ2hlY2tpbmclMjBmb3IlMjBjb21wYXRpYmlsaXR5JTIwd2l0aCUyMG1hbnlsaW51eF8yXzI4JTIwYW5kJTIwUHl0aG9uJTIwQUJJJTIwdmVyc2lvbiUyMDMuOSUzQSUyMCUyRmhvbWUlMkZkYW5pZWwlMkZnaXQlMkZrZXJuZWxzJTJGZXhhbXBsZXMlMkZrZXJuZWxzJTJGcmVsdSUyRnJlc3VsdCUyRnRvcmNoMjExLWNwdS14ODZfNjQtbGludXglMkZfcmVsdV9jcHVfMzBkYzBhZV9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ZrZXJuZWxzJTJGZXhhbXBsZXMlMkZrZXJuZWxzJTJGcmVsdSUyRnJlc3VsdCUyRnRvcmNoMjExLWN1MTMwLXg4Nl82NC1saW51eCUyRl9yZWx1X2N1ZGFfMzBkYzBhZV9kaXJ0eS5hYmkzLnNvJTBBJUUyJTlDJTg1JTIwTm8lMjBjb21wYXRpYmlsaXR5JTIwaXNzdWVzJTIwZm91bmQlMEElNUIuLi4lNUQ=",highlighted:`$ kernel-builder check-abi examples/kernels/relu | |
| ๐ Checking <span class="hljs-keyword">for</span> compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cpu-x86_64-linux/_relu_cpu_30dc0ae_dirty.abi3.so | |
| โ No compatibility issues found | |
| ๐ Checking <span class="hljs-keyword">for</span> compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cu126-x86_64-linux/_relu_cuda_30dc0ae_dirty.abi3.so | |
| โ No compatibility issues found | |
| ๐ Checking <span class="hljs-keyword">for</span> compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cu128-x86_64-linux/_relu_cuda_30dc0ae_dirty.abi3.so | |
| โ No compatibility issues found | |
| ๐ Checking <span class="hljs-keyword">for</span> compatibility with manylinux_2_28 and Python ABI version 3.9: /home/daniel/git/kernels/examples/kernels/relu/result/torch211-cu130-x86_64-linux/_relu_cuda_30dc0ae_dirty.abi3.so | |
| โ No compatibility issues found | |
| [...]`,lang:"bash",wrap:!1});var A=e(q,2);s(A,{title:"Torch extension",local:"torch-extension",headingTag:"h2"});var G=e(A,8);s(G,{title:"Layers",local:"layers",headingTag:"h2"});var Z=e(G,4);s(Z,{title:"Writing layers",local:"writing-layers",headingTag:"h3"});var x=e(Z,12);a(x,{code:"Y2xhc3MlMjBTaWx1QW5kTXVsKG5uLk1vZHVsZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUaGlzJTIwbGF5ZXIlMjBkb2VzJTIwbm90JTIwaW1wbGVtZW50JTIwYmFja3dhcmQuJTBBJTIwJTIwJTIwJTIwaGFzX2JhY2t3YXJkJTNBJTIwYm9vbCUyMCUzRCUyMEZhbHNlJTBBJTBBJTIwJTIwJTIwJTIwZGVmJTIwZm9yd2FyZChzZWxmJTJDJTIweCUzQSUyMHRvcmNoLlRlbnNvciklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkJTIwJTNEJTIweC5zaGFwZSU1Qi0xJTVEJTIwJTJGJTJGJTIwMiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dF9zaGFwZSUyMCUzRCUyMHguc2hhcGUlNUIlM0EtMSU1RCUyMCUyQiUyMChkJTJDKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dCUyMCUzRCUyMHRvcmNoLmVtcHR5KG91dHB1dF9zaGFwZSUyQyUyMGR0eXBlJTNEeC5kdHlwZSUyQyUyMGRldmljZSUzRHguZGV2aWNlKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9wcy5zaWx1X2FuZF9tdWwob3V0JTJDJTIweCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm4lMjBvdXQ=",highlighted:`<span class="hljs-keyword">class</span> <span class="hljs-title class_">SiluAndMul</span>(nn.Module): | |
| <span class="hljs-comment"># This layer does not implement backward.</span> | |
| has_backward: <span class="hljs-built_in">bool</span> = <span class="hljs-literal">False</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, x: torch.Tensor</span>): | |
| d = x.shape[-<span class="hljs-number">1</span>] // <span class="hljs-number">2</span> | |
| output_shape = x.shape[:-<span class="hljs-number">1</span>] + (d,) | |
| out = torch.empty(output_shape, dtype=x.dtype, device=x.device) | |
| ops.silu_and_mul(out, x) | |
| <span class="hljs-keyword">return</span> out`,lang:"python",wrap:!1});var N=e(x,4);a(N,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> <span class="hljs-title class_">LlamaRMSNorm</span>(nn.Module): | |
| weight: torch.Tensor | |
| variance_epsilon: <span class="hljs-built_in">float</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, hidden_states: torch.Tensor</span>) -> torch.Tensor: | |
| <span class="hljs-keyword">return</span> rms_norm_fn( | |
| hidden_states, | |
| <span class="hljs-variable language_">self</span>.weight, | |
| bias=<span class="hljs-literal">None</span>, | |
| residual=<span class="hljs-literal">None</span>, | |
| eps=<span class="hljs-variable language_">self</span>.variance_epsilon, | |
| dropout_p=<span class="hljs-number">0.0</span>, | |
| prenorm=<span class="hljs-literal">False</span>, | |
| residual_in_fp32=<span class="hljs-literal">False</span>, | |
| )`,lang:"python",wrap:!1});var E=e(N,4);s(E,{title:"Exporting layers",local:"exporting-layers",headingTag:"h3"});var R=e(E,4);a(R,{code:"ZnJvbSUyMC4lMjBpbXBvcnQlMjBsYXllcnMlMEElMEFfX2FsbF9fJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIzJTIwLi4uJTBBJTIwJTIwJTIybGF5ZXJzJTIyJTBBJTIwJTIwJTIzJTIwLi4uJTBBJTVE",highlighted:`<span class="hljs-keyword">from</span> . <span class="hljs-keyword">import</span> layers | |
| __all__ = [ | |
| <span class="hljs-comment"># ...</span> | |
| <span class="hljs-string">"layers"</span> | |
| <span class="hljs-comment"># ...</span> | |
| ]`,lang:"python",wrap:!1});var Q=e(R,4);s(Q,{title:"Python requirements",local:"python-requirements",headingTag:"h2"});var l=e(Q,2),V=e(H(l),2),W=e(H(V),2);a(W,{code:"ZnJvbSUyMC5tb2R1bGVfYSUyMGltcG9ydCUyMGZvbw==",highlighted:'<span class="hljs-keyword">from</span> .module_a <span class="hljs-keyword">import</span> foo',lang:"python",wrap:!1});var P=e(W,4);a(P,{code:"JTIzJTIwRE8lMjBOT1QlMjBETyUyMFRISVMhJTBBJTBBZnJvbSUyMGV4YW1wbGUubW9kdWxlX2ElMjBpbXBvcnQlMjBmb28=",highlighted:`<span class="hljs-comment"># DO NOT DO THIS!</span> | |
| <span class="hljs-keyword">from</span> example.module_a <span class="hljs-keyword">import</span> foo`,lang:"python",wrap:!1}),n(2),Y(V),n(2),Y(l);var O=e(l,2);se(O,{source:"https://github.com/huggingface/kernels/blob/main/docs/source/kernel-requirements.md"}),n(2),z(L,t),oe()}export{ue as component}; | |
Xet Storage Details
- Size:
- 38.1 kB
- Xet hash:
- 4a7932f9dfb426aaa54fcb234b3f32a4cb0bc14811db0d00bae50b6eb8666589
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.