-
Notifications
You must be signed in to change notification settings - Fork 1k
[NPU] [Quant] Support HunyuanImage3 offline quantization with vLLM-Ascend on diffusion path #2979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gcanlin
merged 9 commits into
vllm-project:main
from
jiangmengyu18:support-hyimage3-quant-main
Apr 25, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fc18d8d
[Feature][NPU] support hyimage3 offline quant by vllm-ascend.
f05811d
Merge branch 'support-hyimage3-quant' into support-hyimage3-quant-main
5a1a567
fix bug
ce5f3f1
fix pre-commit
631ddc7
fix pre-commit
9fce16e
fix bug when model_class.packed_modules_mapping has default value.
a2b8e8f
Merge branch 'main' into support-hyimage3-quant-main
jiangmengyu18 99a9fb9
resolve conflicts
jiangmengyu18 051c095
Merge branch 'main' into support-hyimage3-quant-main
jiangmengyu18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # msModelSlim Quantization | ||
|
|
||
| ## Overview | ||
|
|
||
| [msModelSlim](https://github.com/Ascend/msmodelslim) is an Ascend-friendly compression tool focused on acceleration, using compression techniques, and built for Ascend hardware. It includes a series of inference optimization technologies such as quantization and compression, aiming to accelerate large language dense models, MoE models, multimodal understanding models, multimodal generation models, etc. | ||
|
|
||
| Once you have a quantized model which is generated by **msModelSlim**, you can use vLLM Omni for inference by specifying the --quantization ascend parameter to enable quantization features. | ||
|
|
||
| ### Supported Schemes | ||
|
|
||
| | Scheme | Bits | Status | | ||
| |--------|------|--------| | ||
| | W8A8 | 8 | ✅ Supported | | ||
| | W4A4 | 4 | Planned | | ||
|
|
||
| W8A8 is the first supported scheme. Additional schemes will be added in future releases. | ||
|
|
||
| ## Model Quantization | ||
|
|
||
| The following example shows how to generate W8A8 quantized weights for the [Wan2_2 model](https://gitcode.com/Ascend/msmodelslim/blob/master/example/multimodal_sd/Wan2_2/README.md). | ||
|
|
||
| **Quantization Script:** | ||
|
|
||
| ```bash | ||
| msmodelslim quant \ | ||
| --model_path /path/to/wan2_2_t2v_float_weights \ | ||
| --save_path /path/to/wan2_2_t2v_quantized_weights \ | ||
| --device npu \ | ||
| --model_type Wan2_2 \ | ||
| --config_path /lab_practice/wan2_2/wan2_2_w8a8f8_mxfp_t2v.yaml \ | ||
| --trust_remote_code True | ||
| ``` | ||
|
|
||
| After quantization completes, the output directory will contain the quantized model files. | ||
|
|
||
| For more examples, refer to the [official examples](https://gitcode.com/Ascend/msit/tree/master/msmodelslim/example). | ||
|
|
||
| ## Configuration | ||
|
|
||
| 1. **CLI**: pass `--quantization ascend`. | ||
|
jiangmengyu18 marked this conversation as resolved.
|
||
|
|
||
| ```bash | ||
| # Offline inference | ||
| python text_to_image.py --model <your-model> --quantization ascend | ||
|
|
||
| # Online serving | ||
| vllm serve <your-model> --omni --quantization ascend | ||
| ``` | ||
|
|
||
| ## Supported Models | ||
|
|
||
| | Model | HF Models | Recommendation | `ignored_layers` | | ||
| |-------|-----------|---------------|------------------| | ||
| | HunyuanImage-3.0 | - | All layers | None | | ||
|
jiangmengyu18 marked this conversation as resolved.
|
||
|
|
||
| Currently, quantized HunyuanImage-3.0 weights have not been uploaded to public model platforms such as Hugging Face. You can use a [HunyuanImage-3.0-adapted msModelSlim version](https://gitcode.com/betta18/msmodelslim/tree/hyimage3_mxfp8) to generate the quantized weights manually. We will upload the quantized weights as soon as possible. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import os | ||
| from collections.abc import Iterable | ||
| from contextlib import AbstractContextManager, nullcontext | ||
| from types import SimpleNamespace | ||
| from typing import Any | ||
|
|
||
| import torch | ||
|
|
@@ -21,6 +22,7 @@ | |
| from vllm.distributed.device_communicators.shm_broadcast import MessageQueue | ||
| from vllm.logger import init_logger | ||
| from vllm.profiler.wrapper import CudaProfilerWrapper, WorkerProfiler | ||
| from vllm.transformers_utils.config import get_config, get_hf_text_config | ||
| from vllm.utils.import_utils import resolve_obj_by_qualname | ||
| from vllm.utils.mem_utils import GiB_bytes | ||
| from vllm.v1.worker.workspace import init_workspace_manager | ||
|
|
@@ -120,6 +122,20 @@ def init_device(self) -> None: | |
| vllm_config.parallel_config.data_parallel_size = self.od_config.parallel_config.data_parallel_size | ||
| vllm_config.parallel_config.enable_expert_parallel = self.od_config.parallel_config.enable_expert_parallel | ||
| vllm_config.profiler_config = self.od_config.profiler_config | ||
| try: | ||
| hf_config = get_config(self.od_config.model, trust_remote_code=self.od_config.trust_remote_code) | ||
| except ValueError: | ||
| hf_config = None | ||
| logger.info("Skipping hf_config loading for diffusion model %r", self.od_config.model_class_name) | ||
| hf_text_config = get_hf_text_config(hf_config) if hf_config is not None else None | ||
| vllm_config.model_config = SimpleNamespace( | ||
| hf_config=hf_config, | ||
| hf_text_config=hf_text_config, | ||
| enforce_eager=self.od_config.enforce_eager, | ||
| dtype=self.od_config.dtype, | ||
| enable_return_routed_experts=False, | ||
| ) | ||
| vllm_config.quant_config = self.od_config.quantization_config | ||
|
Comment on lines
+125
to
+138
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this PR, Only this block is needed to review carefully. @SamitHuang @wtomin @ZJY0516 |
||
| self.vllm_config = vllm_config | ||
|
|
||
| # Initialize distributed environment | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.