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.