Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Nix Builder design","local":"nix-builder-design","sections":[{"title":"Introduction","local":"introduction","sections":[],"depth":2},{"title":"Kernel build steps","local":"kernel-build-steps","sections":[],"depth":2},{"title":"manylinux_2_28 compatibility","local":"manylinux228-compatibility","sections":[],"depth":2},{"title":"The package set pattern","local":"the-package-set-pattern","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/kernels/pr_607/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/entry/start.783410d4.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/scheduler.f3b1e791.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/singletons.1e1d6fe7.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/paths.dc7f083c.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/entry/app.d93c6142.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/preload-helper.b9f0e7b7.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/index.023a9934.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/nodes/0.1d24170c.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/nodes/8.c02b722e.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/CopyLLMTxtMenu.c780467c.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.fb377ec3.js"> | |
| <link rel="modulepreload" href="/docs/kernels/pr_607/en/_app/immutable/chunks/CodeBlock.fc650646.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Nix Builder design","local":"nix-builder-design","sections":[{"title":"Introduction","local":"introduction","sections":[],"depth":2},{"title":"Kernel build steps","local":"kernel-build-steps","sections":[],"depth":2},{"title":"manylinux_2_28 compatibility","local":"manylinux228-compatibility","sections":[],"depth":2},{"title":"The package set pattern","local":"the-package-set-pattern","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="nix-builder-design" 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="#nix-builder-design"><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>Nix Builder design</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-10m3qhc">kernel-builder uses a Nix-based builder that orchestrates the build. The Nix | |
| builder provides:</p> <ul data-svelte-h="svelte-k9b528"><li>Reproducible evaluation. The same Nix builder version will always produce | |
| the same derivations (build recipes).</li> <li>Largely reproducible builds by using a build sandbox that only has the | |
| dependencies specified in a derivation.</li> <li>Seamless creation of different build environments (e.g. different Torch | |
| and CUDA combinations).</li></ul> <h2 class="relative group"><a id="kernel-build-steps" 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="#kernel-build-steps"><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>Kernel build steps</span></h2> <p data-svelte-h="svelte-wtbtic">A kernel derivation builds a kernel in the following steps:</p> <ol data-svelte-h="svelte-18gvsag"><li>Generate CMake files for the kernel using | |
| <code>kernel-builder create-pyproject</code>.</li> <li>Generate Ninja build files using CMake.</li> <li>Build the kernel using Ninja.</li> <li>Perform various checks on the compiled kernel, such as: | |
| <ul><li>Verify that the kernel only uses ABI3/<code>manylinux_2_28</code> symbols.</li> <li>Verify that the kernel can be loaded by the <code>kernels</code> Python package.</li></ul></li> <li>Strip runpaths (ELF-embedded library directories) from kernel binaries | |
| to make the kernel distribution-independent.</li></ol> <h2 class="relative group"><a id="manylinux228-compatibility" 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="#manylinux228-compatibility"><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>manylinux_2_28 compatibility</span></h2> <p data-svelte-h="svelte-dg7mnn">To achieve <code>manylinux_2_28</code> compatibility, kernels are built using a | |
| toolchain similar to the <code>manylinux_2_28</code> Docker images. This toolchain | |
| is based on the gcc toolsets from AlmaLinux 8. <code>manylinux_2_28</code> <a href="https://github.com/pypa/manylinux#manylinux_2_28-almalinux-8-based" rel="nofollow">uses | |
| AlmaLinux 8 as its base</a>, | |
| so we have to compile against the same glibc/libstdc++ versions to | |
| ensure compatibility.</p> <p data-svelte-h="svelte-1wrujd7">We repackage the AlmaLinux 8 toolsets and libstdc++ as Nix derivations (see | |
| the <code>nix-builder/packages/manylinux_2_28</code> source directory). Then we merge | |
| various toolset packages to an unwrapped gcc that resembles unwrapped gcc in | |
| nixpkgs. Finally, we wrap binutils and gcc to combine them into a stdenv.</p> <p data-svelte-h="svelte-mo1kwe">The stdenv does not reuse glibc from AlmaLinux, since its dynamic loader has | |
| hardcoded FHS paths (<code>/lib64</code> etc.) that are not valid in Nix. Using this | |
| dynamic loader results in linking errors, since the paths in the dynamic | |
| loader are used as a last resort (to link glibc libraries). So, instead we | |
| build our own glibc 2.28 package | |
| (see <code>nix-builder/pkgs/manylinux_2_28/stdenv.nix</code>) and use that.</p> <h2 class="relative group"><a id="the-package-set-pattern" 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="#the-package-set-pattern"><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>The package set pattern</span></h2> <p data-svelte-h="svelte-18b8mp1">We repackage various existing package sets as Nix derivations. For instance, | |
| this is done for ROCm, XPU, and manylinux_2_28 packages. We do this because | |
| we want these libraries to be as close as what the user would install. This | |
| avoids compatibility issues between the kernels and the official vendor | |
| packages. For instance, suppose that we built a ROCm library as a shared | |
| library and ROCm provides the same library as a static library, then compiled | |
| kernels could use symbols that cannot be resolved when installing the official | |
| ROCm packages. Similarly, using the official packages allows us to test | |
| against the official upstream packages.</p> <p data-svelte-h="svelte-1x0q90t">These package sets all follow the same pattern:</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-nix "><!-- HTML_TAG_START -->{ | |
| lib, | |
| callPackage, | |
| newScope, | |
| pkgs, | |
| }: | |
| { | |
| packageMetadata, | |
| }: | |
| <span class="hljs-keyword">let</span> | |
| <span class="hljs-keyword">inherit</span> (lib.fixedPoints) extends composeManyExtensions; | |
| <span class="hljs-attr">fixedPoint</span> = final: { | |
| <span class="hljs-keyword">inherit</span> lib; | |
| }; | |
| <span class="hljs-attr">composed</span> = lib.composeManyExtensions [ | |
| <span class="hljs-comment"># Base package set.</span> | |
| (<span class="hljs-built_in">import</span> ./components.nix { <span class="hljs-keyword">inherit</span> packageMetadata; }) | |
| <span class="hljs-comment"># Package-specific overrides.</span> | |
| (<span class="hljs-built_in">import</span> ./overrides.nix) | |
| <span class="hljs-comment"># Additional overlays that extend the package set.</span> | |
| (<span class="hljs-built_in">import</span> ./some-overlay.nix) | |
| ]; | |
| <span class="hljs-keyword">in</span> | |
| lib.makeScope newScope (lib.extends composed fixedPoint)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-11ywwcl">We use a fixed point to build up the package set as a list of | |
| <a href="https://nixos.org/manual/nixpkgs/stable/#sec-overlays-definition" rel="nofollow">overlays</a>. | |
| This has various benefits. For instance, it allows us to refine the | |
| package set incrementally and we can refer to the final versions of | |
| packages in intermediate overlays.</p> <p data-svelte-h="svelte-1o8pfoq">The package sets all use a similar list of overlays:</p> <ul data-svelte-h="svelte-qhvlz7"><li>An initial overlay (<code>components.nix</code>) that applies a generic builder | |
| to the package set metadata. The metadata typically comes from a Yum/DNF | |
| repository that contains RPM packages.The generic builder will extract the | |
| RPMs and move binaries, libraries, and headers to the right location. This | |
| results in a set of Nix derivations that may or may not build.</li> <li>The next overlay (<code>overrides.nix</code>) fixes up derivations generated by the | |
| generic builder in the previous overlay that do not build. Fixing the | |
| derivations typically consists of adding missing dependencies and changing | |
| embedded FHS paths to Nix store paths.</li> <li>Additional overlays with derivations that combine outputs from previous | |
| overlays. One typical example are derivations that construct a full compiler | |
| toolchain (e.g. <code>nix-builder/pkgs/manylinux_2_28/gcc-unwrapped.nix</code>).</li></ul> <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/design-nix-builder.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_13ecnld = { | |
| assets: "/docs/kernels/pr_607/en", | |
| base: "/docs/kernels/pr_607/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/kernels/pr_607/en/_app/immutable/entry/start.783410d4.js"), | |
| import("/docs/kernels/pr_607/en/_app/immutable/entry/app.d93c6142.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 8], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 18.5 kB
- Xet hash:
- 4ff547b8ffd762ecfe6476c2c690464cb891d08ac2eef884ebb581bf2d82415a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.