Skip to main content

pytensor_ml

A(nother) deep learning library, built on top of PyTensor.

Networks are ordinary PyTensor graphs. You build one out of layers, and everything PyTensor already does — symbolic differentiation, graph rewrites, and compilation to Numba, C, JAX, PyTorch, or MLX — applies to it unchanged. Training is a compiled function that takes a batch and returns a loss; there is no separate runtime or tape.

That goes all the way down: layers are graph constructors, parameters are shared variables, and a training step is a compiled function whose updates are the optimizer. Because a model is only a graph, it composes with any other PyTensor graph — a PyMC model included — as there is nothing else to interoperate with.

Status: pre-alpha. The API is still moving, and there is no release-to-release compatibility guarantee yet.

Installation

pip install pytensor-ml

The only hard dependencies are pytensor and numpy. Saving and loading weights needs safetensors (pip install safetensors). A backend beyond the default (numba, jax, torch, mlx) is installed separately, and only loads when you actually compile against it.

Quickstart

Train a classifier on scikit-learn's digits, then run inference:

import numpy as np
import pytensor

pytensor.config.floatX = "float32"

from sklearn.datasets import load_digits

from pytensor_ml.activations import ReLU
from pytensor_ml.layers import Input, Linear, Sequential
from pytensor_ml.loss import CrossEntropy
from pytensor_ml.model import Model
from pytensor_ml.optim import adam, chain, clip_by_global_norm, cosine_schedule
from pytensor_ml.util import DataLoader

X, y = load_digits(return_X_y=True)
X = (X / 16.0).astype("float32")
y_onehot = np.eye(10, dtype="float32")[y]

X_in = Input("X_in", shape=(None, 64))
network = Sequential(
    Linear("fc1", n_in=64, n_out=128),
    ReLU(),
    Linear("logits", n_in=128, n_out=10),
)
model = Model(network(X_in)).initialize(seed=0)

rule = chain(clip_by_global_norm(1.0), adam(learning_rate=cosine_schedule(1e-3, total_steps=500)))
loss_fn = CrossEntropy(expect_onehot_labels=True, expect_logits=True, reduction="mean")
step = model.compile_train(rule, loss_fn)

loader = DataLoader(X, y_onehot, batch_size=64, random_state=0)
for _ in range(500):
    loss_value = step(*loader())

accuracy = (model.predict(X).argmax(axis=-1) == y).mean()

compile_train builds the loss against a target placeholder, differentiates it, folds in any stateful layer updates (batch norm running statistics, RNG advances, the training clock a schedule reads), and compiles a one-step function. predict compiles a separate inference pass, with dropout removed and batch norm reading its running statistics.

Documentation

The full API reference and user guide live at pytensor-ml.readthedocs.io.

For worked models end to end — training loops, convolutional and recurrent networks, transformers, saving and reloading — see the examples gallery.

Contributing

Contributions are welcome. To get set up:

pip install -e ".[dev]"
pre-commit install
pytest

Formatting and linting run through ruff under pre-commit, and mypy checks pytensor_ml/; both also run in CI. Bug reports and feature requests belong in the issue tracker.

License

Apache 2.0. See LICENSE.

Metadata

Release files for pytensor-ml 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytensor-ml 0.3.0
File Size Uploaded Provenance Actions
pytensor_ml-0.3.0.tar.gz 680.6 kB With provenance Details for pytensor_ml-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytensor-ml 0.3.0
File Interpreter ABI Platform Actions
pytensor_ml-0.3.0-py3-none-any.whl Python 3 none any Details for pytensor_ml-0.3.0-py3-none-any.whl

Total release size: 895.0 kB

Release files / pytensor_ml-0.3.0.tar.gz

Download URL pytensor_ml-0.3.0.tar.gz
Size 680.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5bbd1085e1eef52092bf7fd3ce60614a005ff9d2e106a505cd99fbc7e6923001
BLAKE2b-256 checksum
How to use checksums
8f483b86243cba545a26a3577e4bd5c2fb6d669cdf6736f851ea2efee98796be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 6, 2026.

Transparency log

Release files / pytensor_ml-0.3.0-py3-none-any.whl

Download URL pytensor_ml-0.3.0-py3-none-any.whl
Size 214.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bab5ae2bc3273ff7ec5804e60b2eee224a3b33742b271d65c11d79294769f60
BLAKE2b-256 checksum
How to use checksums
b2e0f8e7dec38972f73db1890f05db7fb63b221da8cde1f7fc90cc1988070752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 6, 2026.

Transparency log

Security for pytensor-ml 0.3.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytensor_ml-0.3.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 6, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page