Skip to main content

Relational Transformer (RT)

The official implementation of the Relational Transformer (RT), an architecture for Relational Foundation Models (RFMs) that predict directly over relational databases (tables linked by foreign keys) and generalize zero-shot to new databases, tasks, and schemas.

Paper Venue Implementation
Relational Transformer: Toward Zero-Shot Foundation Models for Relational Data ICLR 2026 rt-v1
PluRel: Synthetic Data unlocks Scaling Laws for Relational Foundation Models ICML 2026 stanford-star/plurel
RT-J: Large-Scale Pretraining of Relational Transformers for Context-Efficient Predictions In progress main

Installation

Install the rt package (the model plus the native Rust data engine) from GitHub. It builds the extension from source, so you need a Rust toolchain and Python 3.12+:

pip install "git+https://github.com/stanford-star/relational-transformer.git"

Quickstart

The quickest way to try a released checkpoint is on a RelBench database already preprocessed into RT's tensor format on the Hub. The example below predicts whether an F1 driver fails to finish a race (driver-dnf) with a released RT-J checkpoint:

import os

# flex_attention's compiled kernel is CUDA-only; run it eager on CPU/MPS
os.environ.setdefault("TORCHDYNAMO_DISABLE", "1")

import torch
from huggingface_hub import snapshot_download

from rt import RelationalTransformer
from rt.eval import build_evaluator
from rt.data import get_tasks

device = (
    "cuda" if torch.cuda.is_available()
    else "mps" if torch.backends.mps.is_available()
    else "cpu"
)

# 1. download one RelBench database, already preprocessed into RT's tensor format
pre_dir = snapshot_download(
    "stanford-star/relbench-preprocessed",
    repo_type="dataset",
    allow_patterns="rel-f1/*",
)

# 2. load a pretrained checkpoint (RT-J here)
model = RelationalTransformer.from_pretrained(
    "stanford-star/rt-j/classification", device=device
).to(torch.bfloat16)
cfg = model.config

# 3. build an evaluator for one task and predict zero-shot for 5 test rows.
#    the evaluator samples each row's context from the preprocessed DB;
tasks = get_tasks(pre_dir, [("rel-f1", "driver-dnf")], ("test",),
                  embedder=cfg["embedder"])
ev = build_evaluator(
    tasks, pre_dir,
    embedder=cfg["embedder"], d_text=cfg["d_text"], device=device,
    ctx_size=128, local_ctx_size=64, bfs_width=32, prefer_latest=True,
    num_walks=10_000, walk_length=20, tokens_per_gpu=2**18,
    items_per_task=5, num_workers=0, prefetch_factor=2,
    shuffle_seed=0, context_seed=0, mmap_populate=True, vector_db_path=None,
)

# evaluate_raw yields one (task, ctx, labels, preds, n) per task
results = ev.evaluate_raw([(model, "")], [128])
_task, _ctx, _labels, out, _n = next(iter(results))
preds = torch.sigmoid(torch.tensor(out[""], dtype=torch.float32))
print("driver-dnf probability:", [round(p, 3) for p in preds.tolist()])

[!NOTE] items_per_task=5 and ctx_size=128 keep this demo quick (most of the runtime is one-time warmup). On a GPU, raise ctx_size toward RT-J's training context of 8192 (with local_ctx_size <= ctx_size) for full accuracy over the whole test split.

Bring your own database

Point RT at your own database, define a prediction task, and infer with a released checkpoint:

Development

We use pixi to manage one self-contained environment (Python, PyTorch + CUDA, Rust, and all dependencies), built on first use. There is nothing to build past pixi install: the native Rust extension is compiled as part of the project's own editable install.

git clone https://github.com/stanford-star/relational-transformer.git
cd relational-transformer
pixi run pytest                        # the test suite
pixi run python examples/train.py      # or eval.py, preprocess.py, ...

Documentation

Guide Description
Downloads Bulk-download raw data, preprocessed data, and checkpoints from HuggingFace
Preprocess Convert RelBench-format databases into RT's on-disk format
Inference Run a trained checkpoint; evaluate, engineer, tune, and ensemble contexts
Pretrain Train RT from scratch, single-GPU to multi-node
Experiments How experiments in expts/ are laid out and submitted to slurm

There is no CLI: RT is a library, and a run is a script that calls it. Copy something from examples/ and edit it — every entry point takes its arguments explicitly, so nothing is hidden in a default you did not choose.

Download files

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

Source Distribution

relational_transformer-1.8.0.tar.gz (139.6 kB view details)

Uploaded Source

Built Distributions

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

relational_transformer-1.8.0-cp311-abi3-manylinux_2_28_x86_64.whl (12.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

relational_transformer-1.8.0-cp311-abi3-macosx_11_0_arm64.whl (10.9 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file relational_transformer-1.8.0.tar.gz.

File metadata

  • Download URL: relational_transformer-1.8.0.tar.gz
  • Upload date:
  • Size: 139.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for relational_transformer-1.8.0.tar.gz
Algorithm Hash digest
SHA256 e61e72228407551c6c8fe5e118240a0ee36778c49405d7d5c6986f0508786fe2
MD5 66d22d5eeec81179450af25bc9dfdef8
BLAKE2b-256 4f42070417ee12df7ed76c86649cff7c5e1de8effc0cf8de00f0beedc841b6a3

See more details on using hashes here.

File details

Details for the file relational_transformer-1.8.0-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for relational_transformer-1.8.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 20a3e12a885a6ca9fbc2f30935650f792a70cc287130af69d9527e0225d15894
MD5 374684f24980b8387832e73d6d36b632
BLAKE2b-256 c83e11f100f14b21a3bf4ef71d13e508566edddd7ba08a67bced99ed8c37714a

See more details on using hashes here.

File details

Details for the file relational_transformer-1.8.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for relational_transformer-1.8.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a7a0df0a79c0cb79746a7b6aa5ffc3d8f5b71f500173d6120d2f5d6ed7a7992
MD5 3e2e6777d3fc01072334b518e6d064bf
BLAKE2b-256 6e6476c5e4a1bcd5239a24633a1600d141b093cb322587303349fc067137e34e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.8.0 This release

3 files

Supported by

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