Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Taktiny

Taktiny modules are Python objects registered as JAX PyTrees. The library does not assume a particular model architecture or dataset format, and its components can be used independently.

The project is experimental and APIs may change.

Quickstart · Guides · API reference

What’s included

  • Models: Module and Parameter, linear and convolutional layers, embeddings, normalization, recurrent layers, attention, and other neural network components.
  • Data: Grain-backed data loading, transforms, batching, and packing for caller-provided records.
  • Training: An Optax-based trainer with evaluation, callbacks, gradient accumulation, and Orbax checkpoints.
  • Sharding: Partition specifications and logical axis mappings for JAX device meshes.
  • Adapters: LoRA, DoRA, AdaLoRA, LoHa, LoKr, and VeRA.
  • Quantization: Quantization utilities backed by Qwix.

The data, training, and model APIs can also be used separately with existing JAX code.

Installation

Taktiny requires Python 3.12+ and JAX 0.10.2+.

Install with uv:

uv add git+https://github.com/solitariusai/taktiny.git@experiment

Or with pip:

pip install git+https://github.com/solitariusai/taktiny.git@experiment

Define a model

Modules hold their parameters directly and are registered as JAX PyTrees.

import jax
import jax.numpy as jnp
from taktiny import nn


class MLP(nn.Module):
    def __init__(self, *, rngs: nn.Rngs):
        self.hidden = nn.Linear(8, 32, rngs=rngs)
        self.output = nn.Linear(32, 1, rngs=rngs)

    def __call__(self, x):
        return self.output(jax.nn.silu(self.hidden(x)))


model = MLP(rngs=nn.Rngs(0))

jit_model = jax.jit(model)
output = jit_model(jnp.ones((4, 8)))

assert output.shape == (4, 1)

Passing the model as an argument to a compiled function makes its parameters part of the function inputs rather than capturing them in a closure.

Prepare data and train

The following example trains the model above on in-memory records.

import numpy as np
import optax

from taktiny.data import DataLoader
from taktiny.trainer import DatasetConfig, Trainer, TrainingConfig


inputs = np.random.default_rng(0).normal(size=(32, 8)).astype(np.float32)
records = [{"x": x, "y": x.sum(keepdims=True)} for x in inputs]

loader = DataLoader(
    records,
    batch_size=8,
    shuffle=True,
    seed=0,
    num_epochs=None,
)


def loss_fn(model, batch):
    return jnp.mean((model(batch["x"]) - batch["y"]) ** 2)


trainer = Trainer(
    model=model,
    loss_fn=loss_fn,
    training_config=TrainingConfig(
        max_steps=20,
        optimizer=optax.adam(1e-3),
        log_interval=10,
    ),
    dataset_config=DatasetConfig(
        train_dataloader=loader,
    ),
)

trainer.train()

assert trainer.global_step == 20

Trainer accepts iterables of batches. Checkpointing is optional.

See the trainer guide for evaluation, saving, and resuming.

Apply an adapter

Adapters can be applied to matching module paths.

from taktiny.takt import LoRAAdapter, Takt


adapted = MLP(rngs=nn.Rngs(1))

adapted = Takt.apply_adapter(
    adapted,
    LoRAAdapter(
        targets="hidden",
        rank=4,
        alpha=8,
        rngs=nn.Rngs(2),
    ),
)

assert adapted(jnp.ones((4, 8))).shape == (4, 1)

targets accepts module-path regex patterns. Applying an adapter freezes existing parameters and adds trainable adapter parameters.

See the PEFT guide.

Documentation

Development

Run the test suite on CPU:

make test

Project layout:

src/taktiny/
├── nn/        Modules, layers, parameters, and RNG utilities
├── data/      Loading and preprocessing
├── takt/      Adapter injection
├── trainer/   Training, evaluation, callbacks, and checkpoints
└── utils/     Sharding, transforms, quantization, and typing

License

Taktiny is distributed under the Apache License 2.0. See LICENSE.md.

Download files

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

Source Distribution

taktiny-0.0.1rc1.tar.gz (637.2 kB view details)

Uploaded Source

Built Distribution

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

taktiny-0.0.1rc1-py3-none-any.whl (167.0 kB view details)

Uploaded Python 3

File details

Details for the file taktiny-0.0.1rc1.tar.gz.

File metadata

  • Download URL: taktiny-0.0.1rc1.tar.gz
  • Upload date:
  • Size: 637.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for taktiny-0.0.1rc1.tar.gz
Algorithm Hash digest
SHA256 9acbfecf6f7dfb6fc2ce7b445b27ded45566dd0f338851352ca6bbeb0b0ef8e4
MD5 1355a1b3105d6c7bb327bfe452148d7a
BLAKE2b-256 634b70b1506587510bda2a5de1264b6db1f9da81e1b1268b6715d593769c2310

See more details on using hashes here.

Provenance

The following attestation bundles were made for taktiny-0.0.1rc1.tar.gz:

Publisher: publish.yml on solitariusai/taktiny

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

File details

Details for the file taktiny-0.0.1rc1-py3-none-any.whl.

File metadata

  • Download URL: taktiny-0.0.1rc1-py3-none-any.whl
  • Upload date:
  • Size: 167.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for taktiny-0.0.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 69d424d89d806c52395342627c487850ab85b35d65ee2d6097ab3f006fb6c259
MD5 1cc5f0948d2772377c2fa3c8eef6ebb8
BLAKE2b-256 1663f86001d71970b086a5cac69153373a51d8a2348ba840cfdc1394b7729a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for taktiny-0.0.1rc1-py3-none-any.whl:

Publisher: publish.yml on solitariusai/taktiny

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

Release history Release notifications | RSS feed

This release

0.0.1rc1 This release

2 files

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