Skip to main content

Trama

Trama is a standalone Python library that defines a JSON schema, validator, and export/import framework for hierarchical model graphs in Static Single Assignment (SSA) style. It is framework-agnostic and is designed to be used by domain-specific modeling libraries that inject their own op registries. Models are serialized to self-contained .trama.json files capturing both topology and parameter values, and can be reconstructed back into runtime modules via registered factory functions.

Installation

# With pip:
pip install trama

# Or with uv:
uv add trama

Quick-start

import trama

# Export a module that implements ExportableOp + ImportableOp.
model = trama.export_model(module, inputs=["x"], outputs=["y"], registry=registry)

# Serialize to JSON and save.
trama.dump(model, "my_model.trama.json")

# Later: load and reconstruct the runtime module.
model = trama.load("my_model.trama.json")
instance = trama.import_model(model, registry=registry)

JSON Schema

Trama exposes a JSON Schema for .trama.json files. Generate it with the tramaschema command:

tramaschema > trama.schema.json

The schema validates format structure: required fields, field types, and identifier patterns. Registry conformance — whether op names resolve and parameter types match — is not expressible in JSON Schema and is enforced at load time in Python by trama.load() or trama.validate().

Example

{
  "format_version": "0.2",
  "inputs": ["x"],
  "outputs": [{ "node": "root", "output": "y" }],
  "nodes": [
    {
      "id": "root", "parent": null, "op": "Sequential",
      "inputs": { "x": { "node": "%input", "output": "x" } },
      "outputs": ["y"],
      "parameters": {},
      "output_bindings": { "y": { "node": "root.linear_1", "output": "y" } }
    },
    {
      "id": "root.linear_0", "parent": "root", "op": "Linear",
      "inputs": { "x": { "node": "%input", "output": "x" } },
      "outputs": ["y"],
      "parameters": {
        "in_features":  { "name": "root.linear_0.in_features" },
        "out_features": { "name": "root.linear_0.out_features" },
        "weight":       { "name": "root.linear_0.weight" }
      },
      "output_bindings": null
    },
    {
      "id": "root.linear_1", "parent": "root", "op": "Linear",
      "inputs": { "x": { "node": "root.linear_0", "output": "y" } },
      "outputs": ["y"],
      "parameters": {
        "in_features":  { "name": "root.linear_0.out_features" },
        "out_features": { "name": "root.linear_1.out_features" },
        "weight":       { "name": "root.linear_1.weight" }
      },
      "output_bindings": null
    }
  ],
  "parameters": {
    "root.linear_0.in_features":  { "value": 8,  "learnable": false },
    "root.linear_0.out_features": { "value": 16, "learnable": false },
    "root.linear_1.out_features": { "value": 4,  "learnable": false },
    "root.linear_0.weight": { "value": { "dtype": "float32", "shape": [16, 8],  "data": "..." }, "learnable": true },
    "root.linear_1.weight": { "value": { "dtype": "float32", "shape": [4,  16], "data": "..." }, "learnable": true }
  }
}

Note that root.linear_0.out_features is referenced by both root.linear_0 and root.linear_1 (the dimension is the same physical value). This is the parameter sharing mechanism: a single entry in the table, multiple refs.

The trama format is inspired by SSA form from compiler design. The tramassa command prints any .trama.json file in this human-readable form:

# trama SSA  (format 0.2)

model(x) -> %root.y

params
  root.linear_0.in_features   : int         = 8
  root.linear_0.out_features  : int         = 16
  root.linear_1.out_features  : int         = 4
  root.linear_0.weight        : f32[16, 8]  learnable
  root.linear_1.weight        : f32[4, 16]  learnable

scope root [Sequential]
  y = %root.linear_1.y

%root.linear_0.y = Linear(
    x            = x,
    in_features  = root.linear_0.in_features,
    out_features = root.linear_0.out_features,
    weight       = root.linear_0.weight
)

%root.linear_1.y = Linear(
    x            = %root.linear_0.y,
    in_features  = root.linear_0.out_features,
    out_features = root.linear_1.out_features,
    weight       = root.linear_1.weight
)

Design

For detailed description of the design of Trama please see the design document.

Compared to other model export formats

Trama operates at a fundamentally different abstraction level than ONNX, torch.export, and similar formats. Those tools target deployment: they decompose user-authored modules into low-level tensor operations (aten.matmul, aten.conv2d, ONNX Gemm) so a runtime can execute them efficiently. The user's Sequential(Encoder(), Decoder()) becomes a flat sequence of primitive ops with the original module boundaries dissolved. Trama instead targets composition: it preserves the user-authored module hierarchy as first-class structure, captures only the wiring between the building blocks the consumer library defines, and treats those blocks as opaque ops whose semantics live in the registry. This makes trama files dramatically smaller and more readable than ONNX graphs of equivalent models, diffable in code review, and meaningful to humans inspecting "what does this model architecture actually look like" — at the cost of being unsuitable for cross-framework deployment, since the ops are defined by the consumer library rather than a standardized vocabulary. Trama is complementary to ONNX, not a replacement: a natural pipeline is to author and review models in trama, then lower to ONNX or torch.export when shipping to inference.

Metadata

Release files for trama 0.2.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 trama 0.2.0
File Size Uploaded
trama-0.2.0.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trama 0.2.0
File Interpreter ABI Platform
trama-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.2 kB

Release files / trama-0.2.0.tar.gz

Download URL trama-0.2.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ce882fc3cb96b77d4c2e0c25adddc35b91ff5c237b042452b3cb73fa344de7cf
BLAKE2b-256 checksum
How to use checksums
ccd217d96cd320f533699a86fd2d19ee63df8339235a1b9fcd4fef03c944c16d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / trama-0.2.0-py3-none-any.whl

Download URL trama-0.2.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11b8e444a2a025a8c521167b5439bbb7ba078d861600c822b19104c9ebbac031
BLAKE2b-256 checksum
How to use checksums
d6834d9477cb6a63e1cc033e4e3ee4cfe9d2ca47f16c6956902cbca698efe5d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release 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