--- id: hoptorch version: "0.1.4" license: MIT license_treatment: permissive maintenance: active --- # hoptorch — Compatibility helpers for PyTorch higher-order operators. License: permissive · Maintenance: active · Downloads: 87.9K/mo ## 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 above — 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 pip install hoptorch uv add hoptorch 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_current - Install friction: low - Maintenance: active - Downloads: 87.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pytorch scan operator wrapper, higher-order operators pytorch, torch scan backward compatibility, pytorch autograd scan, scan operator device check, pytorch-compat, higher-order-ops [View on SkillFed](https://skillfed.io/packages/hoptorch) · [View on PyPI](https://pypi.org/project/hoptorch/)