Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"IDE setup with direnv and the kernel devshell","local":"ide-setup-with-direnv-and-the-kernel-devshell","sections":[{"title":"Introduction","local":"introduction","sections":[],"depth":2},{"title":"Installing direnv and nix-direnv","local":"installing-direnv-and-nix-direnv","sections":[],"depth":2},{"title":"Activating the devshell with direnv","local":"activating-the-devshell-with-direnv","sections":[],"depth":2},{"title":"Generating IDE-facing project files","local":"generating-ide-facing-project-files","sections":[],"depth":2},{"title":"Configuring VS Code","local":"configuring-vs-code","sections":[],"depth":2},{"title":"Remote development","local":"remote-development","sections":[],"depth":2},{"title":"Switching toolchains","local":"switching-toolchains","sections":[],"depth":2},{"title":"noarch kernels","local":"noarch-kernels","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/kernels/main/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/entry/start.0d3b5630.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/scheduler.f3b1e791.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/singletons.1964a5ab.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/paths.7a80a4f8.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/entry/app.d4dbd0eb.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/preload-helper.0cea260c.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/index.023a9934.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/nodes/0.f3b2db53.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/nodes/10.d3008cf3.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/CopyLLMTxtMenu.ee636735.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.9b009efe.js"> | |
| <link rel="modulepreload" href="/docs/kernels/main/en/_app/immutable/chunks/CodeBlock.b439774d.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"IDE setup with direnv and the kernel devshell","local":"ide-setup-with-direnv-and-the-kernel-devshell","sections":[{"title":"Introduction","local":"introduction","sections":[],"depth":2},{"title":"Installing direnv and nix-direnv","local":"installing-direnv-and-nix-direnv","sections":[],"depth":2},{"title":"Activating the devshell with direnv","local":"activating-the-devshell-with-direnv","sections":[],"depth":2},{"title":"Generating IDE-facing project files","local":"generating-ide-facing-project-files","sections":[],"depth":2},{"title":"Configuring VS Code","local":"configuring-vs-code","sections":[],"depth":2},{"title":"Remote development","local":"remote-development","sections":[],"depth":2},{"title":"Switching toolchains","local":"switching-toolchains","sections":[],"depth":2},{"title":"noarch kernels","local":"noarch-kernels","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="ide-setup-with-direnv-and-the-kernel-devshell" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#ide-setup-with-direnv-and-the-kernel-devshell"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>IDE setup with direnv and the kernel devshell</span></h1> <h2 class="relative group"><a id="introduction" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#introduction"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Introduction</span></h2> <p data-svelte-h="svelte-196higt">Language servers do not interpret <code>build.toml</code>, so IDE completion for | |
| CUDA, ROCm, framework headers, and the kernel’s Python wrapper does not | |
| work out of the box. This guide shows how to configure VS Code so that | |
| completion resolves against the same toolchain <code>kernel-builder</code> | |
| uses.</p> <p data-svelte-h="svelte-17k1ly1">The setup has three pieces:</p> <ul data-svelte-h="svelte-1p7eu9p"><li><code>kernel-builder create-pyproject</code> to emit CMake and setuptools files | |
| the IDE can read (see <a href="./local-dev">Local Development</a>).</li> <li>The kernel-builder devshell, which provides the toolchain (CUDA, ROCm, | |
| Torch headers, etc.) from the Nix store.</li> <li><code>direnv</code> to activate the devshell on <code>cd</code>, so VS Code inherits the | |
| environment through the shell.</li></ul> <p data-svelte-h="svelte-1svz3ub">Pinning the toolchain through Nix keeps IDE completion aligned with | |
| the build. It also makes switching between CUDA, ROCm, or XPU a | |
| one-line change in <code>.envrc</code>.</p> <h2 class="relative group"><a id="installing-direnv-and-nix-direnv" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#installing-direnv-and-nix-direnv"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Installing direnv and nix-direnv</span></h2> <p data-svelte-h="svelte-ib4kv1">On non-NixOS systems, install both via <code>nix profile</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ nix profile install nixpkgs<span class="hljs-comment">#nix-direnv</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1jkh9fw">Add the direnv hook to your shell rc (<code>~/.bashrc</code> or | |
| <code>~/.zshrc</code>, for example):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START --><span class="hljs-built_in">eval</span> <span class="hljs-string">"<span class="hljs-subst">$(direnv hook bash)</span>"</span> <span class="hljs-comment"># or: direnv hook zsh</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1tdxnb5">Source the rc file (or open a new shell) so the hook is | |
| active in the current session:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">source</span> ~/.bashrc <span class="hljs-comment"># or: source ~/.zshrc</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1ly2ruq">Wire <code>nix-direnv</code> into direnv:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">mkdir</span> -p ~/.config/direnv | |
| $ <span class="hljs-built_in">echo</span> <span class="hljs-string">'source $HOME/.nix-profile/share/nix-direnv/direnvrc'</span> \ | |
| >> ~/.config/direnv/direnvrc<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1lchhtg">On <a href="https://github.com/nix-community/nix-direnv#via-system-configuration-on-nixos" rel="nofollow">NixOS</a> | |
| or with <a href="https://github.com/nix-community/nix-direnv#via-home-manager" rel="nofollow">home-manager</a>, | |
| enable <code>programs.direnv</code> with | |
| <code>nix-direnv</code> instead. See | |
| <a href="https://github.com/huggingface/kernels/tree/main/terraform/nixos-configuration.nix" rel="nofollow"><code>terraform/nixos-configuration.nix</code></a> | |
| for a working example.</p> <h2 class="relative group"><a id="activating-the-devshell-with-direnv" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#activating-the-devshell-with-direnv"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Activating the devshell with direnv</span></h2> <p data-svelte-h="svelte-1gyke9p">From the kernel root directory (the one containing <code>flake.nix</code> and | |
| <code>build.toml</code>), tell direnv to use the flake’s default devshell:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'use flake'</span> > .envrc | |
| $ direnv allow<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-17sqqi7"><code>direnv</code> now activates the default devshell whenever you <code>cd</code> into the | |
| project. The devshell’s <code>shellHook</code> creates and activates a <code>.venv</code> on | |
| first entry. Confirm it picked up the toolchain and venv:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">which</span> nvcc | |
| /nix/store/.../bin/nvcc | |
| $ <span class="hljs-built_in">ls</span> -ld .venv | |
| drwxr-xr-x ... .venv | |
| $ <span class="hljs-built_in">which</span> python | |
| /path/to/kernel/.venv/bin/python<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-10g97bm">If <code>.venv</code> is missing, re-run <code>direnv reload</code> and check the output for | |
| the <code>Creating new venv environment in path: './.venv'</code> line from the | |
| <code>shellHook</code>.</p> <p data-svelte-h="svelte-1ouvpvu">To pin a non-default build variant, name it explicitly:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">echo</span> <span class="hljs-string">'use flake .#devShells.torch211-cxx11-rocm71-x86_64-linux'</span> > .envrc | |
| $ direnv allow<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1aipx8l">See <a href="./build-variants">Build Variants</a> for the variant list.</p> <h2 class="relative group"><a id="generating-ide-facing-project-files" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#generating-ide-facing-project-files"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Generating IDE-facing project files</span></h2> <p data-svelte-h="svelte-kwas4n">direnv puts the toolchain on <code>PATH</code>, but the C++ language server still | |
| needs a CMake-derived <code>compile_commands.json</code> to resolve per-file | |
| include paths. Generate the CMake/setuptools project and the file:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ kernel-builder create-pyproject -f | |
| $ cmake -B build-ext -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
| $ <span class="hljs-built_in">ln</span> -sf build-ext/compile_commands.json compile_commands.json<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1lokjyh"><code>-DCMAKE_EXPORT_COMPILE_COMMANDS=ON</code> is required: the generated CMake | |
| does not set it. The symlink lets the language server find the file | |
| at the project root.</p> <p data-svelte-h="svelte-8gbuqo">As noted in <a href="./local-dev">Local Development</a>, do not commit the | |
| generated files.</p> <h2 class="relative group"><a id="configuring-vs-code" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#configuring-vs-code"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Configuring VS Code</span></h2> <p data-svelte-h="svelte-196g2nn">Install the <a href="https://github.com/direnv/direnv-vscode" rel="nofollow"><code>mkhl.direnv</code></a> | |
| extension. It activates the project’s <code>.envrc</code> when VS Code opens | |
| the workspace, so language servers and the integrated terminal see | |
| the devshell environment without launching <code>code</code> from a shell.</p> <p data-svelte-h="svelte-11i577r">Alternatively, skip the extension and open the project from a | |
| direnv-activated shell — VS Code inherits the environment that way | |
| too:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">cd</span> path/to/kernel | |
| $ code .<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fkjcvv">Install one of the following first-party extensions for C++/CUDA | |
| completion:</p> <ul data-svelte-h="svelte-1f22tzp"><li><code>llvm-vs-code-extensions.vscode-clangd</code> (recommended for CUDA).</li> <li><code>ms-vscode.cpptools</code> (Microsoft C/C++).</li></ul> <p data-svelte-h="svelte-1m8du9g">Add <code>.vscode/settings.json</code> (do not commit):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-jsonc "><!-- HTML_TAG_START -->{ | |
| <span class="hljs-string">"python.defaultInterpreterPath"</span>: <span class="hljs-string">"<span class="hljs-subst">${workspaceFolder}</span>/.venv/bin/python"</span>, | |
| <span class="hljs-comment">// clangd</span> | |
| <span class="hljs-string">"clangd.arguments"</span>: [<span class="hljs-string">"--compile-commands-dir=<span class="hljs-subst">${workspaceFolder}</span>"</span>], | |
| <span class="hljs-comment">// Microsoft C/C++ extension</span> | |
| <span class="hljs-string">"C_Cpp.default.compileCommands"</span>: <span class="hljs-string">"<span class="hljs-subst">${workspaceFolder}</span>/compile_commands.json"</span> | |
| }<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-mje439">Depending on the extension being used, the configuration above behaves | |
| differently:</p> <ul data-svelte-h="svelte-1vqhbhy"><li>With <code>clangd</code>, the <code>clangd.arguments</code> line is optional. clangd already | |
| looks in the parent directories of each source file for | |
| <code>compile_commands.json</code> and will find the workspace-root symlink on its | |
| own (<a href="https://clangd.llvm.org/installation#project-setup" rel="nofollow">clangd docs</a>). | |
| Setting it explicitly does no harm.</li> <li>With the Microsoft C/C++ extension, the <code>C_Cpp.default.compileCommands</code> | |
| line is required. The extension does not pick up | |
| <code>compile_commands.json</code> from the workspace root on its own, unless | |
| another extension (such as CMake Tools) tells it where to look.</li></ul> <p data-svelte-h="svelte-ecp4ez">To verify, open <code>torch-ext/torch_binding.cpp</code> and hover an | |
| <code>#include <torch/torch.h></code> directive. The resolved path should point | |
| into <code>/nix/store/...</code>, not a system path.</p> <h2 class="relative group"><a id="remote-development" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#remote-development"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Remote development</span></h2> <p data-svelte-h="svelte-1bykdqj">Use the VS Code Remote-SSH extension and put the direnv hook in the | |
| remote shell’s rc. The remote integrated terminal activates the | |
| devshell on <code>cd</code>, and VS Code’s language servers — which run on the | |
| remote — inherit that environment. The | |
| <a href="https://github.com/huggingface/kernels/tree/main/terraform" rel="nofollow"><code>terraform/</code></a> | |
| setup is already configured this way.</p> <h2 class="relative group"><a id="switching-toolchains" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#switching-toolchains"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Switching toolchains</span></h2> <p data-svelte-h="svelte-1b6ml80">Change the <code>use flake</code> line in <code>.envrc</code> to point at a different | |
| variant. For example:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START --><span class="hljs-comment"># CUDA 13.0</span> | |
| use flake .<span class="hljs-comment">#devShells.torch211-cxx11-cu130-x86_64-linux</span> | |
| <span class="hljs-comment"># ROCm 7.1</span> | |
| use flake .<span class="hljs-comment">#devShells.torch211-cxx11-rocm71-x86_64-linux</span> | |
| <span class="hljs-comment"># XPU</span> | |
| use flake .<span class="hljs-comment">#devShells.torch211-cxx11-xpu20253-x86_64-linux</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-9hng5v">Remove <code>.venv/</code> first if it was created against a different variant, | |
| then reload direnv to recreate it via the new devshell’s <code>shellHook</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->$ <span class="hljs-built_in">rm</span> -rf .venv | |
| $ direnv reload<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="noarch-kernels" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#noarch-kernels"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>noarch kernels</span></h2> <p data-svelte-h="svelte-kkkz3t">For Python-only (noarch) kernels, skip the CMake step in “Generating | |
| IDE-facing project files” and the C++ portions of the VS Code | |
| configuration. The <code>direnv</code> setup and <code>python.defaultInterpreterPath</code> | |
| are all that is needed.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/kernels/blob/main/docs/source/builder/ide-setup.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_dhbh13 = { | |
| assets: "/docs/kernels/main/en", | |
| base: "/docs/kernels/main/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/kernels/main/en/_app/immutable/entry/start.0d3b5630.js"), | |
| import("/docs/kernels/main/en/_app/immutable/entry/app.d4dbd0eb.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 10], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 41.7 kB
- Xet hash:
- 602e46e23c5d5aae805991c1b3daa442998506ddbb7873eae8aeedde2121d369
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.