Buckets:
| # AutoRound | |
| [AutoRound](https://github.com/intel/auto-round) là một bộ công cụ lượng tử hóa tiên tiến. Nó đạt độ chính xác cao ở độ rộng bit cực thấp (2-4 bit) với việc tinh chỉnh tối thiểu nhờ sử dụng phương pháp hạ gradient theo dấu và cung cấp khả năng tương thích phần cứng rộng rãi. Xem các bài báo [SignRoundV1](https://arxiv.org/pdf/2309.05516) và [SignRoundV2](https://arxiv.org/abs/2512.04746) của chúng tôi để biết thêm chi tiết. | |
| Cài đặt `auto-round` (phiên bản ≥ 0.13.0): | |
| ```bash | |
| pip install "auto-round>=0.13.0" | |
| ``` | |
| Để sử dụng kernel Marlin cho suy luận CUDA nhanh hơn, hãy cài đặt `gptqmodel`: | |
| ```bash | |
| pip install "gptqmodel>=5.8.0" | |
| ``` | |
| ## Tải một mô hình đã lượng tử hóa | |
| Tải một mô hình AutoRound đã lượng hóa trước bằng cách truyền `AutoRoundConfig` vào [from_pretrained()](/docs/diffusers/v0.43.0/vi/api/models/overview#diffusers.ModelMixin.from_pretrained). Phương thức này hoạt động với bất kỳ mô hình nào được tải qua [Accelerate](https://hf.co/docs/accelerate/index) và có các lớp `torch.nn.Linear`. | |
| Bạn có thể sử dụng [PipelineQuantizationConfig](/docs/diffusers/v0.43.0/vi/api/quantization#diffusers.PipelineQuantizationConfig) để lượng tử hóa các thành phần cụ thể của một 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") | |
| ``` | |
| Hoặc tải trực tiếp một thành phần mô hình đã lượng tử hóa: | |
| ```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 trong Diffusers chỉ hỗ trợ nạp các mô hình *đã lượng tử hóa trước*. Để lượng tử hóa một mô hình từ đầu, hãy sử dụng trực tiếp [CLI hoặc API Python của AutoRound](https://github.com/intel/auto-round), sau đó nạp kết quả bằng Diffusers. | |
| ## torch.compile | |
| AutoRound tương thích với [`torch.compile`](../optimization/fp16#torchcompile) để suy luận nhanh hơn. Bạn có thể biên dịch transformer (DiT) đã lượng tử hóa để đạt hiệu suất tốt hơn: | |
| ```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) | |
| ``` | |
| ## Các backend | |
| AutoRound hỗ trợ nhiều backend suy luận cho mô hình đã lượng tử hóa Weight-only. Backend kiểm soát kernel nào xử lý khử lượng tử hóa trong quá trình truyền thẳng. Đặt tham số `backend` trong `AutoRoundConfig` để chọn một: | |
| | Backend | Giá trị | Thiết bị | Yêu cầu | Ghi chú | | |
| |---------|-------|--------|--------------|-------| | |
| | **Auto** | `"auto"` | Bất kỳ | — | Mặc định. Tự động chọn backend khả dụng tốt nhất. | | |
| | **PyTorch** | `"torch"` | CPU / CUDA | — | Triển khai thuần PyTorch. Khả năng tương thích rộng nhất. | | |
| | **Triton** | `"tritonv2"` | CUDA | `triton` | Lõi (kernel) dựa trên Triton cho suy luận trên GPU. | | |
| | **ExllamaV2** | `"exllamav2"` | CUDA | `gptqmodel>=5.8.0` | Hiệu năng CUDA tốt thông qua kernel ExllamaV2. | | |
| | **Marlin** | `"marlin"` | CUDA | `gptqmodel>=5.8.0` | Hiệu suất CUDA tốt nhất thông qua 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") | |
| ``` | |
| ## Lưu và tải | |
| AutoRound yêu cầu hiệu chuẩn dữ liệu để lượng tử hóa một mô hình. Việc này được thực hiện bên ngoài Diffusers bằng cách sử dụng trực tiếp [thư viện AutoRound](https://github.com/intel/auto-round): | |
| ```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") | |
| ``` | |
| Để biết thêm chi tiết về các tùy chọn hiệu chuẩn, hãy xem [tài liệu 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") | |
| ``` | |
| ### Các phương án lượng hóa được hỗ trợ | |
| AutoRound hỗ trợ một số Schemes: | |
| - **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**(tất cả các định dạng Q*_K, Q*_0, Q*_1 do llamacpp cung cấp đều được hỗ trợ) | |
| - **NVFP4**(Tính năng thử nghiệm, khuyến nghị xuất sang định dạng `llm_compressor` với data_type nvfp4,act_data_type nvfp4,static_global_scale,group_size 16) | |
| - **MXFP4**(**Tính năng nghiên cứu, không có kernel thực**, MXFP4 chuẩn, data_type mxfp,act_data_type mxfp,bits 4, act_bits 4, group_size 32) | |
| - **MXINT4**(**Tính năng nghiên cứu, không có kernel thực**, MXINT4 chuẩn, data_type mxint,act_data_type mxint,bits 4, act_bits 4, group_size 32) | |
| - **MXFP4_RCEIL**(**Tính năng nghiên cứu, không có kernel thực**, biến thể của NVIDIA, data_type mxfp, act_data_type mxfp_rceil, bits 4, act_bits 4, group_size 32) | |
| - **MXFP8**(**Tính năng nghiên cứu, không có kernel thực**, data_type mxfp,act_data_type mxfp_rceil,group_size 32) | |
| - **FPW8A16**(**Tính năng nghiên cứu, không có kernel thực**, data_type fp8,group_size 0->per tensor ) | |
| - **FP8_STATIC**(**Tính năng nghiên cứu, không có kernel thực**, data_type:fp8,act_data_type:fp8,group_size -1 ->mỗi kênh, act_group_size=0->mỗi tensor) | |
| Ngoài ra, bạn có thể chỉnh sửa `group_size`, `bits`, `sym` và nhiều cấu hình khác mà bạn muốn, mặc dù có thể không có kernel thực sự nào. | |
| ## Tài nguyên | |
| - [Các mô hình AutoRound đã lượng hóa trước trên Hub](https://huggingface.co/models?search=autoround) | |
Xet Storage Details
- Size:
- 8.21 kB
- Xet hash:
- 785b331fff36f4c85c8d556933505c369c4741716e79e5db5453952043da360f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.