Skip to content

Commit

Permalink
Add the unittest import for test_fake_quant.py (pytorch#28815)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#28815

Add the unittest import
ghstack-source-id: 92789329

Test Plan: CI

Differential Revision: D18191989

fbshipit-source-id: c54e0309e21156c33e4fec01bfba17a1c30463c9
jianyuh authored and facebook-github-bot committed Oct 29, 2019
1 parent 949678b commit 6f90567
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/test_fake_quant.py
Original file line number Diff line number Diff line change
@@ -10,12 +10,13 @@
from torch.quantization import FakeQuantize
from torch.quantization import default_observer, default_per_channel_weight_observer
import io
import unittest

# Reference method for fake quantize
def _fake_quantize_per_tensor_affine_reference(X, scale, zero_point, quant_min, quant_max):
res = (torch.clamp(torch.round(X.cpu() * (1.0 / scale) + zero_point), quant_min, quant_max) - zero_point) * scale
return res


# Reference method for the gradient of the fake quantize operator
def _fake_quantize_per_tensor_affine_grad_reference(dY, X, scale, zero_point, quant_min, quant_max):
Xq = torch.round(X.cpu() * (1.0 / scale) + zero_point)

0 comments on commit 6f90567

Please sign in to comment.