MCPcopy Index your code
hub / github.com/OpenPPL/ppq / ref_grad_func

Function ref_grad_func

tests/test_cuda_kernel.py:67–78  ·  view source on GitHub ↗
(value: torch.Tensor, dy: torch.Tensor, 
                      scale: torch.Tensor, offset: torch.Tensor)

Source from the content-addressed store, hash-verified

65
66def __TEST_QUANTIZE_LT_B__(size: List[int], iterations: int, sym: bool):
67 def ref_grad_func(value: torch.Tensor, dy: torch.Tensor,
68 scale: torch.Tensor, offset: torch.Tensor):
69
70 qt = ppq_tensor_round(value / scale, policy=ROUNDING_POLICY) + offset
71 clipped_qt = qt.clip(Q_MIN, Q_MAX)
72
73 dx = torch.where(clipped_qt != qt, torch.zeros_like(dy), dy)
74 ds = torch.where(clipped_qt == qt, (((qt - offset) * scale) - value) * dy / scale, torch.zeros_like(dy))
75 ds += torch.where(qt > Q_MAX, (Q_MAX - offset) * dy, torch.zeros_like(dy))
76 ds += torch.where(qt < Q_MIN, (Q_MIN - offset) * dy, torch.zeros_like(dy))
77 ds = ds.sum() / sqrt(value.numel() * (Q_MAX - Q_MIN))
78 return dx, ds
79
80 for _ in tqdm(range(iterations), desc='QUANTIZE LT_B TESTING...'):
81 t = torch.rand(size=size).cuda() * 50

Callers 2

__TEST_QUANTIZE_LT_B__Function · 0.85
__TEST_QUANTIZE_LC_B__Function · 0.85

Calls 1

ppq_tensor_roundFunction · 0.90

Tested by

no test coverage detected