MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / test_round_quantization_matches_levels

Function test_round_quantization_matches_levels

tests/test_quantizer.py:43–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41
42
43def test_round_quantization_matches_levels():
44 cfg = AttributeQuantizerConfig(
45 enabled=True,
46 bitwidth=4,
47 clamp_range=(0.0, 1.0),
48 warmup_steps=None,
49 mode="round",
50 )
51 quantizer = DifferentiableQuantizer("opacities", cfg)
52
53 x = torch.tensor([0.0, 0.1, 0.5, 0.9, 1.0], dtype=torch.float32, requires_grad=True)
54 result = quantizer.quantize(x, step=0)
55
56 q_step = (1.0 - 0.0) / (2 ** 4 - 1)
57 expected = torch.round(x / q_step) * q_step
58 assert torch.allclose(result.value.detach(), expected)
59 assert torch.allclose(result.q_step.cpu(), torch.tensor(q_step))
60
61 grad = torch.autograd.grad(result.value.sum(), x, retain_graph=False)[0]
62 assert torch.allclose(grad, torch.ones_like(grad))
63
64
65def test_warmup_bitwidth_used_before_threshold():

Callers

nothing calls this directly

Calls 3

quantizeMethod · 0.95

Tested by

no test coverage detected