Get started¶
Quick start¶
Note
Before proceeding, make sure you have a working installation of Docker and a modern Python installation (Python 3.10+).
See also
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:
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 import torch.autograd.forward_ad as fwAD with fwAD.dual_level(): x_dual = fwAD.make_dual(x.detach(), torch.ones_like(x)) result = apply_tesseract(t, {"a": {"v": x_dual}, "b": {"v": y}}) _, tangent = fwAD.unpack_dual(result["vector_add"]["result"])
Tip
Now you’re ready to jump into our examples for ways to use Tesseract-Torch.