Skip to content
Merged
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
add hasattr check for torch fp8 dtype
Signed-off-by: xin3he <[email protected]>
  • Loading branch information
xin3he committed Aug 23, 2024
commit 1e9d4188b259878ee825ccac901bb4b36cf99686
18 changes: 12 additions & 6 deletions neural_compressor/torch/algorithms/weight_only/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,18 @@

FLOAT_MAPPING = {"nf4": NF4, "fp4": FP4_BNB, "fp4_e2m1_bnb": FP4_BNB, "fp4_e2m1": FP4_E2M1}
INT_MAPPING = {"nf4": NF4_BIT, "fp4": FP4_BNB_BIT, "fp4_e2m1_bnb": FP4_BNB_BIT, "fp4_e2m1": FP4_E2M1_BIT}
FP8_MAPPING = {
"fp8_e5m2": torch.float8_e5m2,
"fp8_e5m2fnuz": torch.float8_e5m2fnuz,
"fp8_e4m3fn": torch.float8_e4m3fn,
"fp8_e4m3fnuz": torch.float8_e4m3fnuz,
}
if hasattr(torch, "float8_e5m2") and hasattr(torch, "float8_e4m3fn"):
FP8_MAPPING = {
"fp8_e5m2": torch.float8_e5m2,
"fp8_e4m3fn": torch.float8_e4m3fn,
}
if hasattr(torch, "float8_e5m2fnuz") and hasattr(torch, "float8_e4m3fnuz"):
FP8_MAPPING = {
"fp8_e5m2": torch.float8_e5m2,
"fp8_e4m3fn": torch.float8_e4m3fn,
"fp8_e5m2fnuz": torch.float8_e5m2fnuz,
"fp8_e4m3fnuz": torch.float8_e4m3fnuz,
}


def quantize_4bit(tensor, quantile=1.0, dtype="nf4", return_int=False, **kwargs):
Expand Down