hoptorch
Compatibility helpers for PyTorch higher-order operators.
What it is and what it does
hoptorch is a thin compatibility layer for PyTorch's scan operator, which is part of PyTorch's higher-order operator suite. It wraps torch._higher_order_ops.scan with a health check that verifies scan backward is working on your device before you use it, then lazily applies version-specific patches to PyTorch internals if needed. For PyTorch 2.7, where scan backward is not yet implemented, hoptorch provides a small eager scan implementation that uses ordinary autograd instead.
The package is designed to let you write scan code once and have it work reliably across PyTorch versions and devices. It includes utilities to check whether scan is available, to warm the health check before torch.compile, and to inspect why scan might be unavailable on a given device. The health check fails closed during Dynamo tracing to avoid false positives.
Use it for:
- Use it to safely call torch.scan in production code without worrying about device-specific or version-specific backward failures.
- Use it to backport scan functionality to PyTorch 2.7 environments where native scan backward is not available.
- Use it to warm scan health checks before compiling functions with torch.compile to avoid tracing overhead.
- Use it to diagnose why scan backward is unavailable on a specific device or PyTorch version.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a safe wrapper around PyTorch's scan operator that checks backward compatibility across devices and PyTorch versions, with a fallback eager implementation for PyTorch 2.7.
Yes, if you need scan and want version/device safety. The low install friction, permissive license, and active maintenance make it reasonable. However, it is early-stage (Alpha) with minimal real-world usage; test thoroughly in your environment before relying on it in production.
Install
hoptorch on PyPI
pip
pip install hoptorchuv
uv add hoptorchpoetry
poetry add hoptorchInstalling hoptorch
Before you install
Low friction: pure Python wheel with only torch and pyvers as runtime dependencies. Active maintenance with recent release, though early-stage (Alpha) and minimal community adoption.
License in practice
MIT license is permissive; you can use, modify, and distribute this package with minimal restrictions.
Quickstart
pip install hoptorch
import torch
from hoptorch import scan
from hoptorch.scan import ensure_scan_backward
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)
Requires torch>=2.7 and pyvers>=0.2.2; Python >=3.10
Verify before relying
- Whether the eager scan backport for PyTorch 2.7 covers all use cases or has known limitations.
- Real-world performance overhead of the health check and lazy patching on typical scan workloads.
- Scope of PyTorch internals patched and stability across minor PyTorch releases.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — torch, pyvers |
| Maintenance | actively maintained — 70 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 87,914/month — #13,761 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: hoptorch-0.1.4-py3-none-any.whl
Keywords: pytorch, torch, scan, higher-order-operators, autograd
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
torch-einops-utilsProvides utility functions for PyTorch and…
permissive · top 15,000 on PyPI
cuequivariance-ops-torch-cu12Provides CUDA-accelerated PyTorch kernels and…
unclear · top 15,000 on PyPI
torch-npuEnables PyTorch to run computations on Huawei…
permissive · top 5,000 on PyPI
pytorchThis package is a redirect or placeholder; the…
unclear · top 15,000 on PyPI
onnx2torchConverts ONNX models to PyTorch modules with a…
permissive · top 15,000 on PyPI
torchvizGenerates visual diagrams of PyTorch neural…
permissive · top 5,000 on PyPI
depyfDecompile and inspect the internal bytecode and…
permissive · top 5,000 on PyPI
torch-directmlEnables PyTorch to use DirectML for GPU…
permissive · top 15,000 on PyPI
opt-einsum-fxOptimizes PyTorch einsum operations and…
permissive · top 15,000 on PyPI