swift15: BF16 absmax bits belong in the HIGH half of the float32

This commit is contained in:
Frank committed 2026-10-06 20:39:21 -07:00
1 parent d062a376b2
commit 3e46d51df8
1 file changed
+3 -3
+3 -3
View File
@@ -57,9 +57,9 @@ for fname, keys in sorted(shards.items()):
gfile = k gfile = k
mm.close() mm.close()
# rebuild the BF16 value from the sign-cleared uint16 bit pattern # rebuild the BF16 value: the 16 bits are the HIGH half of the float32
absmax = np.frombuffer(np.uint16(gmax).tobytes() + b"\x00\x00", absmax = np.frombuffer(b"\x00\x00" + np.uint16(gmax).tobytes(),
dtype=np.float32)[0] dtype=np.float32)[0]
cap = FP8_E4M3_MAX * SCALE cap = FP8_E4M3_MAX * SCALE
print(f"absmax = {absmax!r} (tensor: {gfile})") print(f"absmax = {absmax!r} (tensor: {gfile})")
print(f"2^log2 = 2^{math.log2(absmax):.3f}") print(f"2^log2 = 2^{math.log2(absmax):.3f}")