[Quantization] Support compressed tensors w8a8 static and w8a8 dynamic weight (#4036)
### What this PR does / why we need it?
While using the LLM Compressor quantization tool from the VLLM community
to generate quantized weights, the VLLM Ascend engine needs to be
adapted to support the compressed tensors quantization format.
1. Add AscendCompressedTensorsConfig to replace CompressedTensorsConfig
in vllm.
2. Support CompressedTensorsW8A8 static weight.
- weight: per-channel, int8, symmetric; activation: per-tensor, int8,
symmetric.
4. Support CompressedTensorsW8A8Dynamic weight.
- weight: per-channel, int8, symmetric; activation: per-token, int8,
symmetric, dynamic.
5. Modify the override_quantization_method in AscendQuantConfig.
Co-authored-by: taoqun110 taoqun@huawei.com
Co-authored-by: chenxi-hh chen464822955@163.com
- vLLM version: v0.11.2
---------
Signed-off-by: LHXuuu <scut_xlh@163.com>
Signed-off-by: chenxi-hh <chen464822955@163.com>
Signed-off-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
Co-authored-by: chenxi-hh <chen464822955@163.com>
Co-authored-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
2025-11-28 14:09:39 +08:00
|
|
|
#
|
|
|
|
|
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
|
|
|
|
|
# Copyright 2023 The vLLM team.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
# This file is a part of the vllm-ascend project.
|
|
|
|
|
# Adapted from vllm/tests/basic_correctness/test_basic_correctness.py
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
from tests.e2e.conftest import VllmRunner
|
|
|
|
|
|
|
|
|
|
|
2025-12-12 08:42:08 +08:00
|
|
|
def test_qwen2_5_w8a8_external_quantized_tp2():
|
[Quantization] Support compressed tensors w8a8 static and w8a8 dynamic weight (#4036)
### What this PR does / why we need it?
While using the LLM Compressor quantization tool from the VLLM community
to generate quantized weights, the VLLM Ascend engine needs to be
adapted to support the compressed tensors quantization format.
1. Add AscendCompressedTensorsConfig to replace CompressedTensorsConfig
in vllm.
2. Support CompressedTensorsW8A8 static weight.
- weight: per-channel, int8, symmetric; activation: per-tensor, int8,
symmetric.
4. Support CompressedTensorsW8A8Dynamic weight.
- weight: per-channel, int8, symmetric; activation: per-token, int8,
symmetric, dynamic.
5. Modify the override_quantization_method in AscendQuantConfig.
Co-authored-by: taoqun110 taoqun@huawei.com
Co-authored-by: chenxi-hh chen464822955@163.com
- vLLM version: v0.11.2
---------
Signed-off-by: LHXuuu <scut_xlh@163.com>
Signed-off-by: chenxi-hh <chen464822955@163.com>
Signed-off-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
Co-authored-by: chenxi-hh <chen464822955@163.com>
Co-authored-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
2025-11-28 14:09:39 +08:00
|
|
|
example_prompts = [
|
|
|
|
|
"The president of the United States is",
|
|
|
|
|
]
|
|
|
|
|
max_tokens = 5
|
2025-12-12 08:42:08 +08:00
|
|
|
with VllmRunner(
|
2026-03-10 09:52:50 +08:00
|
|
|
"neuralmagic/Qwen2.5-3B-quantized.w8a8",
|
|
|
|
|
tensor_parallel_size=2,
|
|
|
|
|
cudagraph_capture_sizes=[1, 2, 4, 8],
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
gpu_memory_utilization=0.8,
|
2025-12-12 08:42:08 +08:00
|
|
|
) as vllm_model:
|
[Quantization] Support compressed tensors w8a8 static and w8a8 dynamic weight (#4036)
### What this PR does / why we need it?
While using the LLM Compressor quantization tool from the VLLM community
to generate quantized weights, the VLLM Ascend engine needs to be
adapted to support the compressed tensors quantization format.
1. Add AscendCompressedTensorsConfig to replace CompressedTensorsConfig
in vllm.
2. Support CompressedTensorsW8A8 static weight.
- weight: per-channel, int8, symmetric; activation: per-tensor, int8,
symmetric.
4. Support CompressedTensorsW8A8Dynamic weight.
- weight: per-channel, int8, symmetric; activation: per-token, int8,
symmetric, dynamic.
5. Modify the override_quantization_method in AscendQuantConfig.
Co-authored-by: taoqun110 taoqun@huawei.com
Co-authored-by: chenxi-hh chen464822955@163.com
- vLLM version: v0.11.2
---------
Signed-off-by: LHXuuu <scut_xlh@163.com>
Signed-off-by: chenxi-hh <chen464822955@163.com>
Signed-off-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
Co-authored-by: chenxi-hh <chen464822955@163.com>
Co-authored-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
2025-11-28 14:09:39 +08:00
|
|
|
vllm_output = vllm_model.generate_greedy(example_prompts, max_tokens)
|
|
|
|
|
|
|
|
|
|
golden_results = [
|
2026-03-10 09:52:50 +08:00
|
|
|
"The president of the United States is the head of state and",
|
[Quantization] Support compressed tensors w8a8 static and w8a8 dynamic weight (#4036)
### What this PR does / why we need it?
While using the LLM Compressor quantization tool from the VLLM community
to generate quantized weights, the VLLM Ascend engine needs to be
adapted to support the compressed tensors quantization format.
1. Add AscendCompressedTensorsConfig to replace CompressedTensorsConfig
in vllm.
2. Support CompressedTensorsW8A8 static weight.
- weight: per-channel, int8, symmetric; activation: per-tensor, int8,
symmetric.
4. Support CompressedTensorsW8A8Dynamic weight.
- weight: per-channel, int8, symmetric; activation: per-token, int8,
symmetric, dynamic.
5. Modify the override_quantization_method in AscendQuantConfig.
Co-authored-by: taoqun110 taoqun@huawei.com
Co-authored-by: chenxi-hh chen464822955@163.com
- vLLM version: v0.11.2
---------
Signed-off-by: LHXuuu <scut_xlh@163.com>
Signed-off-by: chenxi-hh <chen464822955@163.com>
Signed-off-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
Co-authored-by: chenxi-hh <chen464822955@163.com>
Co-authored-by: chenxi-hh <32731611+chenxi-hh@users.noreply.github.com>
2025-11-28 14:09:39 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for i in range(len(vllm_output)):
|
|
|
|
|
assert golden_results[i] == vllm_output[i][1]
|
|
|
|
|
print(f"Generated text: {vllm_output[i][1]!r}")
|
2026-01-14 09:17:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_qwen3_moe_w8a8_dynamic_llm_compressor():
|
|
|
|
|
example_prompts = [
|
|
|
|
|
"The president of the United States is",
|
|
|
|
|
]
|
|
|
|
|
max_tokens = 5
|
|
|
|
|
with VllmRunner(
|
2026-03-10 09:52:50 +08:00
|
|
|
"vllm-ascend/Qwen3-30B-A3B-Instruct-2507-quantized.w8a8",
|
|
|
|
|
tensor_parallel_size=2,
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
gpu_memory_utilization=0.8,
|
2026-01-14 09:17:26 +08:00
|
|
|
) as vllm_model:
|
|
|
|
|
vllm_output = vllm_model.generate_greedy(example_prompts, max_tokens)
|
|
|
|
|
|
|
|
|
|
golden_results = [
|
2026-03-10 09:52:50 +08:00
|
|
|
"The president of the United States is the head of state and",
|
2026-01-14 09:17:26 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for i in range(len(vllm_output)):
|
|
|
|
|
assert golden_results[i] == vllm_output[i][1]
|
|
|
|
|
print(f"Generated text: {vllm_output[i][1]!r}")
|
2026-02-02 16:39:32 +08:00
|
|
|
|
2026-03-10 09:52:50 +08:00
|
|
|
|
2026-02-02 16:39:32 +08:00
|
|
|
def test_qwen3_moe_w4a8_dynamic_llm_compressor():
|
|
|
|
|
example_prompts = [
|
|
|
|
|
"The president of the United States is",
|
|
|
|
|
]
|
|
|
|
|
max_tokens = 5
|
|
|
|
|
with VllmRunner(
|
2026-03-10 09:52:50 +08:00
|
|
|
"vllm-ascend/Qwen3-30B-A3B-Instruct-2507-quantized.w4a8",
|
|
|
|
|
tensor_parallel_size=2,
|
|
|
|
|
max_model_len=4096,
|
|
|
|
|
gpu_memory_utilization=0.8,
|
2026-02-02 16:39:32 +08:00
|
|
|
) as vllm_model:
|
|
|
|
|
vllm_output = vllm_model.generate_greedy(example_prompts, max_tokens)
|
|
|
|
|
|
|
|
|
|
golden_results = [
|
2026-03-10 09:52:50 +08:00
|
|
|
"The president of the United States is the head of state and",
|
2026-02-02 16:39:32 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for i in range(len(vllm_output)):
|
|
|
|
|
assert golden_results[i] == vllm_output[i][1]
|
|
|
|
|
print(f"Generated text: {vllm_output[i][1]!r}")
|