Repository navigation
[PyBindings] Pass float8 tensors through DLPack - #25098
shoumikhin wants to merge 1 commit into
Conversation
The pybindings' DLPack tables had no float8 types. A float8 value handed to a method through DLPack was refused. A float8 weight uploaded with from_host(..., dtype="float8_e4m3fn") failed with "ExecuTorch result dtype cannot be represented by DLPack". A raw DLPack capsule, or a wrapper with only __dlpack__, of a CPU torch float8 tensor failed with "Unsupported DLPack dtype". A float8 output could not be read through DLPack either, so torch.from_dlpack() refused a float8 ExecuTorchResult. DLPack 1.1 added type codes for the float8 formats. The pybindings now map Float8_e4m3fn, Float8_e4m3fnuz, Float8_e5m2 and Float8_e5m2fnuz to and from those codes, with 8 bits and 1 lane, the same codes PyTorch uses. Because the codes are from DLPack 1.1, the capsules the pybindings export now say version 1.1, and the pybindings ask producers for up to version 1.1. Both sides still accept any 1.x version. The README now says float8 results keep their dtype through DLPack, as bfloat16 results do, and how to pass a float8 input. Tests: - test_float8_dlpack_input runs float8_e4m3fn and float8_e5m2 tensors through an identity method on the CPU, given as a wrapper with only __dlpack__, a legacy capsule and a versioned capsule. It also checks that the fnuz dtypes are read as themselves from a versioned capsule: the method refuses them with their own dtype names, since exir cannot export them. - test_float8_result_round_trips_through_dlpack gets ExecuTorchResult outputs on the CPU (EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT=executorch), reads them with torch.from_dlpack, and passes them back into the method. - test_float8_host_bits_run_through_a_method uploads bits of all four float8 dtypes to CUDA with from_host and checks the dtype torch reads. It runs float8_e4m3fn and float8_e5m2 through a method, since exir cannot export the fnuz dtypes. - In test_pybindings_no_aten.py, the importer test now expects a request for up to version 1.1, and the DLPack export test checks that an exported capsule says version 1.1.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25098
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 03e3acb with merge base b3b565b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review effort=max |
|
Claude finished @shoumikhin's task in 18m 8s —— View job Nothing blocks this PR, but there are four minor problems: CPU CI never runs the new float8 export entries, the fnuz codes are not tested anywhere, the DLPack capsules are still labelled 1.0 although they can now carry 1.1 dtype codes, and the README still describes DLPack dtype round-trips for bfloat16 only. PR Review: #25098 (details)SummaryThe PR maps
All five changed files were reviewed. I could not run torch here, so the remarks about how peer libraries treat the version come from the DLPack spec, not from a run. API Design
Testing
Specific Comments
RecommendationApprove. None of these blocks merging. The CPU |
7d4d97a to
0191a01
Compare
|
@claude review effort=max |
|
Claude finished @shoumikhin's task in 18m 27s —— View job Nothing blocks this PR. The new float8 input test never reads a versioned capsule or a fnuz code, the README doesn't say how to pass a float8 input, and there are a few minor code-quality and wording points. PR Review: #25098 (details)SummaryThe PR maps
All 7 changed files were reviewed. This job can't run Python, so every finding comes from reading the code. API Design
Testing
Code Quality
Specific Comments
RecommendationApprove. Nothing here blocks merging. The two test cases are the most useful additions, and each takes only a few lines. |
0191a01 to
03e3acb
Compare
|
@claude review effort=max |
|
Claude finished @shoumikhin's task in 25m 49s —— View job Nothing blocks this float8 DLPack change; three minor points remain: the no-ATen version check asks for 1.1, so it can't tell an unconditional 1.1 label from an echoed request; the new subprocess test brings back a dynamic PR Review: #25098SummaryThe PR maps the DLPack 1.1 float8 codes (10–13) to the four float8 dtypes on import and export. It also labels versioned capsules 1.1 and asks producers for Testing
Code Quality
Specific Comments
RecommendationApprove Nothing blocks merging. The points above are minor fixes to tests and comments. |
The pybindings' DLPack tables have no float8 types, so a float8 tensor cannot be passed to a method through DLPack, and a float8 output cannot be read through it. For example:
ExecuTorchResult.from_host(bits, 0, dtype="float8_e4m3fn")cannot be passed to a method: the call fails with "ExecuTorch result dtype cannot be represented by DLPack".torch.from_dlpack()refuses a float8ExecuTorchResultoutput with the same error.__dlpack__, is refused with "Unsupported DLPack dtype".A plain torch tensor is not affected, because the bindings read it without DLPack.
DLPack 1.1 added codes for the float8 formats. This change maps Float8_e4m3fn, Float8_e4m3fnuz, Float8_e5m2 and Float8_e5m2fnuz to and from them, with the same codes PyTorch uses. Because these codes are from DLPack 1.1, the capsules the bindings export now say version 1.1, and the bindings ask producers for up to version 1.1. Both sides still accept any 1.x capsule. The README now says that float8 results keep their dtype through DLPack, and how to pass a float8 input.
Tested:
__dlpack__, as a legacy capsule and as a versioned capsule. It also passes the fnuz dtypes as versioned capsules and checks that they are read as themselves.EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT=executorchreads float8ExecuTorchResultoutputs withtorch.from_dlpackand passes them back into the method.from_host, checks the dtype torch reads, and runs float8_e4m3fn and float8_e5m2 through a method.All of these fail without the change and pass with it. The existing CUDA DLPack tests still pass on an H100, and torch 2.14 and newer read the version 1.1 capsules.