Tesseract-Torch
Tesseract-Torch is a lightweight extension to Tesseract Core that wraps Tesseracts as differentiable PyTorch operations, with full support for reverse-mode and forward-mode automatic differentiation.
Read the docs | Explore the examples | Report an issue | Talk to the community | Contribute
The API of Tesseract-Torch consists of a single function, apply_tesseract(tesseract, inputs), which integrates any Tesseract into PyTorch's autograd graph:
result = apply_tesseract(my_tesseract, {"x": x_tensor})
result["y"].sum().backward() # reverse-mode AD
x_tensor.grad # gradients flow through the Tesseract
Quick start
-
Install Tesseract-Torch:
$ pip install tesseract-torch
-
Build an example Tesseract:
$ git clone https://github.com/pasteurlabs/tesseract-torch $ tesseract build tesseract-torch/examples/simple/vectoradd_torch
-
Use it as part of a PyTorch program via
apply_tesseract:import torch from tesseract_core import Tesseract from tesseract_torch import apply_tesseract # Load the Tesseract t = Tesseract.from_image("vectoradd_torch") t.serve() # Run it with PyTorch tensors x = torch.ones(1000, requires_grad=True) y = torch.ones(1000) def vector_sum(x, y): res = apply_tesseract(t, {"a": {"v": x}, "b": {"v": y}}) return res["vector_add"]["result"].sum() loss = vector_sum(x, y) loss.backward() print(x.grad) # gradients via the Tesseract's VJP endpoint # Forward-mode AD is also supported via torch.autograd.forward_ad
Sharp edges
-
Required endpoints: Using
apply_tesseractwith reverse-mode AD (.backward(),torch.autograd.grad) requires the Tesseract to define avector_jacobian_productendpoint. Forward-mode AD (torch.autograd.forward_ad) requiresjacobian_vector_product. -
Other
torch.functransforms are not supported:apply_tesseractworks with PyTorch's standard autograd API (.backward(),torch.autograd.grad,torch.autograd.forward_ad), but not withtorch.functransforms (torch.func.vjp,torch.func.jvp,torch.func.grad,torch.func.jacrev,torch.func.jacfwd). These transforms create functionalized tensors that cannot be converted to NumPy arrays, which Tesseract endpoints require. Callingapply_tesseractinside atorch.functransform will raise a clear error. -
No higher-order derivatives: a gradient taken with
create_graph=Truecan be used, but differentiating it again raises aRuntimeError, since the Tesseract'svector_jacobian_productis opaque to PyTorch. See Troubleshooting. -
torch.vmapneeds avmap_method: passvmap_method="sequential","expand_dims"or"broadcast_all"toapply_tesseractto batch it withtorch.vmap; without one,torch.vmapraises when a batched tensor reachesapply_tesseract. See Batching withtorch.vmap.
License
Tesseract-Torch is licensed under the Apache License 2.0 and is free to use, modify, and distribute (under the terms of the license).
Tesseract is a registered trademark of Pasteur Labs, Inc. and may not be used without permission.
Metadata
Release files for tesseract-torch 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tesseract_torch-0.2.0.tar.gz | 28.6 kB | With provenance | Details for tesseract_torch-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tesseract_torch-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tesseract_torch-0.2.0-py3-none-any.whl |
Total release size: 49.6 kB
Release files / tesseract_torch-0.2.0.tar.gz
| Download URL | tesseract_torch-0.2.0.tar.gz |
|---|---|
| Size | 28.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3bb1a20f89aa6cf82f26847d551e757482aafb4fdbf7488387763d10c91a4f83
|
|
BLAKE2b-256 checksum How to use checksums |
12281ecda7dfb1adafe4740e960f1a7c2f6453c4336def332dc95fc6b27ff39a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 21, 2026.
Transparency logRelease files / tesseract_torch-0.2.0-py3-none-any.whl
| Download URL | tesseract_torch-0.2.0-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
076400061882a105de27704d5a64bd03b9b028dd9ca6451ca363cf1d361533a1
|
|
BLAKE2b-256 checksum How to use checksums |
495d45779a256ced0e1c8f4032687df8dfd5514b76cd8e8f72de41855d9e5354
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 21, 2026.
Transparency logSecurity for tesseract-torch 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tesseract_torch-0.2.0.tar.gz
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 Oct 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.