DLPack only specifies a C++ API, but in practice there's a Python embedding that multiple frameworks support (via Python capsules) that does not seem to be formally specified or standardized.
The protocol seems to be:
- producers embed a
DLPackManagedTensor as Python capsule with name "dltensor".
- when a consumer consumes a
DLPackManagedTensor, it renames the capsule to "used_dltensor" so the same capsule cannot be consumed twice.
- different frameworks seem to act differently as to how a consumer should treat a capsule destructor. MXNet seems to remove the capsule destructor, but PyTorch seems to leave it alone (I may have misread the code in either of these two cases.) It would be good to clarify what the correct behavior is. For JAX, I chose to remove the capsule destructor.
DLPack only specifies a C++ API, but in practice there's a Python embedding that multiple frameworks support (via Python capsules) that does not seem to be formally specified or standardized.
The protocol seems to be:
DLPackManagedTensoras Python capsule with name"dltensor".DLPackManagedTensor, it renames the capsule to"used_dltensor"so the same capsule cannot be consumed twice.