Skip to main content

Advanced LLM architecture augmentation library - surgical model expansion with minimal compute

Project description

Cambium ๐ŸŒฑ

License Python PyTorch

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

๐Ÿ—๏ธ 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:

๐Ÿ’ฌ Community

  • GitHub Issues: Bug reports and feature requests
  • Discussions: Q&A and general discussion

Grow your models like nature intended ๐ŸŒฑ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cambium_llm-0.1.1.tar.gz (121.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cambium_llm-0.1.1-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

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

Hashes for cambium_llm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e273c6dabc2126cb6403f5312e07d0d24078e1c32d4c10e341470a3b28bbc79f
MD5 77dfeb7f851ee8654c562e922b648246
BLAKE2b-256 bc63b8c6419033fdb2957b7e4188ae06fd5655499975aa02e6448c873ff36094

See more details on using hashes here.

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

Hashes for cambium_llm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a1fc3f8c150de9b2046b0cd2823aa9bdbc469f58f3d04ef25639ed6bf02645b
MD5 d159048f257127d5ad4de92c8d97c0c3
BLAKE2b-256 56d55ff02143d33a82f815c6e94c91cf9236a9651fc90e3b206ccc05bc7ebb32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page