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
6 changes: 4 additions & 2 deletions mx/elemwise_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _safe_rshift(x, bits, exp):
if exp is None:
return x / (2**bits)
else:
return x / (2**bits) * (2 ** exp)
out = x / (2**bits) * (2 ** exp)
out[torch.isnan(out)] = 0.
return out


def _round_mantissa(A, bits, round, clamp=False):
Expand Down Expand Up @@ -162,7 +164,7 @@ def _quantize_elemwise_core(A, bits, exp_bits, max_norm, round='nearest',
if not custom_cuda:
out[A == float("Inf")] = float("Inf")
out[A == -float("Inf")] = -float("Inf")
out[A == float("NaN")] = float("NaN")
out[torch.isnan(A)] = float("NaN")

if A_is_sparse:
output = torch.sparse_coo_tensor(sparse_A.indices(), output,
Expand Down