Registry / ai-ml / torch-c-dlpack-ext

torch-c-dlpack-ext

JSON →
library0.1.5pypypi✓ verified 25d ago

An internal PyTorch C Extension that facilitates interoperability between PyTorch tensors and C/C++ libraries via DLPack. It is not intended for direct external use by end-users, primarily serving as a utility within the PyTorch ecosystem. Version 0.1.5 is the current release, and its release cadence is tied to PyTorch's internal development.

pip install torch-c-dlpack-ext
INSTALL
IMPORT
SIG · TORCH-C-DLPACK-EXT
T
torch-c-dlpack-ext
ai-mlpythonv0.1.5
Install
74.7s avg
Import
—
Disk
5079MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.1.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
build_error
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 74.7s · import 0.000s · 4710.4MB
5079MB installed
● package 5079MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

to_dlpack, from_dlpack
✓ from torch_c_dlpack_ext import to_dlpack, from_dlpack
These are the primary functions exposed. Note that this is an internal utility and direct external usage is generally discouraged by the PyTorch project.

Demonstrates converting a PyTorch tensor to a DLPack capsule and back, showcasing the `to_dlpack` and `from_dlpack` functions. This example emphasizes that the library is an internal utility not typically used directly by end-users.

import torch # WARNING: This library is primarily an internal utility of PyTorch # and is not intended for direct use by external users. The API may change # without warning and may not follow semantic versioning for external consumption. try: from torch_c_dlpack_ext import to_dlpack, from_dlpack except ImportError: print("ERROR: torch-c-dlpack-ext not installed or failed to import.") print("This library is an internal utility and not meant for direct use.") print("Please ensure 'torch' is also installed.") exit(1) print("Successfully imported torch_c_dlpack_ext (internal utility).") # 1. Create a PyTorch tensor tensor_orig = torch.randn(2, 3) print(f"\nOriginal PyTorch Tensor:\n{tensor_orig}") # 2. Convert to DLPack capsule dlpack_capsule = to_dlpack(tensor_orig) print(f"\nDLPack Capsule (type): {type(dlpack_capsule)}") # 3. Convert back to a PyTorch tensor tensor_restored = from_dlpack(dlpack_capsule) print(f"\nRestored PyTorch Tensor (from DLPack):\n{tensor_restored}") # 4. Verify data (DLPack shares underlying memory, so data should be identical) print(f"\nAre restored and original tensor data close? {torch.allclose(tensor_orig, tensor_restored)}") print(f"Are restored and original tensors the exact same Python object? {tensor_orig is tensor_restored}") # Expected output for last line: False, as 'from_dlpack' creates a new Python Tensor object # sharing the same underlying data.
Debug
Known issues
gotchaThis library is primarily an internal utility of PyTorch and is not intended for direct use by external users. Its API may change without warning, and it may not follow standard semantic versioning conventions for external consumption.
fix
Avoid direct dependency if possible; rely on PyTorch's internal use of this library. If direct usage is necessary, pin versions strictly and be prepared for breaking changes.
affects: All versions
gotchaFunctionality heavily relies on PyTorch being installed. Ensure `torch` is available in your environment, as it's a peer dependency not explicitly listed in `install_requires`.
fix
Ensure `pip install torch` (or `conda install pytorch`) is executed in your environment before using this library.
affects: All versions
gotchaThe `to_dlpack` and `from_dlpack` functions are designed to operate on `torch.Tensor` objects. Passing objects of other types will result in runtime errors, often from the underlying C extension.
fix
Always ensure you are passing `torch.Tensor` instances to `to_dlpack` and a DLPack capsule object (returned by `to_dlpack`) to `from_dlpack`.
affects: All versions
Upgrade
Version history
0.1.5latest on PyPI · released Jan 12, 2026
Audit
Dependencies
torchrequiredPeer dependency; this library is a PyTorch C extension and requires PyTorch for its core functionality.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
torch-c-dlpack-ext — pip install torch-c-dlpack-ext · libregistry