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: 8 additions & 0 deletions src/num_sys_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ def quant_bfloat_py(self, float_arr, n_bits, n_exp):
power_exp_diff = torch.exp2(exp_diff)
mant_adj = mant / power_exp_diff

# handle mantissa underflow after shifting
# values that become subnormal should be clamped to maintain valid representation
mant_adj[mant_adj < 1.0] = 0.0

exp_adj = torch.full(exp.shape, shared_exp, device=float_arr.device)

# exp should not be larger than max_exp
Expand Down Expand Up @@ -415,6 +419,10 @@ def quant_bfloat_meta_py(self, float_arr, n_bits=8, n_exp=3):
power_exp_diff = torch.exp2(exp_diff)
mant_adj = mant / power_exp_diff

# handle mantissa underflow after shifting
# values that become subnormal should be clamped to maintain valid representation
mant_adj[mant_adj < 1.0] = 0.0

exp_adj = torch.full(exp.shape, shared_exp, device=float_arr.device)

# exp should not be larger than max_exp
Expand Down