Skip to main content

TPTT : Transforming Pretrained Transformers into Titans

Project description

😊 TPTT

arXiv PyPI Release Documentation HuggingFace

Transforming Pretrained Transformers into Titans

TPTT is a modular Python library designed to inject efficient linearized attention (LiZA) mechanisms-such as Memory as Gate (described in Titans)-into pretrained transformers 🤗.


Features

  • Flexible Attention Injection: Seamlessly wrap and augment standard Transformer attention layers with linearized attention variants for latent memory.
  • Support for Linear Attention: Includes implementations of DeltaNet and DeltaProduct with optional recurrent nonlinearity between chunks.
  • Modular Design: Easily extend or customize operators and integration strategies.
  • Compatibility: Designed to integrate with Hugging Face Transformers and similar PyTorch models.

[!IMPORTANT] After the injection of LiZA, the model must be fine‑tuned for alignment and obtain memory.

overview

Note: Order 2 Delta-Product has the same expressiveness as titans.

Installation and Usage

pip install tptt

Titanesque Documentation

  • TPTT-LiZA_Training:
    Instructions for training TPTT-based models with LoRA and advanced memory management.

  • TPTT_LiZA_Evaluation:
    Guide for evaluating language models with LightEval and Hugging Face Transformers.

  • TPTT_LiZA_FromScratch:
    Integrating the LinearAttention module into Pytorch deep learning projects.

Basic usage :

from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig
import tptt
from tptt import save_tptt_safetensors, get_tptt_model, load_tptt_safetensors
from torch import nn

##### Transforming into Titans (Tptt)
base_model_path = "Qwen/Qwen2.5-1.5B"
base_config = AutoConfig.from_pretrained(base_model_path)
base_model_name = "Qwen/Qwen2.5-1.5B"
tptt_config = tptt.TpttConfig(
    base_model_config=base_config,
    base_model_name= base_model_name, 
    #lora_config=lora_config,

)
model = tptt.TpttModel(config)
# manual local save
save_tptt_safetensors(model, path, name)

##### Pretrained Titans from Transformer
repo_id = "ffurfaro/Titans-Llama-3.2-1B"
model = AutoModelForCausalLM.from_pretrained(repo_id, trust_remote_code=True)

##### More custom for other Model (BERT, ViT, etc.)
model, linear_cache = get_tptt_model(model, config) # you can activate Bidirectional
model = load_tptt_safetensors(repo_or_path, model) # from saved LoRA only

##### Using LinearAttention from scratch
layers = nn.ModuleList([
    tptt.LinearAttention(hidden_dim=64, num_heads=4,)
    for _ in range(num_layers)])

Some scripts are available here


Development

  • Code is organized into modular components under the src/tptt directory.
  • Use pytest for testing and sphinx for documentation. See on this link🔥
  • Contributions and feature requests are welcome!

Requirements

  • Python 3.11+
  • PyTorch
  • einops
  • Transformers
  • Peft

See requirements.txt for the full list.


Citation

If you use TPTT in your academic work, please cite:

@article{furfaro2025tptt,
  title={TPTT: Transforming Pretrained Transformer into Titans},
  author={Furfaro, Fabien},
  journal={arXiv preprint arXiv:2506.17671},
  year={2025}
}

Contact

For questions or support, please open an issue on the GitHub repository or contact the maintainer.

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

tptt-0.11.6.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

tptt-0.11.6-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file tptt-0.11.6.tar.gz.

File metadata

  • Download URL: tptt-0.11.6.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.11 Linux/6.8.0-71-generic

File hashes

Hashes for tptt-0.11.6.tar.gz
Algorithm Hash digest
SHA256 625feb53c9fef1aea26bbeb41c2f0152d0d6a215d41546ffaf210b9511beadd1
MD5 660d35ed20b84243d14d5fd6b17de2fc
BLAKE2b-256 a2e4a1b0eb61cc5b8cb3a1643713c619cb88765fa9a6ed52b001db8a5f737b69

See more details on using hashes here.

File details

Details for the file tptt-0.11.6-py3-none-any.whl.

File metadata

  • Download URL: tptt-0.11.6-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.11 Linux/6.8.0-71-generic

File hashes

Hashes for tptt-0.11.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4e1072df3e04eb60a7baf3d26bc19824c8418cfddee2b56778a79f95d13c3f5c
MD5 164a57a24082062eafdd3980c87fa028
BLAKE2b-256 6e4634db38037b68c9cfb78bdb9f5106b533fa78844b462a7ee8f0f8241dfe75

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