Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV][FP8] Improve e4m3 decoding #43

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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: 3 additions & 3 deletions python/bitblas/quantization/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def _tir_u32_to_f4_to_f16(nbit: int, val: tir.PrimExpr, pos: tir.PrimExpr, dtype
def _tir_u8_to_f8_e4m3_to_f16(nbit: int, val: tir.PrimExpr, dtype: str):
assert nbit == 8
assert dtype == "float16"
s_f16 = (val >> tir.const(7, "int16")) << tir.const(15, "int16")
offset = tir.Select(s_f16 == 0, tir.const(8192, "int16"), tir.const(-8192, "int16"))
e_f16 = ((val << tir.const(7, "int16")) + offset)
s_f16 = (val >> tir.const(7, "uint16")) << tir.const(15, "uint16")
prefix = tir.Select(s_f16 == 0, tir.const(0x2000, "uint16"), tir.const(0xc000, "uint16"))
e_f16 = (((val & tir.const(127, "uint16")) << tir.const(7, "uint16"))) | prefix
return tir.reinterpret("float16", s_f16 | e_f16)


Expand Down
2 changes: 1 addition & 1 deletion testing/python/operators/test_general_matmul_fp8.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def map_torch_type(intype):
print("torch_ref_out", ref_out)
print("bitblas_out", bitblas_out)

torch.testing.assert_allclose(ref_out, bitblas_out, rtol=1e-2, atol=1e-2)
torch.testing.assert_close(ref_out, bitblas_out, rtol=1e-1, atol=1e-1)


# fmt: on
Expand Down
Loading