Skip to main content

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 whether torch._higher_order_ops.scan.scan exists.
  • ensure_scan_backward(device=None): runs or reads the cached health check, patching lazily if needed, and returns True only after a passing probe.
  • scan_unavailable_reason(device=None): returns None when 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

Metadata

Release files for hoptorch 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hoptorch 0.1.4
File Size Uploaded
hoptorch-0.1.4.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hoptorch 0.1.4
File Interpreter ABI Platform
hoptorch-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / hoptorch-0.1.4.tar.gz

Download URL hoptorch-0.1.4.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
958e22455460342f195c63f989543da6fcc66337b2f8fca1980454209d36d450
BLAKE2b-256 checksum
How to use checksums
5fe46b4a08168cd3c9dd804df68131e1dcd7ea9507ad78d548f63d3979a34e5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release files / hoptorch-0.1.4-py3-none-any.whl

Download URL hoptorch-0.1.4-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0b49e5a8b2370db8b47185fedaf91b3c6cf7f6e726079bb02aca6dbf8bb04f
BLAKE2b-256 checksum
How to use checksums
9743c038f118b0ce03385de7dcabfa64281e3387681f64668b1ee44f6b555cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page