MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / blockwise_dequantize

Function blockwise_dequantize

convert.py:250–260  ·  view source on GitHub ↗
(qweight: torch.Tensor, scale: torch.Tensor, block_size: torch.Tensor)

Source from the content-addressed store, hash-verified

248 return qweight.to(torch.float32) * scale
249
250def blockwise_dequantize(qweight: torch.Tensor, scale: torch.Tensor, block_size: torch.Tensor) -> torch.Tensor:
251 assert qweight.ndim == scale.ndim and scale.ndim == block_size.numel() and scale.ndim == 2
252 assert torch.all((torch.tensor(list(qweight.shape)) / block_size).ceil() == torch.tensor(list(scale.shape)))
253 out = torch.empty_like(qweight, dtype=torch.float32)
254 for i in range(scale.shape[0]):
255 for j in range(scale.shape[1]):
256 block_size_i = block_size[0]
257 block_size_j = block_size[1]
258 qw_block = qweight[i*block_size_i:(i+1)*block_size_i, j*block_size_j:(j+1)*block_size_j]
259 out[i*block_size_i:(i+1)*block_size_i, j*block_size_j:(j+1)*block_size_j] = per_tensor_dequantize(qw_block, scale[i, j])
260 return out
261
262def blockwise_quantize(weight: torch.Tensor, block_size: torch.Tensor, dtype: torch.dtype) -> Tuple[torch.Tensor, torch.Tensor]:
263 assert weight.ndim == block_size.numel() and weight.ndim == 2

Callers 2

load_and_dequantizeFunction · 0.85
conv_expertsFunction · 0.85

Calls 1

per_tensor_dequantizeFunction · 0.85

Tested by

no test coverage detected