[Feature][Quantization]Support NZ for A5 MX quantization - #15565
[Feature][Quantization]Support NZ for A5 MX quantization#15565lijiahang226 wants to merge 1 commit into
Conversation
- Support FRACTAL_NZ for A5 W8A8/W4A4 MX quantization. - Make W8A8 MXFP8 weight_scale contiguous for NZ. - Keep the pre-NZ non-contiguous MX layout when NZ is disabled, so disabling NZ aligns with behavior before NZ support. Signed-off-by: Li Jiahang <216526138+lijiahang226@users.noreply.github.com>
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces FRACTAL_NZ support for A5 MX quantization paths, specifically for W8A8 MXFP8 and W4A4 MXFP4 models. The changes ensure that weights are correctly converted to the FRACTAL_NZ format required by A5 hardware, while maintaining backward compatibility by preserving the previous layout when NZ is disabled. Additionally, the PR refactors SFA preprocess type resolution and implements mechanisms to avoid redundant conversions for layers already handled by fused SFA processes. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
Suggested PR Title:
[Attention][Ops][Feature] Refactor fused preprocess resolution and support NZ-disabled layouts in quantizationSuggested PR Summary:
### What this PR does / why we need it?
This PR refactors the fused preprocess type resolution and improves weight transformation handling under different quantization schemes (W4A4 MXFP4 and W8A8 MXFP8) when FRACTAL_NZ format conversion is disabled or managed externally.
Key changes include:
- **Fused Preprocess Refactoring**: Extracted `_fused_preprocess_type()` in `sfa_v1.py` to determine the active preprocess type (PROLOG_V3 or MLAPO) and avoid redundant checks.
- **Managed Preprocess Marking**: In `mla.py`, layers managed by fused preprocess are marked with `_fused_preprocess_managed = True` to prevent quantization methods from performing duplicate NZ conversions.
- **NZ-Disabled Layout Support**: Updated W4A4 MXFP4 and W8A8 MXFP8 quantization methods to check `_should_trans_nz`. If NZ conversion is disabled, they preserve the pre-NZ non-contiguous transpose layout.
- **Utility Enhancements**: Updated `maybe_trans_nz` to support passing `customize_dtype` and `input_dtype` to `npu_format_cast`.
- **Robustness**: Replaced `.view` with `.reshape` in MXFP8 MoE weight restoration to avoid runtime errors on non-contiguous tensors.
- **Testing**: Added extensive unit tests covering the new NZ-disabled layouts, utility parameters, and preprocess marking.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Tested via newly added and updated unit tests in:
- `tests/ut/attention/test_sfa_v1.py`
- `tests/ut/ops/test_mla.py`
- `tests/ut/quantization/methods/test_w4a4_mxfp4.py`
- `tests/ut/quantization/methods/test_w8a8_mxfp8.py`
- `tests/ut/test_utils.py`I have no further feedback to provide as the changes are well-implemented and thoroughly tested.
a6262bd to
593a262
Compare
What this PR does / why we need it?
This PR adds FRACTAL_NZ support for A5 MX quantization paths (W8A8 MXFP8 and W4A4 MXFP4).
maybe_trans_nzto forwardcustomize_dtypeandinput_dtypetonpu_format_cast, so FP8/FP4 MX weights can be converted to FRACTAL_NZ with the correct dtype hints.Why needed: A5 requires FRACTAL_NZ for these MX quantized weights. The previous code always kept the non-contiguous transpose layout, which is not compatible with NZ-enabled execution on A5. This change also keeps the old behavior when NZ is disabled, avoiding regressions.
Does this PR introduce any user-facing change?
No new user-facing API. Behavior is affected only when
weight_nz_modeenables NZ on supported hardware; with NZ disabled, the existing MX layout behavior is preserved.How was this patch tested?
Added/updated unit tests:
tests/ut/test_utils.pytests/ut/quantization/methods/test_w4a4_mxfp4.pytests/ut/quantization/methods/test_w8a8_mxfp8.pytests/ut/ops/test_mla.pytests/ut/attention/test_sfa_v1.pyvLLM main: vllm-project/vllm@ba07e4a