-
Notifications
You must be signed in to change notification settings - Fork 137
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
[Feature Request] FP8 Support #156
Comments
yes, we shoiuld do it cc @leofang |
Thanks tq, I found a temporary solution that works for me: if arg.dtype in {torch.float8_e4m3fn, torch.float8_e4m3fnuz, torch.float8_e5m2, torch.float8_e5m2fnuz}:
return ndarray.from_dlpack(
to_dlpack_func(arg.view(torch.int8))
).view(dtype=float8_dtype_map[arg.dtype]) |
FP8 (and FP4) has become a common practice in LLM training, and in MLC-Python, we have to extend DLPack to support various FP8 types: https://github.com/mlc-ai/mlc-python/blob/0a22cf87d1888cf39dcd2f856f866c7e1d41a568/include/mlc/c_api.h#L35-L45. Regarding DLPack support, the trickiest issue of fp8/fp4 is that there are multiple different sub-types, e.g. A common standard people may refer to is |
Seems starting with pytorch type is a reasonable choice, given the available hw support here, contributions are welcomed. We can add additional type code if needed if future needs arise. |
cc @seberg @oleksandr-pavlyk @rgommers for vis, let's try to get this discussed in the array API meeting this week |
@potatomashed I am curious what you meant exactly by "full fp8 support" here, I assume you're referring to the set of additional enumerators needed for representing different fp8 subtypes? Are there things beyond this addition? |
Yep that's just a few extra fp8 subtypes. For reference, in PyTorch 2.6, the following fp8 subtypes are supported:
while ml-dtypes has some additional ones:
|
Some extra survey and thinkings: Likely these subtypes from PT are needed.
The latest blackwell microscaling seems to start to support Would be good to also discuss potential use-cases for other data types. but this could be a good initial list(along with |
MX FP training is indeed valid cases, e.g. MXFP4 or asymmetric MXFP4 https://arxiv.org/abs/2411.09909. I don't think we will have to be super over the top speculating future applications, but given the diverse set of existing subbyte dtypes, I'd love to learn DLPack maintainers' principles/rules on which dtypes to include |
as of now we focus on reasonably stablized types, mainly because the goal is to enable frameworks to exchange and also remain stable over time. Notably, MX format usually are stored in two NDArrays, e.g. |
This assumption doesn't always hold but is a good starting point |
xref: pytorch/pytorch#146414 |
It would be great to have FP8 support for converting tensors from PyTorch to DLPack. Currently, both PyTorch and TVM support FP8, but there is no direct way to convert tensors between them. Adding this support would improve interoperability and usability.
The text was updated successfully, but these errors were encountered: