Skip to main content

PyTorch implementation of Titans: Learning to Memorize at Test Time (Behrouz, Zhong & Mirrokni, 2024)

Project description

Getting Started with Titans-Memory (v0.2.0)

Congratulations on installing titans-memory! This package provides a high-performance, feature-rich implementation of the Titans (Learning to Memorize at Test Time) architecture.

🚀 Quick Start

import torch
from titans.utils import TitansConfig, build_model

# Initialize a small MAC model (~30M parameters)
cfg = TitansConfig.tiny(variant='MAC', vocab_size=32000)
model = build_model(cfg)

# Forward pass
input_ids = torch.randint(0, 32000, (1, 512))
output = model(input_ids)
print(output['logits'].shape)  # [1, 512, 32000]

⚡ High-Performance Features (v0.2.0)

1. Parallel Associative Scan

Process massive sequences faster than standard implementations. Our parallel_scan uses a log-depth algorithm optimized for CUDA.

from titans.ops import parallel_scan
# This is automatically used inside the model for GPU tensors

2. HuggingFace Integration

You can now use Titans models with the familiar transformers API:

from titans.utils.hf import TitansModelForCausalLM, TitansHFConfig

config = TitansHFConfig(d_model=512, n_layers=12, variant='MAC')
model = TitansModelForCausalLM(config)

# Save/Load using standard HF methods
model.save_pretrained('./my-titans-model')

3. Distributed Training (DDP)

Scale your training across multiple GPUs seamlessly:

from titans.utils.training import setup_ddp, wrap_ddp

local_rank = setup_ddp()
model = wrap_ddp(model, local_rank)

🛠 Model Variants

Variant Best For Description
MAC Long Context Memory as Context (retrieves long-term memory as a prefix)
MAG Gated Tasks Memory as a Gate (Sliding Window Attention ⊗ NeuralMemory)
MAL Sequential Memory as a Layer
LMM Efficiency Standalone neural memory without attention

📜 Citation

If you use this implementation in your research:

@article{behrouz2024titans,
  title   = {Titans: Learning to Memorize at Test Time},
  author  = {Ali Behrouz, Peilin Zhong, Vahab Mirrokni},
  year    = {2024}
}

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

titans_memory-0.3.0.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

titans_memory-0.3.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file titans_memory-0.3.0.tar.gz.

File metadata

  • Download URL: titans_memory-0.3.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for titans_memory-0.3.0.tar.gz
Algorithm Hash digest
SHA256 dea3bbcbf7cc63c0adb0ef56186abb437eb0a738e2ebdb31debaf402b5068eec
MD5 7098a39da3fdaa61d8c4c9f7f07e3323
BLAKE2b-256 fc0d2b5d13a545c2d288356149ae9df42a4426d8bb8ea82fe68865a411e096e2

See more details on using hashes here.

File details

Details for the file titans_memory-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: titans_memory-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for titans_memory-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95c8d8cd82dd2baf4c4d5b69ad6809637fc3dbf9ca835e0a2cfe6dedbae80dc5
MD5 763d246f42e031c12c486658a16d900e
BLAKE2b-256 afce38ca2469f79e58efb4d1360e569d85adf616d1bee50131152106f11bf944

See more details on using hashes here.

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