skillfed

hoptorch

Compatibility helpers for PyTorch higher-order operators.

hoptorch v0.1.4 87.9K downloads/30d#13,761 on PyPI1
Permissive license MIT Active released

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 hoptorch

uv

uv add hoptorch

poetry

poetry add hoptorch

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersIntended Audience :: Science/ResearchProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Software Development :: Libraries :: Python Modules

Tags

pytorch scan operator wrapperhigher-order operators pytorchtorch scan backward compatibilitypytorch autograd scanscan operator device check
pytorch-compathigher-order-ops

More Python Modules packages