Buckets:

mishig's picture
download
raw
32.4 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Nunchaku Lite&quot;,&quot;local&quot;:&quot;nunchaku-lite&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Installer les noyaux CUDA&quot;,&quot;local&quot;:&quot;install-the-cuda-kernels&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Charger un pipeline quantifié&quot;,&quot;local&quot;:&quot;load-a-quantized-pipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Types de quantification pris en charge&quot;,&quot;local&quot;:&quot;supported-quantization-types&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;NunchakuLiteQuantizationConfig&quot;,&quot;local&quot;:&quot;nunchakulitequantizationconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Noirs fusionnés&quot;,&quot;local&quot;:&quot;fused-kernels&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;torch.compile&quot;,&quot;local&quot;:&quot;torchcompile&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Ressources&quot;,&quot;local&quot;:&quot;resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/yxSHiGDF.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/CPfOwUO_.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/BYe-f74j.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/D32hXVzh.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DqpuBF3n.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dyp9xKq8.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/17.BtT_NXXy.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dk44y1gU.js" rel="modulepreload">
<!--p4df5g--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Nunchaku Lite&quot;,&quot;local&quot;:&quot;nunchaku-lite&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Install the CUDA kernels&quot;,&quot;local&quot;:&quot;install-the-cuda-kernels&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Load a quantized pipeline&quot;,&quot;local&quot;:&quot;load-a-quantized-pipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Supported quantization types&quot;,&quot;local&quot;:&quot;supported-quantization-types&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;NunchakuLiteQuantizationConfig&quot;,&quot;local&quot;:&quot;nunchakulitequantizationconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Fused kernels&quot;,&quot;local&quot;:&quot;fused-kernels&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;torch.compile&quot;,&quot;local&quot;:&quot;torchcompile&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Resources&quot;,&quot;local&quot;:&quot;resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" 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 dir="auto">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> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="nunchaku-lite" 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="#nunchaku-lite"><span><svg 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><!---->Nunchaku Lite<!----></span></h1><!--]--><!----> <p>Nunchaku Lite est un backend de quantification pour charger des points de contrôle pré-quantifiés dans Diffusers. Créez des points de contrôle compatibles avec <a href="https://github.com/rootonchair/diffuse-compressor" rel="nofollow">diffuse-compressor</a>. Il quantifie et exporte un transformer, puis l’empaquète en tant que pipeline Diffusers.</p> <p>Nunchaku Lite s’appuie sur le moteur d’inférence <a href="https://github.com/nunchaku-ai/nunchaku" rel="nofollow">Nunchaku</a> d’origine, la bibliothèque de quantification <a href="https://github.com/nunchaku-ai/deepcompressor" rel="nofollow">DeepCompressor</a> et l’article <a href="https://arxiv.org/abs/2411.05007" rel="nofollow">SVDQuant</a>.</p> <!--[1--><h2 class="relative group"><a id="install-the-cuda-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="#install-the-cuda-kernels"><span><svg 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><!---->Installer les noyaux CUDA<!----></span></h2><!--]--><!----> <p>Le package kernels fournit les noyaux CUDA optimisés, qui sont chargés automatiquement. Installez-le en premier.</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 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> Copié</div><!----></button><!----></div> <pre class="language-bash "><!---->pip install -U kernels<!----></pre></div><!----> <p>Nunchaku Lite charge ses noyaux depuis le dépôt <a href="https://huggingface.co/kernels/rootonchair/nunchaku-lite-kernels" rel="nofollow"><code>rootonchair/nunchaku-lite-kernels</code></a>, dont l’éditeur n’est pas un éditeur de noyaux de confiance sur le Hub. Son chargement télécharge et exécute du code depuis le Hub, Diffusers exige donc que vous activiez explicitement cette option en définissant <code>DIFFUSERS_TRUST_REMOTE_KERNELS=true</code>. Consultez <a href="../optimization/attention_backends#trusting-remote-kernels">Faire confiance aux noyaux distants</a> pour plus de détails.</p> <!--[1--><h2 class="relative group"><a id="load-a-quantized-pipeline" 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="#load-a-quantized-pipeline"><span><svg 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><!---->Charger un pipeline quantifié<!----></span></h2><!--]--><!----> <p>Chargez le pipeline préquantisé avec <a href="/docs/diffusers/main/fr/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a>, qui lit la configuration de quantification depuis <code>config.json</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 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> Copié</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
model_id = <span class="hljs-string">&quot;rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4&quot;</span>
pipe = DiffusionPipeline.from_pretrained(
model_id, dtype=torch.bfloat16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
prompt = <span class="hljs-string">&quot;A modern red armchair in a quiet studio, soft window light, realistic product photography&quot;</span>
image = pipe(
prompt=prompt,
height=<span class="hljs-number">1024</span>,
width=<span class="hljs-number">1024</span>,
num_inference_steps=<span class="hljs-number">8</span>,
guidance_scale=<span class="hljs-number">1.0</span>,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;ernie-image-turbo-nunchaku-lite.png&quot;</span>)<!----></pre></div><!----> <blockquote class="note"><p>Le dictionnaire d'état exporté doit correspondre exactement à l'architecture du modèle Diffusers cible. Par exemple, un point de contrôle quantifié avec des projections QKV fusionnées ne pourra pas être chargé dans une configuration de modèle qui s'attend à des modules de projection Q, K et V séparés.</p></blockquote> <!--[1--><h2 class="relative group"><a id="supported-quantization-types" 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="#supported-quantization-types"><span><svg 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><!---->Types de quantification pris en charge<!----></span></h2><!--]--><!----> <p>Nunchaku Lite prend en charge les formats de couches linéaires quantifiées suivants.</p> <blockquote class="tip"><p>Utilisez <code>nvfp4</code> sur les GPU Blackwell. L’exécution de points de contrôle <code>int4</code> sur Blackwell peut être plus lente que <code>nvfp4</code>.</p></blockquote> <p>Les noyaux CUDA prennent actuellement en charge les architectures de GPU NVIDIA suivantes :</p> <ul><li><code>sm_75</code> (Turing, par exemple RTX 2080)</li> <li><code>sm_80</code> (Ampere, par exemple A100)</li> <li><code>sm_86</code> (Ampere, par exemple RTX 3090 et RTX A6000)</li> <li><code>sm_89</code> (Ada, par exemple RTX 4090)</li> <li><code>sm_120</code> (Blackwell, par exemple RTX 5090)</li></ul> <blockquote class="note"><p>Les GPU Hopper, tels que <code>sm_90</code> H100 et H200, ne sont pas pris en charge pour le moment.</p></blockquote> <p>Les points de contrôle <code>nvfp4</code> nécessitent un GPU NVIDIA Blackwell ou plus récent. Sur les GPU Blackwell, utilisez PyTorch &gt;= 2.7 avec CUDA &gt;= 12.8. Les points de contrôle <code>int4</code> nécessitent un GPU NVIDIA Turing ou plus récent.</p> <table><thead><tr><th>Méthode</th><th align="right">Précision</th><th align="right">Taille du groupe</th><th>Notes</th></tr></thead><tbody><tr><td><code>svdq_w4a4</code></td><td align="right"><code>nvfp4</code></td><td align="right">16</td><td>Utilise les noyaux d'exécution NVFP4 avec correction de faible rang SVDQ.</td></tr><tr><td><code>svdq_w4a4</code></td><td align="right"><code>int4</code></td><td align="right">64</td><td>Utilise les noyaux INT4 W4A4 avec correction de faible rang SVDQ.</td></tr><tr><td><code>awq_w4a16</code></td><td align="right"><code>int4</code></td><td align="right">64</td><td>Utilise des noyaux AWQ-style uniquement pour les poids en INT4.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="nunchakulitequantizationconfig" 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="#nunchakulitequantizationconfig"><span><svg 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><!---->NunchakuLiteQuantizationConfig<!----></span></h2><!--]--><!----> <p>Le fichier <code>config.json</code> doit inclure un <a href="/docs/diffusers/main/fr/api/quantization#diffusers.NunchakuLiteQuantizationConfig">NunchakuLiteQuantizationConfig</a>. Il définit le <code>compute_dtype</code> d’exécution et les modules cibles pour chaque méthode de quantification Nunchaku Lite.</p> <ul><li><code>compute_dtype</code> : type de données d'exécution pour les tampons à virgule flottante dans les modules quantifiés, généralement <code>torch.bfloat16</code>.</li> <li><code>svdq_w4a4</code> : configuration cible SVDQ W4A4 avec <code>precision</code>, <code>group_size</code>, <code>rank</code> et <code>targets</code>.</li> <li><code>awq_w4a16</code> : configuration cible AWQ W4A16 avec <code>precision</code>, <code>group_size</code> et <code>targets</code>.</li></ul> <p>Chaque entrée de <code>targets</code> doit pointer vers une couche linéaire. Diffusers remplace chaque cible <code>svdq_w4a4</code> par une couche SVDQ W4A4 et chaque cible <code>awq_w4a16</code> par une couche AWQ W4A16. L’exemple ci-dessous montre la forme attendue avec des listes de cibles raccourcies.</p> <p>Listez chaque module que vous souhaitez quantiser sous <code>svdq_w4a4</code> ou <code>awq_w4a16</code>. Un module ne peut utiliser qu’une seule méthode, ne listez donc pas la même cible sous les deux.</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 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> Copié</div><!----></button><!----></div> <pre class="language-json "><!----><span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;_class_name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;ErnieImageTransformer2DModel&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;quantization_config&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;quant_method&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;nunchaku_lite&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;compute_dtype&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;bfloat16&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;svdq_w4a4&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;precision&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;nvfp4&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;group_size&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">16</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;rank&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">32</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;targets&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">&quot;layers.0.self_attention.to_q&quot;</span><span class="hljs-punctuation">]</span>
<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;awq_w4a16&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;precision&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;int4&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;group_size&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">64</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;targets&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">&quot;final_linear&quot;</span><span class="hljs-punctuation">]</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="fused-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="#fused-kernels"><span><svg 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><!---->Noirs fusionnés<!----></span></h2><!--]--><!----> <p>Le moteur <a href="https://github.com/nunchaku-ai/nunchaku" rel="nofollow">Nunchaku</a> original tire une grande partie de sa vitesse de chemins d'exécution fusionnés spécifiques au modèle. Il combine les projections Q, K et V avec RMSNorm et RoPE, et utilise un noyau GELU fusionné pour le MLP. Nunchaku Lite, en revanche, utilise le modèle standard de Diffusers avec des couches linéaires quantifiées génériques, et n'inclut donc pas ces fusions.</p> <p>Les mesures suivantes montrent l’impact de ces fusions sur la latence par étape dans le moteur Nunchaku d’origine, mesuré avec Flux Schnell sur une RTX 5090.</p> <table><thead><tr><th>Optimisation</th><th>Latence avec désactivé</th><th>Latence avec activé</th><th>Accélération</th></tr></thead><tbody><tr><td>Fusion QKV+norm+RoPE (combinée)</td><td>1.057 s</td><td>0.834 s</td><td><strong>1.27×</strong></td></tr><tr><td>— regroupement de Q/K/V en une seule multiplication matricielle, seul</td><td>1.059 s</td><td>1.034 s</td><td>1.025×</td></tr><tr><td>— Fusion de l'épilogue RMSNorm+RoPE, en plus du regroupement</td><td>1.034 s</td><td>0.836 s</td><td>1.236×</td></tr><tr><td>Fusion GELU-MLP</td><td>0.766 s</td><td>0.722 s</td><td><strong>1.06×</strong></td></tr></tbody></table> <p>Sans ces fusions, le GPU lance les opérations de projection, de normalisation, d’embedding rotatif et de MLP comme des noyaux distincts, ce qui ajoute un surcoût de lancement. <code>torch.compile</code> peut réduire une partie de ce surcoût, bien qu’il ne reproduise pas nécessairement les noyaux fusionnés du moteur d’origine. Effectuez des benchmarks du pipeline compilé pour votre modèle et votre charge de travail.</p> <!--[1--><h2 class="relative group"><a id="torchcompile" 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="#torchcompile"><span><svg 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><!---->torch.compile<!----></span></h2><!--]--><!----> <p>Les noyaux Nunchaku Lite et les couches linéaires quantifiées sont compatibles avec <a href="../optimization/fp16#torchcompile"><code>torch.compile</code></a>.
Compilez le transformeur quantifié après le chargement du pipeline pour une inférence plus rapide.</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 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> Copié</div><!----></button><!----></div> <pre class="language-python "><!---->pipe.transformer = torch.<span class="hljs-built_in">compile</span>(pipe.transformer, mode=<span class="hljs-string">&quot;default&quot;</span>, fullgraph=<span class="hljs-literal">True</span>)<!----></pre></div><!----> <p>Le pipeline Nunchaku Lite NVFP4 compilé s'exécute 1,8 fois plus vite que le pipeline BF16 d'origine (2,271 s → 1,675 s sur une RTX PRO 6000).</p> <!--[1--><h2 class="relative group"><a id="resources" 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="#resources"><span><svg 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><!---->Ressources<!----></span></h2><!--]--><!----> <ul><li><a href="https://github.com/rootonchair/diffuse-compressor" rel="nofollow">diffuse-compressor</a></li> <li><a href="https://nunchaku.tech/docs/nunchaku/installation/installation.html" rel="nofollow">Exigences d'installation de Nunchaku</a></li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/quantization/nunchaku.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><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_gxjg5b = {
base: "/docs/diffusers/main/en",
assets: "/docs/diffusers/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js"),
import("/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 17],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
32.4 kB
·
Xet hash:
c220975c460dc272ff345e652c0064dfb27b69e61b378bcf268a8cf51725fd92

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