Skip to main content

ShimbaLLM

Compute-efficient training for small language models. ShimbaLLM implements CROP (Curriculum-guided Reduction Of Pretraining): loss-gated data staging with selective token replay, a 2K→4K context ramp, and a WSD backbone with compute recycling — coordinated in one adaptive, FLOPs-accounted training engine.

Based on the research paper "Smaller, Faster, Smarter: Loss-Gated Data Staging with Selective Token Replay for Compute-Efficient Small Language Model Training" (see docs/CROP_paper.pdf).


Why

At fixed parameter count, recent small language models differ by tens of MMLU points purely because of recipe choices (Phi-3-mini 69.0 vs Gemma-2-2B 51.3 at ~3B). CROP turns those choices into a single procedure whose compute bill is explicit and falsifiable:

Component Mechanism FLOPs vs. uniform baseline (paper Table 1, 1.5B / 100B tokens)
Uniform baseline all tokens, 4K context, full loss 100%
Document gating drop lowest-excess-loss 30% of documents — never forwarded or back-propagated −15.4%
Context ramp Stage A at 2K, Stage B ramps 2K→4K −6.6%
Token replay masking mask easiest tokens (no FLOP change; shifts the loss-vs-FLOPs curve down) 0%
Reference scoring 0.3B frozen scorer, forward-only over 1.4× corpus +8.1%
CROP (conservative) matched token budget 88.0%
CROP (H2 scenario) matched validation loss, 20% effective-budget shift 72.1%

Two properties make this more than a bag of tricks:

  1. Every stage transition is gated by a measured signal (validation excess-loss slope), not a fixed token count — a noisy corpus advances to selectivity sooner; a rich corpus earns more stable compute.
  2. The run is re-usable. The WSD schedule puts the whole decay inside Stage C, so the Stage-B stable checkpoint can be re-annealed on different high-quality slices — each additional compute budget costs ~15% of a full run.

The pipeline

            Phase 0 (offline, once)          frozen ref model (0.3B)
 corpus ────────────────────────────────► per-token scores s(x_i)
                                              │  doc score = mean s
                                              ▼
 ┌─────────────────────── Stage A (55%) ───────────────────────┐
 │ docs with mean s ≥ q30   ·  full loss  ·  ctx 2K  ·  WSD warmup→stable │
 └──────────────────────────────┬──────────────────────────────┘
                                ▼  advance when val excess-loss stalls (γ)
 ┌─────────────────────── Stage B (30%) ───────────────────────┐
 │ upper score tiers  ·  masked loss, ρ(t): 0.40→0.10  ·  ctx ramp 2K→4K  │
 └──────────────────────────────┬──────────────────────────────┘
                                ▼  save stable.pt (reusable asset)
 ┌─────────────────────── Stage C (15%) ───────────────────────┐
 │ top 20% slice  ·  LR annealing  ·  final model              │
 └──────────────────────────────┬──────────────────────────────┘
                                ▼
                    re-anneal branches (compute recycling)
                    branch_1, branch_2, ... @ ~15% cost each

Install

git clone https://github.com/ShimbaLLM/shimballm.git
cd shimballm
pip install -e .                # core: torch + numpy + pyyaml
pip install -e ".[hf]"          # optional: transformers / datasets / hub

or straight from GitHub, without cloning:

pip install git+https://github.com/ShimbaLLM/shimballm.git

Python ≥ 3.9, PyTorch ≥ 2.1. CPU works out of the box for small runs.

Train on Google Colab (no local GPU needed)

Open In Colab

notebooks/ShimbaLLM_CROP_Colab.ipynb runs the whole recipe in the cloud on a free T4. It auto-detects the hardware and picks a track:

Track Hardware What runs Time
CPU smoke no GPU tiny_cpu.yaml — synthetic corpus, full pipeline ~2 min
Real run T4/L4/A100 smollm_135m_hf.yaml — SmolLM2-135M on a streamed FineWeb-Edu sample ~1–2 h at the default 30M-token budget

The notebook patches the config for Colab automatically (fp16 on a T4, which lacks bf16; micro-batch 2 × 4K ctx with grad-accum 32 to fit 16 GB VRAM), projects the FLOPs bill before training, trains with --resume so a dropped session continues from last.pt, runs two re-anneal branches, plots the curves from log.jsonl, and finally pushes the model to the HF Hub with shimballm push.

Quickstart (60 seconds, CPU)

shimballm demo

runs the entire recipe on a synthetic corpus: Phase 0 scoring → Stages A/B/C → stable checkpoint → a re-anneal branch → and prints the FLOPs projection. Expect val_ce to fall from ~4.5 to ~0.6 and the re-anneal branch to report ~15% of the baseline cost.

Using the engine

1. Project your compute bill first

shimballm project                       # paper defaults: 1.5B student, 100B tokens
shimballm project --config examples/student_1p5b_crop.yaml

2. Score your corpus (Phase 0, cached)

shimballm score --config examples/tiny_cpu.yaml

Writes <cache_dir>/doc_scores.npy — per-document mean token loss under the frozen reference model. Payed once per corpus; every later run reloads it.

3. Train

shimballm train --config examples/tiny_cpu.yaml          # CPU demo
shimballm train --config examples/smollm_135m_hf.yaml    # real 135M run (needs [hf] extra)
shimballm train --config my.yaml --resume                # resume from last.pt

Artifacts in engine.out_dir:

File Contents
final.pt trained student (state dict + optimizer + meters)
stable.pt Stage-B stable checkpoint — the recycling asset
summary.json stage budgets, FLOPs accounting, val losses, projection
log.jsonl per-step metrics (loss, lr, ctx, masked fraction, FLOPs)
cache/doc_scores.npy Phase 0 document scores
branches/<tag>/branch.pt re-anneal branch models

4. Recycle: re-anneal branches

shimballm anneal --config examples/tiny_cpu.yaml --seed 1
shimballm anneal --config examples/tiny_cpu.yaml --seed 2 --budget 90000

or programmatically:

from shimballm import RunConfig
from shimballm.engine.recycling import AnnealBranchManager

cfg = RunConfig.from_yaml("examples/tiny_cpu.yaml")
mgr = AnnealBranchManager(cfg)                 # loads runs/.../stable.pt
mgr.run_branch(branch_seed=1, tag="code-heavy")
mgr.run_branch(branch_seed=2, tag="math-heavy")
print(mgr.best())                              # pick by val CE

5. Push to the Hugging Face Hub (org ShimbaLLM)

export HF_TOKEN=...
shimballm push --config examples/tiny_cpu.yaml --repo ShimbaLLM/crop-tiny-demo

Uploads weights + config.yaml + summary.json and generates a model card with the full CROP recipe table and this run's measured results.

Library API

from shimballm import RunConfig, CROPTrainer, project_crop

cfg = RunConfig.from_yaml("my.yaml")
trainer = CROPTrainer(cfg)
summary = trainer.train()
print(summary["val"], summary["flops_vs_baseline"])

Configuration reference

Section Key knobs Paper anchor
crop doc_drop_quantile (θ_doc, default 0.30), gate_gamma (γ) — the only two new hyper-parameters Eq. 3, Eq. 6
crop rho_start→rho_end (0.40→0.10): easiest-token share masked in Stage B, linear decay Eq. 5
crop stage_b_doc_quantile / stage_c_doc_quantile: replay tiers / anneal slice §4.4–4.5
schedule stage_shares (0.55/0.30/0.15), context_start→context_end (2K→4K), WSD warmup_fraction, end_lr_fraction §4.1, §4.6
ref arch, size (keep ~5× smaller than student), corpus_inflation (1.4) §4.2
engine out_dir, eval cadence, resume, save_stable_ckpt —
hub org (default ShimbaLLM), repo_name, push_after_train —

Baselines for ablations (paper protocol §6.1): B1 = uniform WSD — set crop.enabled: false, context_start == context_end. B2 = B1 + doc gating only (rho_start=rho_end=0). B3 = B1 + token masking only (drop quantile 0). B4 = cosine schedule (WSDLRSchedule.lr_at_cosine is provided).

Repository layout

shimballm/
├── notebooks/
│   └── ShimbaLLM_CROP_Colab.ipynb  # Colab: cloud training, no local GPU
├── config.py              # RunConfig + YAML (model/ref/data/crop/schedule/engine/hub)
├── tokenizer.py           # char tokenizer + HF adapter
├── data/
│   ├── corpus.py          # DocStore, QuantileSampler (tier curriculum), StreamingPacker
│   └── scorer.py          # Phase 0: excess-loss document scoring (cached)
├── models/
│   ├── tiny_gpt.py        # built-in decoder-only LM (RoPE, GQA, SwiGLU opt)
│   └── __init__.py        # build_model / build_reference_model (HF bridge)
├── optim/
│   ├── lr.py              # WSD schedule over token milestones
│   └── muon.py            # Muon (orthogonalized momentum) + AdamW factory
├── engine/
│   ├── flops.py           # 6ND + attention term; Table-1 projector; live meter
│   ├── masks.py           # Eq. 5 masked loss + rho(t) scheduler
│   ├── gates.py           # Eq. 6 adaptive stage gate (val excess-loss slope)
│   ├── recycling.py       # AnnealBranchManager (Stage-C fan-out)
│   └── trainer.py         # CROPTrainer: the full Algorithm 1
├── hub.py                 # HF Hub push + model card generation
└── cli.py                 # shimballm demo|project|score|train|anneal|push

Tests

pip install -e ".[dev]"
pytest tests/ -q          # 34 tests: paper numbers, WSD, masks, gate, curriculum, smoke run

tests/test_flops.py reproduces the paper's Table 1 from the engine's formulas — the accounting stays falsifiable as the code evolves.

Notes & limitations

  • Token replay masks do not save raw FLOPs (masked tokens still flow through the network); they buy learning efficiency per FLOP. The compute saving comes from document gating and the context ramp — exactly as in the paper.
  • The projection numbers are analytic (6ND + attention term), not measured wall-clock; systems effects (memory, I/O, kernels) are out of scope.
  • Reference-model bias is the main risk (a scorer that under-rates a domain starves it). Probe with mismatched-domain scorers before production runs; consider per-domain gate floors.
  • Mid-stage resume re-seeds the stream packer (a small data overlap window).

Citation

@techreport{shimballm2025crop,
  title  = {Smaller, Faster, Smarter: Loss-Gated Data Staging with Selective
            Token Replay for Compute-Efficient Small Language Model Training},
  author = {{ShimbaLLM}},
  year   = {2025},
  note   = {See docs/CROP\_paper.pdf; engine: github.com/ShimbaLLM/shimballm}
}

License

Apache-2.0 — see LICENSE.

Metadata

Release files for shimballm 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shimballm 0.1.0
File Size Uploaded Provenance Actions
shimballm-0.1.0.tar.gz 51.0 kB With provenance Details for shimballm-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shimballm 0.1.0
File Interpreter ABI Platform Actions
shimballm-0.1.0-py3-none-any.whl Python 3 none any Details for shimballm-0.1.0-py3-none-any.whl

Total release size: 99.3 kB

Release files / shimballm-0.1.0.tar.gz

Download URL shimballm-0.1.0.tar.gz
Size 51.0 kB
Tags Source
SHA-256 checksum
How to use checksums
34206cc056d6a1c1f88b2d4cfcd55ca2c0c75cfadb978041b642604012a1f58e
BLAKE2b-256 checksum
How to use checksums
b437827fd4503ce0dcc5929d6968b7747cdf2cb37abe965be667d3ca257fcd49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / shimballm-0.1.0-py3-none-any.whl

Download URL shimballm-0.1.0-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc8bb911b094a6e2b80fb001e7475c30d37c87d6c27d2de5d4366ad475ffdfe1
BLAKE2b-256 checksum
How to use checksums
abc8571d67756265ba4e5df2e3e68f328525452b974fcff6c075a98cd2fc01ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for shimballm 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for shimballm-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page