Examples Curriculum
Examples Curriculum
The Laco examples curriculum is a set of progressively more complex
configuration examples demonstrating the full API. All examples live under
sources/laco/examples/ and are exercised by tests/test_examples.py.
Tier 0–1: Foundations
| Module | What it demonstrates |
|---|---|
mlp.py | L.call, L.params, L.repeat, L.OrderedDict |
linear_regression.py | L.call, L.partial, L.params |
cnn_classifier.py | Stacked stages with L.repeat |
text_classifier.py | L.required[T]() for mandatory fields |
Minimal example: linear regression
import laco.language as L
from torch import nn, optim
@L.params
class hps:
in_features: int = 8
out_features: int = 1
learning_rate: float = 1e-2
model = L.call(nn.Linear, root=True)(
in_features=hps.in_features,
out_features=hps.out_features,
)
optimizer = L.partial(optim.SGD)(lr=hps.learning_rate)
Load and instantiate:
cfg = laco.load("configs://examples/linear_regression.py#model")
model = laco.instantiate(cfg)
Override from CLI:
laco compose configs://examples/linear_regression.py hps.in_features=16
Tier 0–1: Typed-group variants
Each Tier 0–1 example has a sibling in examples/typed/ that uses the
typed-group API (L.Group, @L.config, L.slot, L.bind).
| Module | Changes |
|---|---|
typed/mlp.py | ActivationGroup(L.Group[nn.Module]) for swappable activations |
typed/linear_regression.py | OptimGroup(L.Group[Optimizer]) |
typed/text_classifier.py | @L.config schema, L.required[int]() |
Typed-group example: MLP
class ActivationGroup(L.Group[nn.Module]):
relu = L.call(nn.ReLU)()
gelu = L.call(nn.GELU)()
@L.config
class MLPSchema:
dim_in: int = 128
activation: nn.Module = L.slot(ActivationGroup)
defaults = L.Defaults(
L.self_,
L.bind(MLPSchema.activation, ActivationGroup.relu), # default to ReLU
)
Override from CLI: laco compose examples/typed/mlp.py activation=gelu
Tier 2: Building Blocks
| Module | What it demonstrates |
|---|---|
blocks/residual.py | Residual connection, L.call factories |
blocks/transformer.py | Multi-head attention + FFN layers |
blocks/decoder.py | Autoregressive decoder |
Tier 3–4: Vision & Language Models
Large model configs under examples/models/.
Tier 5: Ecosystem Integrations
| Module | Integration |
|---|---|
integrations/lightning_module.py | PyTorch Lightning |
integrations/transformers_qa.py | HuggingFace Transformers |
integrations/tensordict_module.py | TensorDict |
Tier 6: End-to-end Pipelines
| Module | What it demonstrates |
|---|---|
pipelines/mnist_train.py | MNIST training loop with @L.task |
pipelines/clm_finetune.py | Causal-LM fine-tuning pipeline |
Running the MNIST pipeline
# Smoke run (1 step, no real data needed):
python -m laco.examples.pipelines.mnist_train
# 10 steps on real MNIST (downloads ~11 MB):
python -m laco.examples.pipelines.mnist_train hps.num_steps=10