Skip to main content

ML framework with tensors, autograd, NN modules, optimizers, transformers.

Project description

tiramisu

MNIST training — loss over 10 epochs

A from-scratch ML framework in C++20 — about 5,000 lines of readable, PyTorch-familiar code with a Python binding.

  • Stdlib-only compute (no Eigen, no BLAS, no PyTorch at link time)
  • Tensor, requires_grad, backward(), Module, Linear, Adam — Python and C++
  • AVX2/FMA matmul on x86, scalar fallback elsewhere
  • Optional CUDA backend for GPU training
  • End-to-end MNIST and char-level GPT examples

PyPI Python CMake on multiple platforms License: MIT

Install

pip install tiramisu-ml

Requires Python 3.10+. Wheels ship for Linux (x86_64, aarch64) and macOS (x86_64, arm64); other platforms build from sdist and need CMake + a C++20 compiler.

Quick start

import numpy as np
import tiramisu as tr

x = tr.from_numpy(np.random.randn(2, 784).astype(np.float32))
layer = tr.nn.Linear(784, 10)
print(layer.forward(x).shape())  # [2, 10]

Example: train an MLP on MNIST

Grab the MNIST IDX files into data/, then:

import numpy as np
import tiramisu as tr

def load_images(path):
    with open(path, "rb") as f:
        _, n, r, c = np.frombuffer(f.read(16), ">u4")
        return np.frombuffer(f.read(), np.uint8).reshape(n, r * c).astype(np.float32) / 255

def load_labels(path):
    with open(path, "rb") as f:
        _, n = np.frombuffer(f.read(8), ">u4")
        return np.frombuffer(f.read(), np.uint8).astype(np.float32)

X = load_images("data/train-images-idx3-ubyte")
y = load_labels("data/train-labels-idx1-ubyte")

fc1 = tr.nn.Linear(784, 128)
fc2 = tr.nn.Linear(128, 10)
opt = tr.optim.Adam(fc1.parameters() + fc2.parameters(), lr=1e-3)

for epoch in range(5):
    idx = np.random.permutation(len(X))
    for i in range(0, len(idx), 64):
        b = idx[i:i + 64]
        bx, by = tr.from_numpy(X[b]), tr.from_numpy(y[b])
        logits = fc2.forward(tr.relu(fc1.forward(bx)))
        loss = tr.nn.cross_entropy_loss(logits, by)
        opt.zero_grad(); loss.backward(); opt.step()
    print(f"epoch {epoch}: loss={float(np.asarray(loss)[0]):.4f}")

Expected: loss decreases to ~0.1 after 5 epochs, ~95%+ test accuracy.

Example: one GPT training step

import numpy as np
import tiramisu as tr

vocab, seq = 65, 8
model = tr.nn.GPT(vocab_size=vocab, d_model=32, num_heads=2, num_layers=1, max_seq_len=seq)
opt = tr.optim.Adam(model.parameters(), lr=1e-3)

tokens = tr.from_numpy((np.arange(seq) % vocab).reshape(1, seq).astype(np.float32))
logits = model.forward(tokens)  # (batch, seq, vocab)

flat_logits = tr.from_numpy(np.asarray(logits)[:, :-1, :].reshape(-1, vocab))
flat_targets = tr.from_numpy(np.asarray(tokens)[:, 1:].reshape(-1))
loss = tr.nn.cross_entropy_loss(flat_logits, flat_targets)

opt.zero_grad(); loss.backward(); opt.step()
print(f"loss={float(np.asarray(loss)[0]):.4f}")

Full training loops for both live in examples/ (C++) and examples/python/.

API

Tensor opsadd, sub, mul, div, neg, matmul, sum, mean, reshape, transpose, contiguous, relu, gelu, softmax, from_numpy, backward

Modulesnn.Linear, nn.LayerNorm, nn.GPT, nn.cross_entropy_loss

Optimizersoptim.Adam

Full binding reference in python/README.md.

Build from source

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure

CUDA: -DTIRAMISU_ENABLE_CUDA=ON. Debug builds enable ASan+UBSan by default.

Run the C++ MNIST example:

cmake --build build --target mnist && ./build/examples/mnist

Char-level GPT on Tiny Shakespeare (presets tiny, 2m, 10m; add --cuda for GPU):

cmake --build build --target train_shakespeare
./build/examples/train_shakespeare --preset tiny --epochs 3

Layout

core/       Storage, Tensor, dtype, device
ops/cpu/    Forward kernels (elementwise, reduce, matmul, normalization)
ops/cuda/   Optional CUDA kernels
autograd/   Differentiable wrappers, backward(), gradcheck
nn/         Module, Linear, GPT, LayerNorm, loss
optim/      SGD, Adam, AdamW, grad clipping, cosine LR
python/     pybind11 bindings
serialize/  GPT checkpoint save/load
examples/   hello_tiramisu, mnist, train_shakespeare

License: MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiramisu_ml-0.2.0.tar.gz (558.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl (379.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_aarch64.whl (346.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_x86_64.whl (234.4 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_arm64.whl (211.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl (379.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_aarch64.whl (347.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_x86_64.whl (234.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_arm64.whl (210.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (379.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_aarch64.whl (348.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_x86_64.whl (232.7 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_arm64.whl (210.9 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (378.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_aarch64.whl (347.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_x86_64.whl (231.1 kB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_arm64.whl (209.5 kB view details)

Uploaded CPython 3.10macOS 13.0+ ARM64

File details

Details for the file tiramisu_ml-0.2.0.tar.gz.

File metadata

  • Download URL: tiramisu_ml-0.2.0.tar.gz
  • Upload date:
  • Size: 558.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tiramisu_ml-0.2.0.tar.gz
Algorithm Hash digest
SHA256 766dc877d25576c3e59d4d8c8770ca9fcd4adc691cafccaf0dfd7b2b9e57e78f
MD5 88f2c02ceace618525c1dedd8cd8c01b
BLAKE2b-256 9f9c4734bd6fd12057c1cfce340f0784053d62a7e6a1aaa46aacd59b7d622d16

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0.tar.gz:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da1978df1301fdcf351fe2742884b73ec75d9af3ed41288a0afb6aa01eef1b61
MD5 bc6c96a7fa5cfcea9f211aacb20ba90b
BLAKE2b-256 c20ea60752fe2c58343e145db214fb3c2b7af0d138b2785e301d93aaabc003f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dadffe9585c8ae71efb165cc49d9439a42b434af009dfae41faa75cafba10863
MD5 7ea05dba2ad12496d454a5cde88e1faf
BLAKE2b-256 9f57cd53f9a880e603798915d5aeb9483dc143fcf6b9e31ecf1607504df09142

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 06632878d750ced24b9c075f71adf1775c1ad7bebf9f51e410ce23c10bb76f96
MD5 906cdf76417b6fb81f6e11588f985d4a
BLAKE2b-256 472cdabb19e8ad67abafe53a49f2e65574b2ec78e4f9fb66d6abbea36a709f9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 6cf9754569dd4f431aa0097a41afa17f1aa81c00e1c05d67aa43b3569028cccc
MD5 8c9bb65a4369a600658a937caf478137
BLAKE2b-256 77cbcb8017475dbabf72112d94eb593f10c3e5cd93b5afd3f7383385feac16db

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp313-cp313-macosx_13_0_arm64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40f0f47ee0e3291752fbc07378c4f4774abd6464965070e76586c17255c079ee
MD5 bf637cc4a02a9c02ac90a35e31b3b110
BLAKE2b-256 41025640db0d588a7b9c5d501c5d00ff5c27d5ef46b4b173be490d48f84bee53

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fa44049c1796610532dd01bc6aeda897b658b5e87baf83427444b85917d73f2d
MD5 161d4f411e514649131453413eea1a07
BLAKE2b-256 f5d17ab86570be50b494f3ed79a07face155b807f09439287d13cfc2fca1967a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 9ffd9424687a097cf583aa6f9a1fedf589f396e907c70c86abf4af6778fd3419
MD5 4691e43ae53d1cd861d8fc6f434ce6f2
BLAKE2b-256 e32f4250923a2fabbcb90f4219a8260e30aada237cc25f301bbf742650066701

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 fdf3afb61b3351fae28c4ef4b9df8c0c0d3c56557c872102423c4302912a7f85
MD5 dc2988384875bb5b966a9f5e13b08de8
BLAKE2b-256 67b32286d6431b8deb6c74283600c66fba98ae73a12f4c700bb70ba9e6b9d442

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp312-cp312-macosx_13_0_arm64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3f6562f759198647da17f67a9ace2f5cc9170f1f75db1cefba232df37c0fecde
MD5 27b9ff574e2d04e507fe3672d65b0b1b
BLAKE2b-256 928407509a4924a31ef8040f93666a404d3591a540fa5e018434e21a4fde3d2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 14fd7c6bca8784f159ea75edae61d3e48e944d68095bd95cdc632873856bb16c
MD5 1ec8d1aa29a8370eb5c894c120573b92
BLAKE2b-256 97ae7acbb1aeeb79e7ef25d201edc1cf7e8380f4e30759c0afa83b5576c86c84

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 0a880368178d7ec3ad65685726bf4b567fe6939e1029f7d58e0f1e98c0a5d3ae
MD5 ca3b72af6eabd8fbfeb99e38ab50c522
BLAKE2b-256 f22b72f0879b72eaaeba01c090d2e474f6cc8477d64a84ed97b7eb4efe67db0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 cdd2301c1b14a062d2ea3a437293076cf635c149e552aec1c936a7820f18cc08
MD5 6eaf496df83107f53975fc7db0a5a1db
BLAKE2b-256 fce241b3e266e51a2119cc786d32942456a45b37bfc9d151fde7065fd5b2a091

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp311-cp311-macosx_13_0_arm64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c846d9492d6156f3c37e3d2111e95f8a02d58710b930c5a8357f6755f9e1c045
MD5 db3bcb6ea91bd38c69999ec8cc9f6849
BLAKE2b-256 bfe5d503f8f87c87cd9dc5716c99464d305122d413940d87b770565a4a8fea72

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 22d719377bf04cb976846159def90191353fbc7e4021986fd758fb0927cae430
MD5 d5cdd5af8407ba09f5cc70df75151709
BLAKE2b-256 89fc6aa559b5a553fd36ca1021d344ce03647f72c20d13e69915c15c4a429096

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 85cd5c121a07758436e26368f44fede6baad4bd9320bda827ca9bf0abcc77a39
MD5 96e329f76452847fc689709af9e69c3e
BLAKE2b-256 1652e4a1587e8ef5df2860cad6b3be5d624a973a31362a6422848e96225fc5b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_x86_64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ad7d1a17354df42321acdb91dc9c6550e106090bf1b4bc6e7491374e9780383b
MD5 f497e36e6493c911cd5d23477140d011
BLAKE2b-256 043361396d853b2d14f2628d0ab2cae97ee3bcab165fac4ed27879108f3ee3c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiramisu_ml-0.2.0-cp310-cp310-macosx_13_0_arm64.whl:

Publisher: publish.yml on dnexdev/tiramisu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page