Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions nemo/quant/pact.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def pact_quantized_requantize(t, eps_in, eps_out, D=1, exclude_requant_rounding=
# re-quantize from a lower precision (larger eps_in) to a higher precision (lower eps_out)
def pact_integer_requantize(t, eps_in, eps_out, D=1):
D = D.clone().detach().to(eps_in.device)
# D = torch.tensor(D, device=eps_in.device)
eps_ratio = (D*eps_in/eps_out).round()
device = t.device
return torch.as_tensor((t.clone().detach().type(torch.int64) * eps_ratio.clone().detach().type(torch.int64) // D), dtype=torch.float32, device=device)
Expand Down Expand Up @@ -372,7 +373,7 @@ def set_static_precision(self, limit_at_32_bits=True, **kwargs):
if not limit_at_32_bits:
self.D = D
else:
self.D = min(D, 2.0**(32-1-(self.precision.get_bits())))
self.D = min(D, torch.tensor(2.0**(32-1-(self.precision.get_bits())), device = D.device))

def get_output_eps(self, eps_in):
r"""Get the output quantum (:math:`\varepsilon`) given the input one.
Expand Down Expand Up @@ -610,8 +611,9 @@ def set_output_eps(self, limit_at_32_bits=True, **kwargs):
if not limit_at_32_bits:
self.D = D
else:
self.D = min(D, 2**(32-(self.precision.get_bits())))

# self.D = min(D, 2**(32-(self.precision.get_bits())))
self.D = min(D, torch.tensor([2.0**(32-1-(self.precision.get_bits()))], device = D.device, dtype=torch.int64))

def get_output_eps(self, eps_in):
r"""Get the output quantum (:math:`\varepsilon`) given the input one.

Expand Down