bitsandbytes icon indicating copy to clipboard operation
bitsandbytes copied to clipboard

FP4 Format in Bitsandbytes Library vs ieee 754 standard

Open metamath1 opened this issue 2 years ago • 2 comments

I have a question regarding the functional.py file in the bitsandbytes library, specifically the comment on line 855:

0b000 = 0
0b001 = 0.0625
0b010 = 8
0b011 = 12
0b100 = 4
0b101 = 6
0b110 = 2
0b111 = 3
can also be created with bnb.functional.create_fp8_map(signed=True, exponent_bits=2, precision_bits=1, total_bits=4)

For the FP4 format with 1 sign bit, 2 exponent bits, and 1 mantissa bit, where the sign bit is 0, I'm struggling to understand why the values are calculated as shown above.

According to the IEEE 754 standard, I believe the calculations should be(not considering bias):

0b000 = 0
0b001 = 1.5  (1 + 1*2^-1) * 2^0
0b010 = 2    (1 + 0*2^-1) * 2^1
0b011 = 3    (1 + 1*2^-1) * 2^1
0b100 = 4    (1 + 0*2^-1) * 2^2
0b101 = 6    (1 + 1*2^-1) * 2^2
0b110 = 8    (1 + 0*2^-1) * 2^3
0b111 = 12   (1 + 1*2^-1) * 2^3

What am I missing here? Additionally, could you advise on what documents I should refer to for a better understanding of the FP4 format?

Thank you for your assistance.

metamath1 avatar Jan 26 '24 08:01 metamath1

I am also thinking about this issue! help me ! @metamath1 @kashif @stephenroller @akx @jbn

kkwhale7 avatar Apr 17 '24 11:04 kkwhale7

second this!

xyliaaaaa avatar Jul 29 '24 19:07 xyliaaaaa