LFM2 - Liquid Foundation Model 2 (Minimal Implementation)
This is a minimal, open-source implementation of the Liquid Foundation Model 2 (LFM2) architecture described in Liquid AI's blog post. Since there is no official open-source implementation available, this repository provides a PyTorch implementation of the core architecture for research and educational purposes.
Features
- Hybrid architecture combining short-range convolutions with grouped query attention
- 16 blocks: 10 LIV convolution blocks + 6 GQA blocks
- Double-gated short-range convolutions for efficient local processing
- Grouped Query Attention (GQA) for efficient global attention
- SwiGLU activation functions
- RMSNorm normalization
- Rotary Positional Embeddings (RoPE)
Model Sizes
The implementation supports three model sizes:
- 350M parameters (768 hidden size)
- 700M parameters (1024 hidden size)
- 1.2B parameters (1536 hidden size)
Installation
pip3 install -U lfm2
Quick Start
import torch
from lfm2.main import create_lfm2_model
# Create a model
model = create_lfm2_model(
model_size="700M", # Choose from: "350M", "700M", "1.2B"
vocab_size=32768,
max_seq_length=32768,
verbose=True
)
# Example forward pass
batch_size = 2
seq_length = 32
input_ids = torch.randint(0, model.config.vocab_size, (batch_size, seq_length))
# Generate outputs
with torch.no_grad():
outputs = model(input_ids)
logits = outputs["logits"]
Architecture Details
LIV Convolution Blocks
The model uses Linear Input-Varying (LIV) convolution blocks that combine double-gating with short-range convolutions:
def lfm2_conv(x):
B, C, x = linear(x) # input projection
x = B*x # gating (gate depends on input)
x = conv(x) # short conv
x = C*x # gating
x = linear(x)
return x
Grouped Query Attention
The model implements Grouped Query Attention (GQA) for efficient global attention processing, reducing memory and computational requirements while maintaining model quality.
Usage Examples
Check example.py for detailed usage examples including:
- Basic forward pass
- Forward pass with attention masks
- Forward pass with caching
- Forward pass with all outputs
- Forward pass with custom position IDs
Citation
If you use this implementation in your research, please cite:
@misc{lfm2_minimal,
author = {Kye Gomez},
title = {LFM2: Minimal Implementation of Liquid Foundation Model 2},
year = {2024},
publisher = {GitHub},
url = {https://github.com/kyegomez/LFM2}
}
Disclaimer
This is an unofficial, minimal implementation based on publicly available information about the LFM2 architecture. It is not affiliated with or endorsed by Liquid AI. The implementation may differ from the original model in various aspects.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Release files for lfm2 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lfm2-0.0.2.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lfm2-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.7 kB
Release files / lfm2-0.0.2.tar.gz
| Download URL | lfm2-0.0.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d2ab18b6a63da226917d307de0b87a8a0596959033689d73661e77a81b2d42d
|
|
BLAKE2b-256 checksum How to use checksums |
c9ff2a8caebed5fc83573400829b0bf37e8d74db52012a265cd9e10706814d75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Darwin/24.5.0
|
Release files / lfm2-0.0.2-py3-none-any.whl
| Download URL | lfm2-0.0.2-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdc6b6fbecd34131071ccda2fad8b2a1c93e584b5d8d64230e58f29b286a613d
|
|
BLAKE2b-256 checksum How to use checksums |
5ce536d814029ba0ed79fe6e4d0103d5f5f51b374d2308a7929de8df2a4b43be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Darwin/24.5.0
|