Tesseract Torch wraps Tesseracts as differentiable PyTorch operations, with full support for reverse-mode and forward-mode automatic differentiation.
Project description
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
[!NOTE] Before proceeding, make sure you have a working installation of Docker and a modern Python installation (Python 3.10+).
[!IMPORTANT] For more detailed installation instructions, please refer to the Tesseract Core documentation.
-
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
[!TIP] Now you're ready to jump into our examples for more ways to use Tesseract-Torch.
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. -
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.vmap). 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.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tesseract_torch-0.1.0.tar.gz.
File metadata
- Download URL: tesseract_torch-0.1.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89b6b354bdcc339f8cc1cc98634cea6d8b2ac6da8ebda3589288a0f51ad6e16d
|
|
| MD5 |
b19d8c88e4e0a5dffc8710ea862b3ce1
|
|
| BLAKE2b-256 |
91b65a99b712feaa88148c34a859caa925e31bda8b73c3784a4f5d81b5ff671d
|
Provenance
The following attestation bundles were made for tesseract_torch-0.1.0.tar.gz:
Publisher:
publish.yml on pasteurlabs/tesseract-torch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tesseract_torch-0.1.0.tar.gz -
Subject digest:
89b6b354bdcc339f8cc1cc98634cea6d8b2ac6da8ebda3589288a0f51ad6e16d - Sigstore transparency entry: 1927386374
- Sigstore integration time:
-
Permalink:
pasteurlabs/tesseract-torch@d334c4704d93a213daba06c0a1b90b3ad1581065 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pasteurlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d334c4704d93a213daba06c0a1b90b3ad1581065 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tesseract_torch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tesseract_torch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33408808e088f5168d77c85c405631155f847442a13b3606c90ac6afae705b6c
|
|
| MD5 |
072ce069350e01546def872689ae250e
|
|
| BLAKE2b-256 |
7df8302f35a3d7fdae4b9833b06036fc97eb175121fc7768582faf586905e0f6
|
Provenance
The following attestation bundles were made for tesseract_torch-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on pasteurlabs/tesseract-torch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tesseract_torch-0.1.0-py3-none-any.whl -
Subject digest:
33408808e088f5168d77c85c405631155f847442a13b3606c90ac6afae705b6c - Sigstore transparency entry: 1927386704
- Sigstore integration time:
-
Permalink:
pasteurlabs/tesseract-torch@d334c4704d93a213daba06c0a1b90b3ad1581065 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pasteurlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d334c4704d93a213daba06c0a1b90b3ad1581065 -
Trigger Event:
release
-
Statement type: