Repository navigation
central documentation
GURUMURTHY edited this page Feb 24, 2026
·
1 revision
--
Note
This page is the central documentation hub for the Stackformer library.
- What is Stackformer?
- Repository structure
- Installation
- Quick start
- Core modules
- Model families
- Vision models
- Training workflow
- Text generation
- Development workflow
- Contribution guidelines
- Project links
Stackformer is a modular PyTorch library for Transformer-based models across NLP and vision. It is designed for:
- quick experimentation,
- reusable building blocks,
- clean model prototyping,
- production-friendly project structure.
Stackformer/
├── stackformer/
│ ├── modules/
│ │ ├── Attention.py
│ │ ├── Feed_forward.py
│ │ ├── Normalization.py
│ │ └── position_embedding.py
│ ├── models/
│ │ ├── OpenAI.py
│ │ ├── Meta.py
│ │ ├── Google.py
│ │ └── Transformer.py
│ ├── vision/
│ │ ├── vit.py
│ │ └── segformer.py
│ ├── generate.py
│ └── trainer.py
├── tests/
├── docs/
└── README.md
Install the library:
pip install stackformerInstall with optional extras:
pip install "stackformer[train]"
pip install "stackformer[dev]"
Tip
For local development, use an editable install: pip install -e ".[dev]".
import torch
from stackformer.models.OpenAI import GPT_2
model = GPT_2(
vocab_size=128,
num_layers=2,
embed_dim=32,
num_heads=4,
seq_len=16,
dropout=0.0,
hidden_dim=64,
)
x = torch.randint(0, 128, (2, 16))
logits = model(x)
print(logits.shape) # [2, 16, 128]
Multi_Head_AttentionMulti_query_AttentionGroup_query_Attention- RoPE and KV-cache helper utilities
FF_ReLUFF_GELU-
FF_SwiGLU
LayerNormalization-
RMSNormalization
- absolute/learned embeddings
- sinusoidal embeddings
- RoPE positional encoding
GPT_1-
GPT_2
llama_1-
llama_2
gemma_1_2b-
gemma_1_7b
-
transformer
stackformer.vision.vit.ViT-
stackformer.vision.segformer.SegFormerB0
The standard training loop with stackformer.trainer.Trainer:
- Prepare tokenized tensors/datasets.
- Create a model instance.
- Initialize
Trainerwith datasets and hyperparameters. - Run
trainer.train(). - Evaluate and use saved checkpoints.
Use stackformer.generate for autoregressive text generation with language models.
Run tests:
pytest -qInstall in editable mode:
pip install -e ".[dev]"
- Keep modules composable and independent.
- Prefer clear, typed APIs.
- Add or update tests in
tests/for behavior changes. - Keep default configurations practical for smoke tests.
- Repository: Gurumurthy30/Stackformer
- Issues: Issue tracker
- Discussions: Community discussions
- Releases: Release history
If you are new to the project, start with:
-
README.mdfor a high-level overview. -
stackformer/modules/for reusable core blocks. -
tests/for usage examples and expected behavior.