[refactor] refactor weight trans nz and transpose (#4878)
### What this PR does / why we need it?
Now `VLLM_ASCEND_ENABLE_NZ` will have three options:
0: disable nz;
1: only quant case enable nz;
2: enable nz as long as possible;
And `VLLM_ASCEND_ENABLE_NZ`=1 by default.
All cases are shown in the table below:
| | W4A4 | W4A8 | W8A8 | fp16/bf16 | fp32 |
|---|---|---|---|---|---|
| trans nz | can't support nz | trans nz by default | trans nz by
default | trans nz when VLLM_ASCEND_ENABLE_NZ is 2 | can't support nz |
| transpose | only support not transpose case | only support transpose
case | only support transpose case | linear: only support not transpose
case<br>gmm: only support transpose case | same to fp16/bf16 |
Some exceptional cases:
1. MLAPO op need to do some additional processing on the weights,
including trans nz. If use MLAPO op, some weight will be transformed to
nz forcely;
2. MLA/SFA's weight `W_UV` will be used by op
`torch.ops._C_ascend.batch_matmul_transpose`, and this op can't support
nz currently;
### Does this PR introduce _any_ user-facing change?
Now fp16/bf16 weight will not trans nz by default.
### How was this patch tested?
- vLLM version: v0.12.0
- vLLM main:
ad32e3e19c
Signed-off-by: zzzzwwjj <1183291235@qq.com>
This commit is contained in:
@@ -62,7 +62,8 @@ class TestAscendW4A8DynamicLinearMethod(TestBase):
|
||||
|
||||
@patch('torch_npu.npu_convert_weight_to_int4pack')
|
||||
@patch('torch.Tensor.npu')
|
||||
def test_process_weights_after_loading(self, mock_npu,
|
||||
@patch("torch_npu.npu_format_cast")
|
||||
def test_process_weights_after_loading(self, mock_format_cast, mock_npu,
|
||||
mock_npu_convert_weight):
|
||||
mock_npu.side_effect = lambda: torch.zeros(
|
||||
(1, 32), dtype=torch.float32)
|
||||
@@ -85,6 +86,8 @@ class TestAscendW4A8DynamicLinearMethod(TestBase):
|
||||
layer.weight_offset_second = torch.nn.Parameter(torch.empty_like(
|
||||
layer.weight_scale_second.data),
|
||||
requires_grad=False)
|
||||
mock_format_cast.return_value = layer.weight.data.transpose(
|
||||
0, 1).contiguous()
|
||||
self.method.process_weights_after_loading(layer)
|
||||
self.assertTrue(hasattr(layer, "weight_scale_bias"))
|
||||
self.assertEqual(layer.weight_scale_bias.data.shape, (32, ))
|
||||
@@ -110,6 +113,8 @@ class TestAscendW4A8DynamicLinearMethod(TestBase):
|
||||
new_layer.scale_bias = torch.nn.Parameter(torch.zeros(
|
||||
(32, 1), dtype=torch.float32),
|
||||
requires_grad=False)
|
||||
mock_format_cast.return_value = new_layer.weight.data.transpose(
|
||||
0, 1).contiguous()
|
||||
self.method.process_weights_after_loading(new_layer)
|
||||
self.assertEqual(new_layer.scale_bias.data.shape, (32, ))
|
||||
self.assertTrue(hasattr(new_layer, "weight_scale_second"))
|
||||
|
||||
Reference in New Issue
Block a user