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

Function per_expert_blockwise_quantize

convert.py:277–286  ·  view source on GitHub ↗
(expert_weights: torch.Tensor, block_size: torch.Tensor, dtype: torch.dtype)

Source from the content-addressed store, hash-verified

275 return out, scale
276
277def per_expert_blockwise_quantize(expert_weights: torch.Tensor, block_size: torch.Tensor, dtype: torch.dtype) -> Tuple[torch.Tensor, torch.Tensor]:
278 assert expert_weights.ndim == 3
279 num_experts = expert_weights.shape[0]
280 output_weights = []
281 scales = []
282 for e in range(num_experts):
283 weight, scale = blockwise_quantize(expert_weights[e], block_size, dtype)
284 output_weights.append(weight)
285 scales.append(scale)
286 return torch.stack(output_weights), torch.stack(scales)
287
288def per_expert_k_quantize(expert_weights: torch.Tensor, method: Literal["q2_k", "q3_k"]) -> torch.Tensor:
289 assert expert_weights.ndim == 3

Callers 1

conv_expertsFunction · 0.85

Calls 1

blockwise_quantizeFunction · 0.85

Tested by

no test coverage detected