Buckets:
| # AutoRound | |
| [AutoRound](https://github.com/intel/auto-round) adalah toolkit kuantisasi tingkat lanjut. Alat ini mencapai akurasi tinggi pada lebar bit ultra-rendah (2-4 bit) dengan penyetelan minimal dengan memanfaatkan sign-gradient descent dan menyediakan kompatibilitas perangkat keras yang luas. Lihat makalah kami [SignRoundV1](https://arxiv.org/pdf/2309.05516) dan [SignRoundV2](https://arxiv.org/abs/2512.04746) untuk detail lebih lanjut. | |
| Instal `auto-round`(versi ≥ 0.13.0): | |
| ```bash | |
| pip install "auto-round>=0.13.0" | |
| ``` | |
| Untuk menggunakan kernel Marlin untuk inferensi CUDA yang lebih cepat, instal `gptqmodel`: | |
| ```bash | |
| pip install "gptqmodel>=5.8.0" | |
| ``` | |
| ## Muat model terkuantisasi | |
| Muat model AutoRound yang sudah dikuantisasi sebelumnya dengan meneruskan `AutoRoundConfig` ke [from_pretrained()](/docs/diffusers/main/id/api/models/overview#diffusers.ModelMixin.from_pretrained). Metode ini berfungsi dengan model apa pun yang dimuat melalui [Accelerate](https://hf.co/docs/accelerate/index) dan memiliki lapisan `torch.nn.Linear`. | |
| Anda dapat menggunakan [PipelineQuantizationConfig](/docs/diffusers/main/id/api/quantization#diffusers.PipelineQuantizationConfig) untuk mengkuantisasi komponen tertentu dari sebuah pipeline: | |
| ```python | |
| import torch | |
| from diffusers import DiffusionPipeline, PipelineQuantizationConfig, AutoRoundConfig | |
| pipeline_quant_config = PipelineQuantizationConfig( | |
| quant_mapping={"transformer": AutoRoundConfig(backend="auto")} | |
| ) | |
| pipe = DiffusionPipeline.from_pretrained( | |
| "INCModel/Z-Image-W4A16-AutoRound", | |
| quantization_config=pipeline_quant_config, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| image = pipe("a cat holding a sign that says hello").images[0] | |
| image.save("output.png") | |
| ``` | |
| Atau muat komponen model terkuantisasi secara langsung: | |
| ```python | |
| import torch | |
| from diffusers import ZImageTransformer2DModel, ZImagePipeline, AutoRoundConfig | |
| model_id = "INCModel/Z-Image-W4A16-AutoRound" | |
| quantization_config = AutoRoundConfig(backend="auto") | |
| transformer = ZImageTransformer2DModel.from_pretrained( | |
| model_id, | |
| subfolder="transformer", | |
| quantization_config=quantization_config, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| pipe = ZImagePipeline.from_pretrained( | |
| model_id, | |
| transformer=transformer, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", | |
| ) | |
| image = pipe("a cat holding a sign that says hello").images[0] | |
| image.save("output.png") | |
| ``` | |
| > [!NOTE] | |
| > AutoRound di Diffusers hanya mendukung pemuatan model *pre-quantized*. Untuk mengkuantisasi model dari awal, gunakan [AutoRound CLI atau Python API](https://github.com/intel/auto-round) secara langsung, lalu muat hasilnya dengan Diffusers. | |
| ## torch.compile | |
| AutoRound kompatibel dengan [`torch.compile`](../optimization/fp16#torchcompile) untuk inferensi yang lebih cepat. Anda dapat mengompilasi transformer (DiT) yang dikuantisasi untuk kinerja yang lebih baik: | |
| ```python | |
| import torch | |
| from diffusers import DiffusionPipeline, PipelineQuantizationConfig, AutoRoundConfig | |
| pipeline_quant_config = PipelineQuantizationConfig( | |
| quant_mapping={"transformer": AutoRoundConfig(backend="auto")} | |
| ) | |
| pipe = DiffusionPipeline.from_pretrained( | |
| "INCModel/Z-Image-W4A16-AutoRound", | |
| quantization_config=pipeline_quant_config, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| pipe.transformer = torch.compile(pipe.transformer, mode="default", fullgraph=False) | |
| ``` | |
| ## Backend | |
| AutoRound mendukung beberapa backend inferensi untuk model yang dikuantisasi hanya pada bobot. Backend mengontrol kernel mana yang menangani dekuantisasi selama forward pass. Atur parameter `backend` di `AutoRoundConfig` untuk memilih salah satu: | |
| | Backend | Nilai | Perangkat | Persyaratan | Catatan | | |
| |---------|-------|--------|--------------|-------| | |
| | **Auto** | `"auto"` | Semua | — | Default. Secara otomatis memilih backend terbaik yang tersedia. | | |
| | **PyTorch** | `"torch"` | CPU / CUDA | — | Implementasi PyTorch murni. Kompatibilitas paling luas. | | |
| | **Triton** | `"tritonv2"` | CUDA | `triton` | Kernel berbasis Triton untuk inferensi GPU. | | |
| | **ExllamaV2** | `"exllamav2"` | CUDA | `gptqmodel>=5.8.0` | Kinerja CUDA yang baik melalui kernel ExllamaV2. | | |
| | **Marlin** | `"marlin"` | CUDA | `gptqmodel>=5.8.0` | Kinerja CUDA terbaik melalui kernel Marlin. | | |
| ```python | |
| from diffusers import AutoRoundConfig | |
| # Auto-select (default) | |
| config = AutoRoundConfig() | |
| # Explicit Triton backend for CUDA | |
| config = AutoRoundConfig(backend="tritonv2") | |
| # Marlin backend for best CUDA performance (requires gptqmodel>=5.8.0) | |
| config = AutoRoundConfig(backend="marlin") | |
| # ExllamaV2 backend for good CUDA performance (requires gptqmodel>=5.8.0) | |
| config = AutoRoundConfig(backend="exllamav2") | |
| # PyTorch backend for CPU/CUDA inference | |
| config = AutoRoundConfig(backend="torch") | |
| ``` | |
| ## Simpan dan muat | |
| AutoRound memerlukan kalibrasi data untuk mengkuantisasi model. Hal ini dilakukan di luar Diffusers dengan menggunakan [library AutoRound](https://github.com/intel/auto-round) secara langsung: | |
| ```python | |
| from auto_round import AutoRound | |
| autoround = AutoRound( | |
| "Tongyi-MAI/Z-Image", | |
| scheme="W4A16", # W4G128 symmetric | |
| enable_torch_compile=True, | |
| num_inference_steps=3, | |
| guidance_scale=7.5, | |
| dataset="coco2014", | |
| ) | |
| autoround.quantize_and_save("Z-Image-W4A16-AutoRound") | |
| ``` | |
| Untuk detail lebih lanjut tentang opsi kalibrasi, lihat [dokumentasi AutoRound](https://github.com/intel/auto-round). | |
| ```python | |
| import torch | |
| from diffusers import ZImageTransformer2DModel, ZImagePipeline | |
| model_id = "INCModel/Z-Image-W4A16-AutoRound" | |
| # The inference backend will be automatically selected. | |
| pipe = ZImagePipeline.from_pretrained( | |
| model_id, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| image = pipe("a cat holding a sign that says hello").images[0] | |
| image.save("output.png") | |
| ``` | |
| ### Skema Kuantisasi yang Didukung | |
| AutoRound mendukung beberapa Skema: | |
| - **W4A16**(bits:4,group_size:128,sym:True,act_bits:16) | |
| - **W8A16**(bits:8,group_size:128,sym:True,act_bits:16) | |
| - **W3A16**(bits:3,group_size:128,sym:True,act_bits:16) | |
| - **W2A16**(bits:2,group_size:128,sym:True,act_bits:16) | |
| - **GGUF:Q4_K_M**(semua Q*_K,Q*_0,Q*_1 yang disediakan oleh llamacpp didukung) | |
| - **NVFP4**(Fitur eksperimental, disarankan untuk mengekspor ke format `llm_compressor` dengan data_type nvfp4,act_data_type nvfp4,static_global_scale,group_size 16) | |
| - **MXFP4**(**Fitur riset, tanpa kernel nyata**, Standard MXFP4, data_type mxfp,act_data_type mxfp,bits 4, act_bits 4, group_size 32) | |
| - **MXINT4**(**Fitur riset, tanpa kernel nyata**, Standard MXINT4, data_type mxint,act_data_type mxint,bits 4, act_bits 4, group_size 32) | |
| - **MXFP4_RCEIL**(**Fitur riset, tidak ada kernel nyata**, varian NVIDIA, data_type mxfp, act_data_type mxfp_rceil, bits 4, act_bits 4, group_size 32) | |
| - **MXFP8**(**Fitur riset, tanpa kernel nyata**, data_type mxfp,act_data_type mxfp_rceil,group_size 32) | |
| - **FPW8A16**(**Fitur riset, tanpa kernel nyata**, data_type fp8,group_size 0->per tensor ) | |
| - **FP8_STATIC**(**Fitur riset, tanpa kernel nyata**, data_type:fp8,act_data_type:fp8,group_size -1 ->per channel, act_group_size=0->per tensor) | |
| Selain itu, Anda dapat memodifikasi `group_size`, `bits`, `sym` dan banyak konfigurasi lain yang Anda inginkan, meskipun mungkin tidak ada kernel nyata. | |
| ## Sumber daya | |
| - [Model AutoRound pra-kuantisasi di Hub](https://huggingface.co/models?search=autoround) | |
Xet Storage Details
- Size:
- 7.5 kB
- Xet hash:
- 44624e66b14ad321969dc1dae38ce562bc1cc4d1c7ad3eacf987a48cbefc80db
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.