Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redformer

A transformer-based language model with hierarchical memory architecture for unlimited context.

Architecture

Redformer implements a novel multi-level memory system that enables processing arbitrarily long sequences:

  • Hierarchical Memory: 15 levels of memory (2^0, 2^1, ..., 2^14 tokens) for efficient long-range context
  • TwoPacker: Geometric algebra-based operations for memory compression
  • Reducer: Attention-based memory reduction across levels
  • Memory Persistence: Memory state carries across sequences for continuous learning

Installation

pip install -r requirements.txt

Training

Train the model using trainer2.py:

python trainer2.py

The trainer uses Hugging Face Accelerate for distributed training with mixed precision (bfloat16). Models are saved to ~/ReD2B/ by default.

Training Details:

  • Memory updates happen after optimization step (not in forward pass) to prevent double-updates with gradient checkpointing
  • Supports streaming datasets for large-scale pretraining
  • Automatic checkpointing every 1000 steps

Chat Demo

Run the interactive chat interface:

python demo_chat.py

Features:

  • Streaming token generation
  • Loss display showing model "surprise"
  • Multi-line input support (Alt-Enter or Ctrl-J)
  • Persistent memory across conversation turns

Model Storage (rocli)

Manage model checkpoints with Google Cloud Storage:

# list
./rocli list
# Upload local model to GCS
./rocli upload ~/ReD2B/

# List stored models
./rocli list

# Download model from GCS
./rocli download ReD2B ~/

# Delete stored model
./rocli delete Red2B

The CLI provides a lightweight interface for syncing large model files to cloud storage without external dependencies.

Model Components

  • modelling/model.py - Core model and memory wrapper
  • modelling/layer.py - Layer architecture with hierarchical memory
  • modelling/twopack.py - Geometric packing operations
  • modelling/reducer.py - Attention-based reduction
  • modelling/config.py - Model configuration

Configuration

Default config (2.8B parameters + memory):

hidden_size = 2816
num_packer_heads = 256
num_reducer_heads = 128
num_layers = 8
memory_levels = 15

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages