CLI overrides

Any JobConfig field reachable through dotted attributes can be overridden from the command line with --section.key=value. Parsing happens in _parse_cli_overrides in kempnerforge/config/loader.py; type coercion happens in _coerce_value in the same file.

Syntax

uv run python scripts/train.py configs/train/debug.toml \
    --model.dim=512 \
    --train.compile_model=false \
    --optimizer.lr=1e-4 \
    --optimizer.betas="[0.9,0.95]" \
    --distributed.tp=2

Each flag must begin with --. Parsing splits once on =:

  • Left of = is the dotted path. It builds a nested dict: --model.dim=512 becomes {"model": {"dim": 512}}.

  • Right of = is the literal value. The loader calls ast.literal_eval on it. If that raises, the raw string is kept.

  • A flag without = is shorthand for true: --train.compile_model sets it to true.

  • The value has to follow =. A value passed as the next argument, as in --train.max_steps 7, is refused with an error that shows --train.max_steps=7.

  • A value with a space has to reach the loader as one argument, so quote it: '--metrics.wandb_run_name=7b baseline'. Unquoted, the shell splits off baseline, and an argument without -- after an override is refused with an error that shows the quoted form. Arguments without -- before the first override are skipped, such as the config path when load_config reads sys.argv[1:] because it got no cli_args.

  • The SLURM launchers in scripts/slurm/ pass each override on as one argument, so a quoted value stays whole through them.

Value parsing

ast.literal_eval accepts Python literals:

CLI snippet

Parsed as

--model.dim=512

int(512)

--optimizer.lr=3e-4

float(0.0003)

--train.compile_model=true

bool(True) (via coercion — see below)

--optimizer.betas=[0.9,0.95]

list → tuple(0.9, 0.95) (coerced to tuple by field type)

--checkpoint.load_path=/scratch/ckpt

str("/scratch/ckpt") (literal_eval fails, keep as string)

--adapter.pre_norm=

str("") (literal_eval fails on an empty value, keep as string)

--data.anneal_weights='{"c4":0.7,"books":0.3}'

dict (parsed into DataConfig.anneal_weights)

Quote any value the shell would otherwise eat:

--optimizer.betas="[0.9,0.95]"   # list literal with spaces/brackets
--data.dataset_path="/n/holylfs06/.../shards"

Lists of dataclasses (DataConfig.datasets, DataConfig.phases) are not ergonomic on the CLI — pass them in the TOML preset instead. The loader will accept them if you really want to, by expanding each entry to a dict literal, but the TOML version is readable:

[[data.datasets]]
path = "/scratch/c4"
weight = 0.7
name = "c4"

[[data.datasets]]
path = "/scratch/books"
weight = 0.3
name = "books"

Dict-valued fields

A dotted path below a dict-valued field sets that one key and keeps the rest of the table, whether the TOML or the field’s default holds it. With [metrics.mlflow_tags] holding team = "kf" and stage = "one", --metrics.mlflow_tags.stage=two gives {"team": "kf", "stage": "two"}, and --vlm.module_patterns.adapter="['adapter.*']" changes the adapter’s patterns and keeps the other modules’. A dict literal replaces the whole table: --data.anneal_weights='{"c4":0.7,"books":0.3}' drops any other key the TOML set.

Each value takes the value type of the table, so --vlm.module_patterns.vision_encoder="vision_encoder.*" gives the list ["vision_encoder.*"]. A key the table does not hold is added, so a misspelled key adds a new entry unless the field checks its keys, as optimizer.lr_multipliers does against vlm.module_patterns. Each dot starts a level below, so a dotted path cannot set a key that contains a dot: --data.anneal_weights.c4.en=0.9 names the key en in a table c4, which a table of floats refuses. Set such a key in the TOML as a quoted key, such as "c4.en" = 0.9, or give the whole table as a dict literal.

Boolean shorthand

A flag with no = becomes True:

--train.compile_model     # equivalent to --train.compile_model=true

For False, write it explicitly: --train.compile_model=false.

A bool field also takes the strings "true", "1" and "yes" as True and "false", "0" and "no" as False, in any case, and the numbers 1 and 0. Any other value, such as the misspelling ture or the number 2, is refused with an error that names the field, from the TOML file as from the command line.

Type coercion

After ast.literal_eval produces a raw value, _coerce_value walks the dataclass type hint and coerces:

Field type

Input

Result

int

"512" or 3.0

int(…); a fraction such as 2.7, a bool, another string or another type → ValueError

float

"3e-4" or 1

float(…); a bool, a non-numeric string, an int too large for a float or another type → ValueError

bool

"true", "1", "yes" or 1 / "false", "0", "no" or 0

True / False; anything else → ValueError

tuple[float, float]

[0.9, 0.95]

(0.9, 0.95)

list[str]

"a"

["a"] (wraps bare scalar)

list[DatasetSource]

[{"path": …}]

[DatasetSource(path=…)] (recursive)

dict[str, list[str]]

{"vision_encoder": "vision_encoder.*"}

{"vision_encoder": ["vision_encoder.*"]} (each value coerced to the value type)

Literal["bf16", "fp16", "fp32", "fp8"]

anything else

ValueError

StrEnum (NormType, SchedulerType, …)

"rmsnorm"

NormType.rmsnorm

SchedulerType, NormType, Activation

a registered name

the name, as a str

X | None (Optional)

None → None; else coerce to X

Literal fields reject unknown strings at coercion time — a typo like --train.mixed_precision=bfloat16 (should be "bf16") fails before training starts. Every coercion refusal starts with the class and field it concerns, such as TrainConfig.batch_size: expected an int, got 2.7, and a refused value of a table also names its key, such as DataConfig.anneal_weights: key 'c4': expected a float, got 'x'. "fp16" passes this check on purpose and is then rejected by TrainConfig.__post_init__, whose error explains that fp16 would train with no loss scaling.

Three enums select a registry builder, so they also accept a name registered in their category: scheduler.name (SchedulerType, category scheduler), model.norm_type (NormType, norm) and model.activation (Activation, mlp). A plugin module in plugins registers its names before the overrides apply, so --scheduler.name=my_sched selects a scheduler it registered. A name that is neither a member nor registered raises a ValueError that lists both. The other enums (train.activation_checkpointing, distributed.pp_schedule, checkpoint.async_mode) accept only their members. model.activation also rejects core’s own mlp keys (swiglu, standard_gelu, standard_relu) in favor of silu, gelu and relu, and rejects a plugin’s MLP when num_experts > 0, since the MoE expert kernels compute core’s MLPs from the expert weights.

Unknown keys

The loader rejects keys not declared on the dataclass. A typo surfaces immediately:

$ uv run python scripts/train.py configs/train/debug.toml --model.dimm=512
ValueError: Unknown config keys in ModelConfig: ['dimm'].
Valid keys: ['activation', 'dim', ...]

--vlm.arch is the one field an override cannot always change. Each arch has its own [vlm] config class, picked by the arch of the TOML’s [vlm] section, whose other keys were written for it, and an override keeps that class; so when the TOML has a [vlm] section, --vlm.arch naming another arch is rejected with a ValueError that says to set arch in the TOML instead.

Inspecting the final config

Print the resolved config before the training loop begins by adding the flag to scripts/train.py or dumping it from a REPL:

from kempnerforge.config import load_config
from dataclasses import asdict
import json

config = load_config("configs/train/debug.toml",
                     cli_args=["--model.dim=512"])
print(json.dumps(asdict(config), indent=2, default=str))

See also