()
| 41 | |
| 42 | |
| 43 | def 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 | |
| 65 | def test_warmup_bitwidth_used_before_threshold(): |
nothing calls this directly
no test coverage detected