(qweight: torch.Tensor, scale: torch.Tensor, block_size: torch.Tensor)
| 248 | return qweight.to(torch.float32) * scale |
| 249 | |
| 250 | def 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 | |
| 262 | def 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 |
no test coverage detected