Buckets:

hf-doc-build/doc / transformers /main /id /quantization /compressed_tensors.html
mishig's picture
download
raw
43.4 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;compressed-tensors&quot;,&quot;local&quot;:&quot;compressed-tensors&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Mode pemuatan&quot;,&quot;local&quot;:&quot;loading-modes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Akselerasi kernel FP8&quot;,&quot;local&quot;:&quot;fp8-kernel-acceleration&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Memuat model FP8 yang sudah dikuantisasi&quot;,&quot;local&quot;:&quot;loading-a-pre-quantized-fp8-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Dequantisasi saat pemuatan&quot;,&quot;local&quot;:&quot;dequantizing-at-load-time&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Checkpoint model&quot;,&quot;local&quot;:&quot;model-checkpoint&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DSYYoqAA.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/BovLmb3z.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/WyYpyc-L.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DYBfcveH.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DOLBYqcr.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/nodes/0.ByO_lNbj.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/ZtBhN-Ei.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/nodes/701.DJOCfMvb.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/D-dvW--N.js" rel="modulepreload">
<link href="/docs/transformers/main/en/_app/immutable/chunks/BDdFI6Uf.js" rel="modulepreload">
<!--6pfp--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;compressed-tensors&quot;,&quot;local&quot;:&quot;compressed-tensors&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Loading modes&quot;,&quot;local&quot;:&quot;loading-modes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;FP8 kernel acceleration&quot;,&quot;local&quot;:&quot;fp8-kernel-acceleration&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Loading a pre-quantized FP8 model&quot;,&quot;local&quot;:&quot;loading-a-pre-quantized-fp8-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Dequantizing at load time&quot;,&quot;local&quot;:&quot;dequantizing-at-load-time&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Model checkpoint&quot;,&quot;local&quot;:&quot;model-checkpoint&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/transformers/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="compressed-tensors" 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="#compressed-tensors"><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><!---->compressed-tensors<!----></span></h1><!--]--><!----> <p><a href="https://github.com/neuralmagic/compressed-tensors" rel="nofollow">compressed-tensors</a> memperluas file <a href="https://github.com/huggingface/safetensors" rel="nofollow">safetensors</a> ke tipe data tensor terkompresi untuk menyediakan format checkpoint terpadu dalam menyimpan dan memuat berbagai format kuantisasi, seperti dense, int-quantized (int8), float-quantized (fp8), dan pack-quantized (int4 atau int8 weight-quantized yang dikemas ke dalam int32).</p> <p>compressed-tensors mendukung fine-tuning dengan <a href="https://huggingface.co/docs/peft" rel="nofollow">PEFT</a> dan juga mencakup fitur-fitur berikut.</p> <ul><li>presisi bobot dan aktivasi fp8, int4, int8.</li> <li>Strategi skala kuantisasi dan titik nol untuk <a href="https://github.com/neuralmagic/compressed-tensors/blob/83b2e7a969d70606421a76b9a3d112646077c8de/src/compressed_tensors/quantization/quant_args.py#L43-L52" rel="nofollow">tensor, channel, group, block, token</a>.</li> <li>Kuantisasi aktivasi dinamis per-token (atau strategi statis apa pun).</li> <li>Kuantisasi modul apa pun, bukan hanya modul <a href="https://pytorch.org/docs/stable/generated/torch.nn.Linear.html" rel="nofollow">nn.Linear</a>.</li> <li>Dukungan yang ditargetkan untuk modul tertentu berdasarkan nama atau kelas.</li></ul> <p>Instal compressed-tensors dari <a href="https://pypi.org/project/compressed-tensors" rel="nofollow">PyPI</a> untuk mendapatkan rilis stabil terbaru (disarankan) atau instal dari sumber untuk mendapatkan fitur terbaru.</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><!--[--><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">PyPI</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">kode sumber</div><!--]--></div> <div class="language-select"><div><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> Disalin</div><!----></button><!----></div> <pre class="language-bash "><!---->pip install compressed-tensors<!----></pre></div><!----></div><!----> <div hidden=""><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> Disalin</div><!----></button><!----></div> <pre class="language-bash "><!---->git <span class="hljs-built_in">clone</span> https://github.com/neuralmagic/compressed-tensors
<span class="hljs-built_in">cd</span> compressed-tensors
pip install -e .<!----></pre></div><!----></div><!----><!----></div><!----> <p>Gunakan <a href="https://huggingface.co/models?other=compressed-tensors" rel="nofollow">tag</a> compressed-tensors untuk mencari model yang kompatibel di Hugging Face Hub.</p> <p>Model yang sudah dikuantisasi dapat dimuat secara langsung. Untuk menguantisasi model ke format compressed-tensors, lihat <a href="https://github.com/vllm-project/llm-compressor" rel="nofollow">llm-compressor</a>. Sebagai alternatif, model dapat dibuat secara independen dan diserialisasi dengan konfigurasi compressed-tensors.</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> Disalin</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM
ct_model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
<span class="hljs-comment"># measure memory usage</span>
mem_params = <span class="hljs-built_in">sum</span>([param.nelement()*param.element_size() <span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> ct_model.parameters()])
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">{mem_params/<span class="hljs-number">2</span>**<span class="hljs-number">30</span>:<span class="hljs-number">.4</span>f}</span> GB&quot;</span>)
<span class="hljs-comment"># 8.4575 GB</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="loading-modes" 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="#loading-modes"><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><!---->Mode pemuatan<!----></span></h2><!--]--><!----> <p>Checkpoint compressed-tensors menyimpan bobotnya dalam bentuk terkompresi (fp8, atau int4/int8 yang dikemas). Cara eksekusinya ditentukan oleh dua argumen <a href="/docs/transformers/main/id/main_classes/quantization#transformers.CompressedTensorsConfig">CompressedTensorsConfig</a>.</p> <table><thead><tr><th>Konfigurasi</th><th>Bobot setelah dimuat</th><th>Eksekusi</th></tr></thead><tbody><tr><td>default</td><td>disimpan dalam format compressed-tensors: setiap tensor yang diserialisasi (<code>weight_packed</code>, <code>weight_scale</code>, <code>weight_zero_point</code>, …) dimuat sesuai dengan cara penyimpanannya</td><td>compressed-tensors memiliki lapisan dan melakukan dekompresi model pada jalur maju pertama</td></tr><tr><td><code>dequantize=True</code></td><td>didekompresi saat dimuat ke dalam dtype model (misalnya BF16)</td><td>model dense biasa tanpa <code>quantization_scheme</code> yang tersisa, sehingga aktivasi w8a8 juga tidak dikuantisasi; model ini dapat dihaluskan atau disimpan dalam dtype tersebut</td></tr><tr><td><code>use_optimized_inference=True</code></td><td>tetap terkuantisasi</td><td>lapisan yang skemanya memiliki kernel yang dijalankan di dalamnya, saat ini W8A8 fp8; hanya untuk inferensi</td></tr></tbody></table> <p>Dengan pengaturan bawaan, <a href="/docs/transformers/main/id/main_classes/model#transformers.PreTrainedModel.save_pretrained">save_pretrained()</a> menuliskan kembali tensor terkompresi tanpa perubahan, sehingga model yang dimuat disimpan dalam format terkompresi yang sama.</p> <!--[1--><h2 class="relative group"><a id="fp8-kernel-acceleration" 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="#fp8-kernel-acceleration"><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><!---->Akselerasi kernel FP8<!----></span></h2><!--]--><!----> <p>Lewati <code>use_optimized_inference=True</code> untuk mempertahankan model compressed-tensors FP8 dalam FP8 dan menjalankan matmuls-nya melalui kernel FP8 yang dipercepat oleh perangkat keras (<a href="https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_mm.html" rel="nofollow">torch.nn.functional.scaled_mm</a>, yang mendispatch ke <code>torch._scaled_mm_v2</code>; versi torch yang lebih lama akan kembali ke <code>torch._scaled_mm</code>), alih-alih mendekuantisasi bobot kembali ke BF16. Mempertahankan bobot dalam FP8 sepanjang inferensi menurunkan penggunaan memori dan mempercepat komputasi. Ini hanya untuk inferensi, jadi biarkan nonaktif untuk fine-tuning.</p> <table><thead><tr><th>Perangkat</th><th>Kernel</th><th>Catatan</th></tr></thead><tbody><tr><td>Intel XPU</td><td><code>torch.nn.functional.scaled_mm</code></td><td>Semua perangkat XPU dengan dukungan FP8</td></tr><tr><td>NVIDIA CUDA (SM89+)</td><td><code>torch.nn.functional.scaled_mm</code></td><td>Ada Lovelace (L4, L40), Hopper (H100), Blackwell dan yang lebih baru</td></tr><tr><td>Apple silicon (MPS)</td><td><code>torch.nn.functional.scaled_mm</code></td><td>Memerlukan torch &gt;= 2.15</td></tr><tr><td>CPU / CUDA SM80 (A100) / MPS dengan torch &lt; 2.15</td><td>Cadangan</td><td><code>use_optimized_inference=True</code> diabaikan, model dijalankan dalam keadaan dequantized</td></tr></tbody></table> <p>Jalur kernel FP8 mendukung tata letak kuantisasi berikut.</p> <table><thead><tr><th>Strategi</th><th>Model contoh</th></tr></thead><tbody><tr><td>Dinamis per kanal</td><td><a href="https://huggingface.co/RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8-dynamic" rel="nofollow">RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8-dynamic</a></td></tr><tr><td>Statis per tensor</td><td><a href="https://huggingface.co/RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8" rel="nofollow">RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8</a></td></tr></tbody></table> <!--[2--><h3 class="relative group"><a id="loading-a-pre-quantized-fp8-model" 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="#loading-a-pre-quantized-fp8-model"><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><!---->Memuat model FP8 yang sudah dikuantisasi<!----></span></h3><!--]--><!----> <p>Kernel FP8 bersifat opt-in: mintanya dengan <code>use_optimized_inference=True</code>, dan kernel ini akan digunakan jika konfigurasi model menentukan kuantisasi FP8 dan GPU yang didukung tersedia.</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> Disalin</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, CompressedTensorsConfig
model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8-dynamic&quot;</span>,
quantization_config=CompressedTensorsConfig(use_optimized_inference=<span class="hljs-literal">True</span>),
device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8-dynamic&quot;</span>)
inputs = tokenizer(<span class="hljs-string">&quot;Hello, how are you?&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=<span class="hljs-number">20</span>)
<span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>))<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="dequantizing-at-load-time" 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="#dequantizing-at-load-time"><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><!---->Dequantisasi saat pemuatan<!----></span></h3><!--]--><!----> <p>Tanpa <code>use_optimized_inference=True</code>, model mengambil rute compressed-tensors reguler: bobot dibiarkan terkompresi dan compressed-tensors mendekompresinya pada forward pass pertama. Sampaikan <code>dequantize=True</code> untuk mendekompresinya saat loading, yang merupakan hal yang Anda inginkan untuk fine-tune model atau menyimpannya dalam presisi aslinya (mis. BF16). Hasilnya adalah model dense biasa: tidak ada skema compressed-tensors yang terlampir, sehingga activation quantization (mis. w8a8) juga dihapus.</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> Disalin</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, CompressedTensorsConfig
model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;RedHatAI/Meta-Llama-3.1-8B-Instruct-FP8-dynamic&quot;</span>,
quantization_config=CompressedTensorsConfig(dequantize=<span class="hljs-literal">True</span>),
device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="model-checkpoint" 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="#model-checkpoint"><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><!---->Checkpoint model<!----></span></h2><!--]--><!----> <p>Model compressed-tensor didefinisikan melalui entri konfigurasinya. Contoh berikut diambil dari file <code>config.json</code> pada <a href="https://huggingface.co/nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf/blob/main/config.json" rel="nofollow">nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf</a>.</p> <p>Ada banyak entri untuk memungkinkan ekspresi yang fleksibel baik selama maupun setelah kompresi, tetapi entri untuk pemuatan dan inferensi dapat disederhanakan untuk berfokus hanya pada beberapa entri kunci.</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> Disalin</div><!----></button><!----></div> <pre class="language-json "><!----><span class="hljs-attr">&quot;quantization_config&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;config_groups&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;group_0&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;input_activations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;num_bits&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">8</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;strategy&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;tensor&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;float&quot;</span>
<span class="hljs-punctuation">}</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;Linear&quot;</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;weights&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;num_bits&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-number">8</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;strategy&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;tensor&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;float&quot;</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;format&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;naive-quantized&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;ignore&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">&quot;lm_head&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;compressed-tensors&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;quantization_status&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;frozen&quot;</span>
<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span><!----></pre></div><!----> <p>File konfigurasi menentukan kuantisasi dari grup konfigurasi (<code>group_0</code>), yang mencakup kuantisasi bobot dan aktivasi ke fp8 dengan strategi statis per tensor. Modul <code>lm_head</code> tidak dikuantisasi, seperti yang ditunjukkan pada kunci <code>ignore</code>.</p> <p>Untuk melihat detail lebih lanjut tentang bobot model, gunakan <a href="https://huggingface.co/nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf?show_file_info=model.safetensors.index.json" rel="nofollow">safetensors viewer</a> di kartu model untuk melihat bobot terkuantisasi, skala input, dan skala bobot untuk semua modul <a href="https://pytorch.org/docs/stable/generated/torch.nn.Linear.html" rel="nofollow">nn.Linear</a>.</p> <table><thead><tr><th>Tensor</th><th>Bentuk</th><th>Presisi</th></tr></thead><tbody><tr><td>model.layers.0.input_layernorm.weight</td><td>[4 096]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.down_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.down_proj.weight</td><td>[4 096, 14 336]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.mlp.down_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.gate_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.gate_proj.weight</td><td>[14 336, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.mlp.gate_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.up_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.mlp.up_proj.weight</td><td>[14 336, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.mlp.up_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.post_attention_layernorm.weight</td><td>[4 096]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.k_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.k_proj.weight</td><td>[1 024, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.self_attn.k_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.o_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.o_proj.weight</td><td>[4 096, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.self_attn.o_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.q_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.q_proj.weight</td><td>[4 096, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.self_attn.q_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.v_proj.input_scale</td><td>[1]</td><td>BF16</td></tr><tr><td>model.layers.0.self_attn.v_proj.weight</td><td>[1 024, 4 096]</td><td>F8_E4M3</td></tr><tr><td>model.layers.0.self_attn.v_proj.weight_scale</td><td>[1]</td><td>BF16</td></tr></tbody></table> <p>Saat memuat model compressed-tensors dengan integrasi <code>~quantizers.HFQuantizer</code>, modul yang ditargetkan diserahkan ke compressed-tensors: integrasi ini menempelkan <code>quantization_scheme</code> yang telah dipecahkan, mengatur <code>quantization_status</code>, mendaftarkan parameter yang disimpan oleh checkpoint (<code>weight</code> dalam fp8, serta <code>weight_scale</code> dan, untuk strategi statis, <code>input_scale</code>), dan memasang jalur forward-nya sendiri di atas parameter tersebut. Modul-modul ini tetap berupa instance <a href="https://pytorch.org/docs/stable/generated/torch.nn.Linear.html" rel="nofollow">nn.Linear</a>, sehingga itulah yang ditampilkan oleh <code>print</code> — versi compressed-tensors terbaru tidak lagi membungkusnya dalam subclass <code>CompressedLinear</code>. Modul yang tercantum di bawah <code>ignore</code>, seperti <code>lm_head</code>, dibiarkan apa adanya.</p> <p>Dengan <code>dequantize=False</code> (default), bobot masih terkompresi setelah proses pemuatan selesai, dan compressed-tensors akan mendekompresi seluruh model pada langkah forward pertama. <code>dequantize=True</code> mendekompresi setiap bobot saat dimuat, sehingga tidak diperlukan langkah forward untuk mendapatkan bobot padat, dan modulnya menjadi lapisan padat biasa tanpa <code>quantization_scheme</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> Disalin</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, CompressedTensorsConfig
model_id = <span class="hljs-string">&quot;nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf&quot;</span>
ct_model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=CompressedTensorsConfig(dequantize=<span class="hljs-literal">False</span>),
device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)
q_proj = ct_model.model.layers[<span class="hljs-number">0</span>].self_attn.q_proj
<span class="hljs-built_in">print</span>(q_proj, q_proj.quantization_status)
<span class="hljs-comment"># Linear(in_features=4096, out_features=4096, bias=False) QuantizationStatus.COMPRESSED</span>
<span class="hljs-comment"># ^ compressed-tensors module: fp8 weight, weight_scale, and its own forward</span>
ct_model(input_ids=torch.tensor([[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]], device=ct_model.device))
<span class="hljs-built_in">print</span>(q_proj, q_proj.quantization_status)
<span class="hljs-comment"># Linear(in_features=4096, out_features=4096, bias=False) QuantizationStatus.DECOMPRESSED</span>
<span class="hljs-comment"># ^ weight is BF16 now, decompressed by that forward pass</span>
ct_model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=CompressedTensorsConfig(dequantize=<span class="hljs-literal">True</span>),
device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)
<span class="hljs-built_in">print</span>(ct_model.model.layers[<span class="hljs-number">0</span>].self_attn.q_proj)
<span class="hljs-comment"># Linear(in_features=4096, out_features=4096, bias=False) weight: BF16</span><!----></pre></div><!----> <p>Dengan <code>use_optimized_inference=True</code>, lapisan yang tercakup oleh grup konfigurasi fp8 diganti dengan <code>CompressedTensorsFP8Linear</code>, yang menyimpan bobot fp8 dan skalanya dalam tata letak yang diharapkan oleh kernel matmul baris-nya. Bobot tersebut tetap dalam fp8, termasuk pada jalur maju (forward pass).</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> Disalin</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, CompressedTensorsConfig
ct_model = AutoModelForCausalLM.from_pretrained(
<span class="hljs-string">&quot;nm-testing/Meta-Llama-3.1-8B-Instruct-FP8-hf&quot;</span>,
quantization_config=CompressedTensorsConfig(use_optimized_inference=<span class="hljs-literal">True</span>),
device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)
<span class="hljs-built_in">print</span>(ct_model.model.layers[<span class="hljs-number">0</span>].self_attn.q_proj)
<span class="hljs-comment"># CompressedTensorsFP8Linear(in_features=4096, out_features=4096, bias=False) weight: F8_E4M3</span><!----></pre></div><!----> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/quantization/compressed_tensors.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_1m6yd5j = {
base: "/docs/transformers/main/en",
assets: "/docs/transformers/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js"),
import("/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 701],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
43.4 kB
·
Xet hash:
d850aceaafd510f9859789debd4edca8ddbb132d3e2e15e70ab9b8e437a18895

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