MCPcopy Index your code
hub / github.com/DevTechJr/turboquant_cutile / quantize

Method quantize

turboquant_cutile/codebook.py:70–72  ·  view source on GitHub ↗
(self, x: torch.Tensor)

Source from the content-addressed store, hash-verified

68 self.centroids, self.boundaries = solve_lloyd_max(d, bits)
69
70 def quantize(self, x: torch.Tensor) -> torch.Tensor:
71 diffs = x.unsqueeze(-1) - self.centroids.to(x.device)
72 return diffs.abs().argmin(dim=-1)
73
74 def dequantize(self, indices: torch.Tensor) -> torch.Tensor:
75 return self.centroids.to(indices.device)[indices.long()]

Calls

no outgoing calls

Tested by 2