Skip to content

Commit d0ba19c

Browse files
authored
Fix dequant mixed for qwen3.5 quantized model made by vllm/llm-compressor (#4675)
* fix dequant_mixed * add llm_config check * remove dequantize_gemm * add CompressedTensorFormat.dequant * Potential fix for pull request finding * Potential fix for pull request finding
1 parent 408bdac commit d0ba19c

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

lmdeploy/turbomind/linear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def _dequant_linear(linear: Linear, *, data_type) -> Linear:
7373
"""Dequantize a quantized Linear to trivial.
7474
7575
``TrivialFormat.dequant`` is identity, so already-trivial inputs round-trip
76-
safely. ``AWQFormat.dequant`` and ``FP8Format.dequant`` do real work.
77-
GPTQ / CompressedTensor / MXFP4 inherit the base-class
76+
safely. ``AWQFormat.dequant``, ``CompressedTensorFormat.dequant`` and
77+
``FP8Format.dequant`` do real work. GPTQ / MXFP4 inherit the base-class
7878
``NotImplementedError`` — calling ``_dequant_linear`` on one of those is a
7979
broken-fusion-group configuration, and the raise names it at the call site.
8080
"""

lmdeploy/turbomind/weight_format.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def pack_u4_row(x: torch.Tensor) -> torch.Tensor:
7575

7676

7777
def _zeros_int4_symmetric(scales: Tensor) -> Tensor:
78-
"""Synthesize symmetric int4 zero-points (value = 8) matching *scales*
79-
shape."""
80-
return torch.full(scales.shape, 8, dtype=torch.uint8, device=scales.device)
78+
"""Synthesize normalized symmetric int4 zero-points (value = 8) matching
79+
*scales* shape."""
80+
return torch.full(scales.shape, 8, dtype=scales.dtype, device=scales.device)
8181

8282

8383
# ---------------------------------------------------------------------------
@@ -329,6 +329,22 @@ def pack(self, tensor: Tensor, kind: str) -> PackedTensor:
329329
def synthesize_zeros(self, scales: Tensor) -> Tensor:
330330
return _zeros_int4_symmetric(scales)
331331

332+
def dequant(self, tensors, data_type):
333+
weight = tensors['weight']
334+
scales = tensors['scales']
335+
zeros = tensors['zeros']
336+
337+
out_size = weight.shape[-1]
338+
zeros = zeros[..., :out_size]
339+
340+
scales = scales.repeat_interleave(self.block_in, dim=0)[:weight.shape[0]]
341+
zeros = zeros.repeat_interleave(self.block_in, dim=0)[:weight.shape[0]]
342+
w = (weight.to(scales.dtype) - zeros.to(scales.dtype)) * scales
343+
result: dict[str, Tensor] = {'weight': w}
344+
if 'bias' in tensors:
345+
result['bias'] = tensors['bias']
346+
return result
347+
332348

333349
class FP8Format(WeightFormat):
334350
name = 'fp8'

0 commit comments

Comments
 (0)