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 โš ๏ธ โš ๏ธ โš ๏ธ
Mistral โš ๏ธ โš ๏ธ โš ๏ธ
Qwen2 โš ๏ธ โš ๏ธ โš ๏ธ

โš ๏ธ Experimental: Gemma, Mistral, and Qwen2 support is architecture-level (they share the same decoder-layer structure as LLaMA) but has not been end-to-end tested yet. LLaMA-family models are fully verified.

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.0.tar.gz (101.9 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.0-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file cambium_llm-0.1.0.tar.gz.

File metadata

  • Download URL: cambium_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 101.9 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.0.tar.gz
Algorithm Hash digest
SHA256 a39e81575b3a1e62aa4aa4d50247cccb5dcedd0a7916357253bcc7c62efd14c0
MD5 cd84269aeb37f36bf350805f098a4d42
BLAKE2b-256 3af3664c6fe7d17b1cc94c6a8fe683b8bf6696045821ca13fa31ec7f8eaf4204

See more details on using hashes here.

File details

Details for the file cambium_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cambium_llm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 57.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1dd776d2c5ddadcf61318c95fe105ba9e1237aec2246d2a5d94f56cf6ec5ab9
MD5 d5226433011f7123d60f2e46fb58d7d5
BLAKE2b-256 ccb3c7519b1613ec32ebeeceb0fb02421bd79d45214b809dc3d81efe22b0cc5d

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