]> khamidou — GitHub mirrors - safetensors.git/commit
Implement PyTorch support for float8 types (F8_E5M2 and F8_E4M3) (#404)
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>
Thu, 18 Jan 2024 12:21:01 +0000 (04:21 -0800)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2024 12:21:01 +0000 (13:21 +0100)
commite19f55e4bf2e7576eb24447bccfab893759bf263
treeeb930f90425c710c4329f85ab7d58f211e16abc1
parent1a40a2df6a8016c747dd4a3438feec4ca54753ed
Implement PyTorch support for float8 types (F8_E5M2 and F8_E4M3) (#404)

* Implement PyTorch support for float8 types (F8_E5M2 and F8_E4M3)

Note that PyTorch name for e4m3 type has an extra "fn" prefix to match
MLIR, but the format should be the same ("fn" means "finite").

We also test that -0.5 roundtrips in both formats, which makes sure that
the format is preserved properly - both types are single-byte and have
the same representation for zero, but different representations for
-0.5.

* Transparently support PyTorch before 2.1 by ignoring float8 formats
bindings/python/py_src/safetensors/torch.py
bindings/python/src/lib.rs
bindings/python/tests/test_pt_comparison.py