Repository

transformer-mamba-llm-research

๐Ÿš€ Transformer-Mamba Hybrid LLM Research architectures for efficient language modeling & research. : Alternating Transformer and Mamba layers : Mixed precision, gradient scaling, an ยท License unknown ยท Install via pip ยท Maintenance unknown

License
Unknown

README

๐Ÿš€ Transformer-Mamba Hybrid LLM Research

LLM combining Transformer attention and Mamba SSM architectures for efficient language modeling & research.

โœจ Features

  • ๐Ÿง‘โ€๐Ÿ’ป Only 252 Lines of Code
  • ๐Ÿ”„ Hybrid Architecture: Alternating Transformer and Mamba layers
  • โšก Efficient Training: Mixed precision, gradient scaling, and optimized data loading
  • ๐ŸŽฏ Flexible Patterns: Configurable layer arrangements (e.g., "MMAMAMAM")
  • ๐Ÿš€ Multi-GPU Support: Automatic DataParallel for multi GPUs (only 1 tested)
  • ๐Ÿ’พ Easy Inference: Interactive chat mode and text generation

๏ธ Architecture

The model alternates between:

  • Mamba SSM: State space model with convolution and simplified parallel processing
  • Transformer: Multi-head attention with causal masking

Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Train the Model

python hybrid_llm.py

3. Run Inference

python inference.py --interactive

or

python inference.py --prompt "The future of AI is"

๐Ÿ“Š Model Configuration

  • Hidden Size: 384
  • Layers: 8 (configurable pattern)
  • Sequence Length: 512
  • Vocabulary: Auto-detected from tokenizer
  • Parameters: ~2.5M (configurable)

๐ŸŽฎ Usage Examples

Interactive Chat

python inference.py --model model.pt --interactive

Text Generation

python inference.py --model model.pt --prompt "The future of AI is"

๐Ÿ“ Project Structure

โ”œโ”€โ”€ hybrid_llm.py    # Training script and model definition
โ”œโ”€โ”€ inference.py     # Inference and chat interface
โ”œโ”€โ”€ gpu_monitor.py  # GPU monitoring utilities
โ””โ”€โ”€ requirements.txt # Python dependencies

Customization

Modify HybridConfig in hybrid_llm.py to adjust:

  • Model dimensions
  • Layer patterns
  • Training parameters
  • Architecture choices

๐Ÿ“ˆ Performance

  • Training: Optimized with AMP, gradient clipping, and efficient data loading
  • Inference: Fast generation with temperature and top-k sampling
  • Memory: Efficient attention and SSM implementations

Contributing

This is a research project - feel free to experiment with different architectures and configurations!

๐Ÿ“„ License

See LICENSE file for details.