Advanced LLM architecture augmentation library - surgical model expansion with minimal compute
Project description
Cambium ๐ฑ
Advanced LLM Architecture Augmentation Library
Expand your LLMs like nature intended - surgically, efficiently, and beautifully.
Cambium is an open-source Python library that enables surgical expansion of Large Language Models (LLMs). Named after the plant tissue responsible for secondary growth, Cambium allows developers and researchers to add new layers or architecture blocks to existing models using familiar PyTorch-like APIs.
๐ฑ Our Vision
We believe that experimenting with LLM architecture should not require a multi-million-dollar compute cluster.
Today, the frontier of language-model research is largely locked behind paywalls of scaleโprohibitive GPU hours, massive infrastructure, and closed-source decisions made by a handful of organizations. Cambium exists to change that. We want anyone with curiosity and a laptop to be able to ask: "What if I add a new attention mechanism here?" or "What happens if I widen the hidden dimensions of layer 12?"โand actually try it, on real models, in minutes.
By making surgical model expansion lightweight, reproducible, and accessible, we hope to empower students, indie researchers, and open-source teams to push the boundaries of LLM architecture without the traditional barriers of cost and scale. Every new idea deserves a fair shot, regardless of the size of your GPU budget.
๐ฏ The Core Idea
Traditional: Train new 7B model from scratch (expensive ๐ฐ)
Cambium: Expand 2B โ 4B, preserve weights, train only new (efficient ๐ฑ)
Key Benefits:
- ๐ Preserve pretrained knowledge - Keep all original weights intact
- ๐ Modular expansion - Add capacity where needed
- ๐๏ธ Staged training - Progressive unfreezing strategies
- โก Minimal compute - Train only new parameters initially
- ๐ค Framework compatible - Works with HF Transformers, TRL, PEFT
๐ฆ Installation
# Basic installation
pip install cambium-llm
# With training dependencies (recommended)
pip install "cambium-llm[train]"
# Development installation
pip install "cambium-llm[dev]"
๐ Quick Start
from cambium import ExpandableModel, InterleavedExpansion
from cambium.training import StagedTrainer
import torch
# 1. Load base model
model = ExpandableModel.from_pretrained("HuggingFaceTB/SmolLM2-135M", dtype=torch.float32)
# 2. Expand with 4 new transformer blocks
model.expand(InterleavedExpansion(num_layers=4, initialization="identity"))
# 3. Setup staged training
trainer = StagedTrainer(model)
trainer.add_phase(name="warmup", freeze="original", lr=1e-4, epochs=2)
trainer.add_phase(name="finetune", freeze="none", lr=1e-6, epochs=1)
# 4. Train
trainer.train(train_dataloader, eval_dataloader)
# 5. Save
model.save_expanded("./my-expanded-model")
๐ Expansion Strategies
1. Interleaved Block Expansion (LLaMA-Pro style)
Insert new transformer blocks between existing ones:
from cambium import InterleavedExpansion
expander = InterleavedExpansion(
num_layers=4,
initialization="identity", # Near-identity init
)
model.expand(expander)
# Original: [Block0] โ [Block1] โ [Block2]
# Expanded: [Block0] โ [New0] โ [Block1] โ [New1] โ [Block2]
2. Width Expansion
Increase hidden dimensions:
from cambium.strategies import WidthExpansion
expander = WidthExpansion(
hidden_dim_multiplier=1.5, # 768 โ 1152
initialization="copy",
)
model.expand(expander)
3. Parallel Adapters
Add parallel pathways:
from cambium.strategies import ParallelAdapterExpansion
expander = ParallelAdapterExpansion(
adapter_type="bottleneck",
bottleneck_dim=256,
target_layers=[20, 21, 22, 23], # Last 4 layers
)
model.expand(expander)
4. Custom Block Expansion
Define and insert your own architecture blocks:
from cambium import CustomBlockExpansion
from cambium.blocks import CambiumBlock, SwiGLUBlock
import torch.nn as nn
# Use a template
model.expand(CustomBlockExpansion(
block_class=SwiGLUBlock,
num_layers=4,
residual_connection=True,
))
# Or define your own
class MyBlock(CambiumBlock):
required_config_keys = ["hidden_size"]
def __init__(self, config, layer_idx=0):
super().__init__()
self.proj = nn.Linear(config.hidden_size, config.hidden_size)
def forward(self, hidden_states, **kwargs):
return self.proj(hidden_states)
model.expand(CustomBlockExpansion(
block_class=MyBlock,
num_layers=2,
residual_connection=True,
))
๐ Training Strategies
Phase 1: Warmup New Layers
trainer.add_phase(
name="warmup",
freeze="original", # Freeze all original weights
lr=1e-4,
epochs=2,
)
Phase 2: Progressive Unfreezing
trainer.add_phase(
name="unfreeze",
unfreeze_groups=[-4, -3, -2, -1], # Last 4 layer groups
lr=5e-5,
epochs=1,
)
Phase 3: Full Fine-tuning
trainer.add_phase(
name="finetune",
freeze="none", # Unfreeze all
lr=1e-6,
discriminative_lr={
"embeddings": 1e-8,
"original_layers": 1e-6,
"new_layers": 1e-5,
},
epochs=1,
)
๐ง Supported Models
| Model | Block Expansion | Width Expansion | Adapters |
|---|---|---|---|
| LLaMA 2/3 | โ | โ | โ |
| Gemma / Gemma 3 | โ | โ ๏ธ | โ ๏ธ |
| Mistral | โ | โ ๏ธ | โ ๏ธ |
| Qwen2 / Qwen3 | โ | โ ๏ธ | โ ๏ธ |
โ Verified end-to-end for block expansion (
InterleavedExpansion) on all listed models. โ ๏ธ Width expansion and adapters are currently verified only on LLaMA-family models.More models coming soon!
๐ Documentation
- 01 - Quickstart Guide
- 02 - Interleaved Expansion
- 03 - Staged Training
- 04 - Complete Workflow
- 05 - Width Expansion
- 06 - Parallel Adapters
- 07 - Custom Blocks
๐๏ธ Architecture
cambium/
โโโ core/ # Low-level surgical operations
โ โโโ expansion.py # Model surgery engine
โ โโโ initialization.py # Smart init strategies
โ โโโ freezing.py # Advanced freezing logic
โโโ strategies/ # Expansion strategies
โ โโโ block_expansion.py
โ โโโ width_expansion.py
โ โโโ parallel_adapters.py
โ โโโ custom_expansion.py # Custom block insertion
โโโ blocks/ # Custom block definitions
โ โโโ base.py # CambiumBlock ABC, ResidualWrapper
โ โโโ templates.py # Pre-built blocks (SwiGLU, etc.)
โโโ training/ # Training utilities
โ โโโ staged_trainer.py
โ โโโ utilities.py
โโโ models/ # Model wrappers
โ โโโ expandable.py
โโโ utils/ # Helper utilities
โ โโโ memory.py
โ โโโ validation.py
โโโ exceptions.py # Error classes
๐งช Testing
# Run tests
pytest tests/
# Run with coverage
pytest --cov=cambium tests/
# Run specific test file
pytest tests/unit/test_expansion.py -v
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
# Clone the repository
git clone https://github.com/SorawitChok/Cambium.git
cd cambium
# Install in development mode
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
๐ Comparison with Alternatives
| Approach | Method | Pros | Cons |
|---|---|---|---|
| Cambium | Add new blocks | Full capacity increase | More memory |
| LoRA | Low-rank adapters | Minimal params | Limited capacity |
| IAยณ | Learned scaling | Preserves structure | Architecture-specific |
| Prefix Tuning | Learned prefixes | No model changes | Limited expressiveness |
| Full Fine-tune | Train all params | Best performance | Expensive |
When to use Cambium:
- You need more model capacity than adapters can provide
- You want to add architectural components (new attention types, etc.)
- You have compute for training new layers but not full models
- You want progressive training strategies
๐ Citation
If you use Cambium in your research, please cite:
@software{cambium2026,
title={Cambium: Advanced LLM Architecture Augmentation},
author={Sorawit Chokphantavee, Sirawit Chokphantavee, and Cambium Team},
year={2026},
url={https://github.com/SorawitChok/Cambium}
}
๐ License
Cambium is released under the Apache License 2.0. See LICENSE for details.
๐ Acknowledgments
Cambium builds on the excellent work of:
- Hugging Face Transformers
- PyTorch
- LLaMA-Pro (inspiration for interleaved expansion)
๐ฌ Community
- GitHub Issues: Bug reports and feature requests
- Discussions: Q&A and general discussion
Grow your models like nature intended ๐ฑ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cambium_llm-0.1.1.tar.gz.
File metadata
- Download URL: cambium_llm-0.1.1.tar.gz
- Upload date:
- Size: 121.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e273c6dabc2126cb6403f5312e07d0d24078e1c32d4c10e341470a3b28bbc79f
|
|
| MD5 |
77dfeb7f851ee8654c562e922b648246
|
|
| BLAKE2b-256 |
bc63b8c6419033fdb2957b7e4188ae06fd5655499975aa02e6448c873ff36094
|
File details
Details for the file cambium_llm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cambium_llm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 69.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a1fc3f8c150de9b2046b0cd2823aa9bdbc469f58f3d04ef25639ed6bf02645b
|
|
| MD5 |
d159048f257127d5ad4de92c8d97c0c3
|
|
| BLAKE2b-256 |
56d55ff02143d33a82f815c6e94c91cf9236a9651fc90e3b206ccc05bc7ebb32
|