Fixup platform FP8 data type query
Browse files
torch-ext/quantization/compressed_tensors.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
-
from typing import Optional,
|
| 2 |
|
| 3 |
import torch
|
| 4 |
|
| 5 |
from ._ops import ops
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# fp8
|
| 8 |
def scaled_fp8_quant(
|
|
|
|
| 1 |
+
from typing import Optional, Union
|
| 2 |
|
| 3 |
import torch
|
| 4 |
|
| 5 |
from ._ops import ops
|
| 6 |
+
from .platforms import current_platform
|
| 7 |
+
|
| 8 |
|
| 9 |
# fp8
|
| 10 |
def scaled_fp8_quant(
|
torch-ext/quantization/platforms.py
CHANGED
|
@@ -27,6 +27,29 @@ class DeviceCapability(NamedTuple):
|
|
| 27 |
class Platform(ABC):
|
| 28 |
simple_compile_backend: str = "inductor"
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@classmethod
|
| 31 |
@abstractmethod
|
| 32 |
def get_device_name(cls, device_id: int = 0) -> str: ...
|
|
@@ -51,6 +74,18 @@ class CudaPlatform(Platform):
|
|
| 51 |
|
| 52 |
|
| 53 |
class RocmPlatform(Platform):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
@classmethod
|
| 55 |
@lru_cache(maxsize=8)
|
| 56 |
def get_device_capability(cls, device_id: int = 0) -> DeviceCapability:
|
|
|
|
| 27 |
class Platform(ABC):
|
| 28 |
simple_compile_backend: str = "inductor"
|
| 29 |
|
| 30 |
+
@classmethod
|
| 31 |
+
def fp8_dtype(cls) -> torch.dtype:
|
| 32 |
+
"""
|
| 33 |
+
Returns the preferred FP8 type on the current platform.
|
| 34 |
+
|
| 35 |
+
See the documentation for is_fp8_fnuz for details.
|
| 36 |
+
"""
|
| 37 |
+
return torch.float8_e4m3fn
|
| 38 |
+
|
| 39 |
+
@classmethod
|
| 40 |
+
def is_fp8_fnuz(cls) -> bool:
|
| 41 |
+
"""
|
| 42 |
+
Returns whether the preferred FP8 type is FNUZ on the current platform.
|
| 43 |
+
|
| 44 |
+
There are two representations of FP8, OCP FP8 and FNUZ FP8.
|
| 45 |
+
The OCP specification can be found at https://tinyurl.com/b7jvwpft.
|
| 46 |
+
The FNUZ specification can be found at https://tinyurl.com/5n6hwwu5.
|
| 47 |
+
|
| 48 |
+
AMD's MI300 and MI325 have native hardware support for FNUZ. All other
|
| 49 |
+
hardware has converged on the OCP FP8 standard.
|
| 50 |
+
"""
|
| 51 |
+
return False
|
| 52 |
+
|
| 53 |
@classmethod
|
| 54 |
@abstractmethod
|
| 55 |
def get_device_name(cls, device_id: int = 0) -> str: ...
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
class RocmPlatform(Platform):
|
| 77 |
+
@classmethod
|
| 78 |
+
def fp8_dtype(cls) -> torch.dtype:
|
| 79 |
+
if cls.is_fp8_fnuz():
|
| 80 |
+
return torch.float8_e4m3fnuz
|
| 81 |
+
else:
|
| 82 |
+
return torch.float8_e4m3fn
|
| 83 |
+
|
| 84 |
+
@classmethod
|
| 85 |
+
def is_fp8_fnuz(cls) -> bool:
|
| 86 |
+
# only device 0 is checked, this assumes MI300 platforms are homogeneous
|
| 87 |
+
return "gfx94" in torch.cuda.get_device_properties(0).gcnArchName
|
| 88 |
+
|
| 89 |
@classmethod
|
| 90 |
@lru_cache(maxsize=8)
|
| 91 |
def get_device_capability(cls, device_id: int = 0) -> DeviceCapability:
|