Compatibility helpers for PyTorch higher-order operators.
Project description
hoptorch
hoptorch is a small compatibility package for PyTorch higher-order operators.
Its first helper is a safe wrapper around torch._higher_order_ops.scan that
checks whether scan backward is healthy on the requested device and lazily
installs version-specific compatibility patches for affected PyTorch internals.
For PyTorch 2.7, where scan backward is not implemented, hoptorch backports
a small eager scan implementation with ordinary autograd support.
Install
pip install hoptorch
Runtime dependency:
torch>=2.7
pyvers>=0.2.2
Usage
import torch
from hoptorch import scan
from hoptorch.scan import ensure_scan_backward, scan_unavailable_reason
if ensure_scan_backward("cpu"):
xs = torch.arange(4.0)
def step(carry, x):
next_carry = carry + x
return next_carry, next_carry.clone()
carry, ys = scan(step, torch.zeros(()), xs)
else:
print(scan_unavailable_reason("cpu"))
For compiled code, warm the health check before entering torch.compile:
from hoptorch.scan import ensure_scan_backward
ensure_scan_backward("cpu")
compiled_fn = torch.compile(fn)
If a wrapper call happens during Dynamo tracing before the health result is
cached, hoptorch fails closed instead of tracing the probe.
Public API
from hoptorch import scan
from hoptorch.scan import (
ensure_scan_backward,
has_scan,
patch_scan_backward,
scan_unavailable_reason,
)
scan(fn, init, xs, *, dim=0, **kwargs): calls PyTorch scan only when scan backward is known to be healthy for the inferred device.has_scan(): reports whethertorch._higher_order_ops.scan.scanexists.ensure_scan_backward(device=None): runs or reads the cached health check, patching lazily if needed, and returnsTrueonly after a passing probe.scan_unavailable_reason(device=None): returnsNonewhen scan backward is usable, otherwise a stable human-readable reason.patch_scan_backward(): attempts to install the compatibility patch and is intended mainly for diagnostics.
Tests
python -m unittest discover -s tests
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hoptorch-0.1.0.tar.gz.
File metadata
- Download URL: hoptorch-0.1.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0361f4ce9c4db88536c875a965358e0211d0ef6aff654564b248fee618b3191
|
|
| MD5 |
241770d1ac0f566dd3f6ee8eddeb5b47
|
|
| BLAKE2b-256 |
71bbd982f6f7560f59db627c1ced9d21db4e075ae21daacc783c6ffc318ccf74
|
Provenance
The following attestation bundles were made for hoptorch-0.1.0.tar.gz:
Publisher:
publish.yml on vmoens/hoptorch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hoptorch-0.1.0.tar.gz -
Subject digest:
b0361f4ce9c4db88536c875a965358e0211d0ef6aff654564b248fee618b3191 - Sigstore transparency entry: 1704587762
- Sigstore integration time:
-
Permalink:
vmoens/hoptorch@14e37a9260278a22c75dfe141a00631ac226e9b1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vmoens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14e37a9260278a22c75dfe141a00631ac226e9b1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hoptorch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hoptorch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22819c617d9b9e638af17e587448a40486a7f8cf78f3ef99f0a4519c2a44f443
|
|
| MD5 |
555d360234520b7c3f8f08072549eae2
|
|
| BLAKE2b-256 |
606636074e7800d3676c4b62c20f4debef3e9b0600f6e8eb118eeafb06580a7e
|
Provenance
The following attestation bundles were made for hoptorch-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on vmoens/hoptorch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hoptorch-0.1.0-py3-none-any.whl -
Subject digest:
22819c617d9b9e638af17e587448a40486a7f8cf78f3ef99f0a4519c2a44f443 - Sigstore transparency entry: 1704587771
- Sigstore integration time:
-
Permalink:
vmoens/hoptorch@14e37a9260278a22c75dfe141a00631ac226e9b1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vmoens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14e37a9260278a22c75dfe141a00631ac226e9b1 -
Trigger Event:
push
-
Statement type: