Validation rules¶
Validation runs in two passes:
Per-dataclass
__post_init__— fires the moment the dataclass is instantiated (i.e. as soon as the TOML and CLI overrides land). Checks fields that can be validated in isolation, and inJobConfigthe cross-section rules listed underJobConfig.__post_init__.JobConfig.validate(world_size)— called explicitly by the launchers (training/runtime.py,scripts/eval.py) onceworld_sizeis known, before the process group starts. Checks rules that cross section boundaries.
All invalid cases raise ValueError with a message naming the fields
involved, unless noted otherwise.
Per-dataclass __post_init__¶
ModelConfig¶
File:
kempnerforge/config/model.py.
n_kv_headsdefaults ton_headsif leftNone(MHA), whichever layer setsn_heads.dim,n_layers,n_heads,vocab_size,n_kv_headsmust all be positive.head_dim_overridemust be non-negative and even;0infers the head dim asdim // n_heads.With
head_dim_override = 0,dim % n_heads == 0(head dim is integral) anddim // n_headsmust be even, since rotary embeddings rotate pairs of dimensions. An odd quotient fails when the config is built rather than at model build; set an evenhead_dim_overrideto keep thatdimandn_heads.n_heads % n_kv_heads == 0(GQA replication factor is integral).activationis not one of core’smlpkeys (swiglu,standard_gelu,standard_relu); the error names the activation that selects it (silu,gelu,relu).With
num_experts > 0,activationissilu,geluorrelu: a plugin’s registered MLP is rejected, since the MoE expert kernels (grouped GEMM, packed experts) compute core’s SwiGLU or standard MLP from the expert weights.sdpa_backend ∈ {"auto", "flash", "efficient", "cudnn", "math"}.attention_backend ∈ {"sdpa", "flex"}.attention_backend = "flex"requiresdim // n_heads ≥ 16(below that the Triton template fails to lower). There is no upper bound: head_dim 256/320/384/512 are all verified working. Note the usable set is not an interval: head_dim 192 fails to compile on H200 / torch 2.11 while 128 and 256 are fine. That surfaces as a loud compile-time error, not silent corruption, so it is documented rather than guarded.attention_backend = "flex"with ansdpa_backendother than"auto"logs a warning: only a forward given aBlockMask(document or attention-group ids without a key padding mask) runs FlexAttention, which ignoressdpa_backend. Every other forward runs exactly as withattention_backend = "sdpa", andsdpa_backendapplies to it as it does there.attention_backend = "flex"requirestrain.seq_len ≥ 128, checked byJobConfigsince it reads[train]. Below that an Inductor-compiled model silently leaks attention across document boundaries. Localized to Inductor codegen: the same model underbackend="eager"orbackend="aot_eager"is exact, as is the FlexAttention kernel on its own, and a single attention block compiled by Inductor is exact too — it takes a larger graph to trigger. Reproduced identically on torch 2.11/2.13/2.14 (cu128 and cu130), so it is not waiting on a release. The dense-mask"sdpa"path is unaffected at every length, so existing packed runs are not at risk. Not reduced further; the bound is empirical. It costs nothing, since a sequence below the mask block size has no block sparsity to exploit.When
num_experts > 0(MoE):moe_top_k > 0moe_top_k ≤ num_expertsmoe_frequency > 0moe_sequence_aux_loss_weight ≥ 0moe_bias_schedule ∈ {"constant", "cosine_decay", "linear_warmup"}moe_shared_experts ≥ 0
TrainConfig¶
File:
kempnerforge/config/training.py.
batch_size,seq_len,max_steps,grad_accum_steps,nan_max_consecutiveall positive.grad_clip_norm > 0.nan_action ∈ {"warn", "skip", "raise"}; the TOML and CLI loader rejects any other value first, through the field’sLiteral.mixed_precision = "fp16"is rejected, since there is no loss scaling; use"bf16", or"fp32"on GPUs without bf16. A TOML that sets it fails to load everywhere, includingscripts/eval.py,generate.pyandconvert_checkpoint.py, unless an override replaces it. The check reads the TOML with the CLI overrides laid over it, so--train.mixed_precision=bf16loads it on any command line that takes config overrides;convert_checkpoint.pytakes none, so edit the TOML for it.
OptimizerConfig¶
File:
kempnerforge/config/optimizer.py.
lr > 0.weight_decay ≥ 0.weight_decay_scope ∈ {"exclude_norms_and_biases", "all"}.betas[0], betas[1] ∈ [0, 1).muon_momentum ∈ (0, 1).muon_ns_steps > 0.muon_adjust_lr ∈ {"original", "match_rms_adamw", "spectral_unclamped"}.muon_orthogonalize ∈ {"local", "exact"}.muon_ns_dtype ∈ {"fp32", "bf16"}.schedule_free_warmup_steps ≥ 0.lr_multipliersmaps non-empty module names without/to finite numbers> 0. A non-empty one needs a[vlm]section whosemodule_patternsnames every listed module; this is checked whenJobConfigis built. When the optimizer is built, a listed module that matches no parameter raisesValueError, and so do two listed modules that match the same parameters or parameters that partly overlap; a module whose parameters another’s strictly contain keeps them (see Optimizers). Which parameters the modules share depends on the model’s parameter names, so only the build can tell.
SchedulerConfig¶
File:
kempnerforge/config/scheduler.py.
warmup_steps ≥ 0.warmup_start_factor ∈ [0, 1].min_lr_ratio ∈ [0, 1].wsd_decay_type ∈ {"cosine", "linear", "sqrt"}.rex_alpha > 0.
DataConfig (and nested types)¶
File:
kempnerforge/config/data.py.
DataConfig:
num_workers ≥ 0.prefetch_factor ≥ 1.mix_temperature > 0.token_dtype ∈ {"", "uint16", "uint32"}.Every
DatasetSourceindatasetshaspathorhf_nameset.If
phasesis non-empty,phases[*].start_stepis strictly monotonically increasing (and unique).anneal_start_step ≥ 0.phasesandanneal_start_step > 0are mutually exclusive.
JobConfig.validate refuses datasets and mixture weights on a VLM run
(A mixture on a VLM run), weights for a mixture
the run does not build
(Mixture weights without a mixture),
sources that go by one name
(Mixture sources that share a name),
and a weight for a source the mixture does not have
(Mixture weights for unknown sources).
DatasetSource:
weight > 0.token_dtype ∈ {"", "uint16", "uint32"}.
TrainingPhase:
start_step ≥ 0.lr_scale > 0.Every weight in
dataset_weights ≥ 0.
EvalConfig¶
File:
kempnerforge/config/eval.py.
interval > 0.steps > 0.token_dtype ∈ {"", "uint16", "uint32"}.
(Data-source presence is enforced by JobConfig.validate, not here —
a disabled eval is still a valid EvalConfig.)
The .bin dtype itself is resolved, checked against metadata.yaml
and against each shard’s size when the dataset is built, not at config
load; see Memory-mapped dataset.
DistributedConfig¶
File:
kempnerforge/config/distributed.py.
dp_shard ∈ {-1} ∪ {1, 2, …}(negative values other than-1rejected;-1is the auto-resolve sentinel).dp_replicate, tp, pp, cp, ep ≥ 1.cp == 1. Context parallelism is not implemented and the mesh has nocpdimension, socp > 1would build a mesh that leaves ranks out, or train as plain FSDP whencpequals the world size. Rejecting it here stops the run beforeinit_distributed.
World-size validation happens in validate_world_size (called from
JobConfig.validate).
CheckpointConfig¶
File:
kempnerforge/config/checkpoint.py.
interval > 0.If
dyn_ckpt_windowis set:dyn_ckpt_window.start >= 0.dyn_ckpt_window.stop >= dyn_ckpt_window.start.dyn_ckpt_window.strategymust name a registered dyn_ckpt strategy ("power2"ships by default; seekempnerforge/config/registry.py).
MetricsConfig¶
File:
kempnerforge/config/metrics.py.
log_interval > 0.mlflow_description, when set, is a non-empty string.mlflow_tagsmaps non-empty string names to non-empty string values; the error names the offending key.With
enable_mlflowand a Databricks tracking URI,mlflow_experiment(when set) is an absolute workspace path, starting with/. The URI ismlflow_tracking_uri, else$MLFLOW_TRACKING_URI, else"databricks", read when the config loads.mlflow_register_checkpointsrequiresenable_mlflow.
ProfilingConfig¶
File:
kempnerforge/config/profiling.py.
end_step > start_step.
VLMConfig freeze specs¶
File:
kempnerforge/config/vlm.py.
freeze_schedulestart steps are strictly increasing.Every
moduleinfreezeand in eachFreezeStageis a module alias, a key ofmodule_patterns, or a parameter pattern, which holds a dot or one of*?[; a key resolves as its alias first, dot or not. A bare word that is neither, such as a typo of an alias, fails when the config loads. The check reads the TOML with the CLI overrides laid over it, so the alias a spec names may be amodule_patternskey set on the command line.The VLM build refuses a pattern in
freezeor in aFreezeStagethat matches no parameter of the built model, and names it.
AdapterConfig¶
File:
kempnerforge/config/adapter.py.
typemust name a registered adapter; the error lists them.hidden_dim >= 0.activation ∈ {"gelu", "silu", "relu"}.pre_normis""or a registered norm; the error lists them.pool_window > 0andpool_heads > 0.Every other field must be one the selected adapter uses, or stay at its default. The fields an adapter uses come from its builder’s parameters, or from the
acceptsit registers with (see Registry), so the check needs no list of types; the error names each unused field, its value, the adapter type, and the fields that type uses:typeUses
mlp_2layerhidden_dim,activation,pre_normlinearnone
avgpoolpool_window,hidden_dim;activationandpre_normoncehidden_dim > 0attentional_poolpool_window,pool_headsA plugin adapter whose builder reads a
**kwargsand registers noacceptsaccepts every field. The check reads the TOML with the CLI overrides laid over it, so a setting the adapter would drop stops the run beforeinit_distributed, whichever layer sets it. An override never restores a default, so a type switched on the command line needs the fields it does not use reset there too (for example--adapter.hidden_dim=0 --adapter.pre_norm=); see Config sections.
Cross-section rules in JobConfig.__post_init__¶
File:
kempnerforge/config/job.py.
These run when JobConfig is built, with the per-dataclass checks:
pluginsmust be a list of module path strings.data.hf_max_images != 1applies to VLM image runs only, not text runs or[video], and needsvlm.arch = "joint_decoder". It is refused withtrain.mixed_precision = "fp8"and, underattention_backend = "sdpa", withmodel.sdpa_backend = "flash".[video]needs a[vlm]section, andvlm.tile_gridmust stay 0 with[video].[vlm]needs a[vision_encoder]section; a missing[adapter]takes the defaults.With
vision_encoder.num_tokens > 0,model.max_seq_lenmust hold the image tokens the residual stream carries plusvlm.max_text_len. The image tokens count every image a document may hold (data.hf_max_images, or one clip on a[video]run) and every view of each (each frame of a clip, or each view of a tiled image) after the adapter, and none under Cross-Attention, whose residual stream carries text only.On a VLM run, an HF-backed encoder (
siglip2,clip) withfeature_dimornum_tokensabove 0 logs a warning: the values override the ones the encoder probes.data.pack_sequenceson a VLM run needsvlm.arch = "joint_decoder"and takes neither[video]nortrain.mixed_precision = "fp8".A nonempty
optimizer.lr_multipliersneeds a[vlm]section whosemodule_patternsnames every listed module (seeOptimizerConfig).attention_backend = "flex"needstrain.seq_len ≥ 128(seeModelConfig).
Cross-section rules — JobConfig.validate(world_size)¶
File:
kempnerforge/config/job.py.
Parallelism arithmetic¶
distributed.validate_world_size(world_size) requires
dp_replicate × dp_shard × tp × pp × cp × ep == world_size
with dp_shard=-1 resolving to world_size / (dp_replicate·tp·pp·cp·ep)
(must be an integer). Any mismatch raises ValueError naming all six
factors and the resolved dp_shard.
Sequence length¶
train.seq_len ≤ model.max_seq_len
The RoPE frequency tables are sized by model.max_seq_len; exceeding
it would index past the end.
Tie embeddings vs pipeline parallel¶
model.tie_embeddings && distributed.pp > 1 → ValueError
The embedding and output-head weights must live on different pipeline stages, so they can’t be tied.
Eval data source¶
eval.enabled && !eval.dataset_path && !eval.hf_dataset_name → ValueError
Eval steps under pipeline parallelism¶
eval.enabled && distributed.pp > 1 && eval.steps % train.grad_accum_steps != 0 → ValueError
Eval runs its batches through the training schedule, grad_accum_steps at a
time, so each eval microbatch has the shape the stages were built for.
A mixture on a VLM run¶
vlm set && (data.datasets is nonempty
|| some data.phases[i].dataset_weights is nonempty
|| data.anneal_start_step > 0 && data.anneal_weights is nonempty) → ValueError
A VLM run reads its data from data.hf_dataset_name and the other
data.hf_* fields, or from [video], and never builds a [[data.datasets]]
mixture, so its sources and any weights for them would be dropped silently.
One error names each such field and where the run reads its data from, and
asks for their removal. A phase’s lr_scale needs no mixture: it scales the
LR on a VLM run too.
Mixture weights without a mixture¶
vlm unset && data.datasets is empty
&& (some data.phases[i].dataset_weights is nonempty
|| data.anneal_start_step > 0 && data.anneal_weights is nonempty) → ValueError
Only a text run with [[data.datasets]] builds a mixture; a run on
data.dataset_path or data.hf_dataset_name builds none, so weights for one
would be dropped silently. The error names each field and asks for the
sources as [[data.datasets]] tables or the weights’ removal. A phase’s
lr_scale needs no mixture: it scales the LR on any run.
DataConfig.mixture_weight_fields lists the fields.
Mixture weights for unknown sources¶
a key of some data.phases[i].dataset_weights, or of data.anneal_weights when
data.anneal_start_step > 0, is no source's DatasetSource.mixture_name → ValueError
The mixture names each source by its name, else its path, else its
hf_name, and a phase reweights a source only through a key equal to that
name, so a key that matches none would be ignored and the source would keep
its declared weight. The error names each field with its unknown keys and
lists the sources’ names. DataConfig.unknown_mixture_weight_keys finds them.
These four checks run here, on the config after the CLI overrides, so a
TOML can leave the sources to --data.datasets or the weights to
--data.anneal_weights.
VLM architectures under tensor parallelism¶
Checked first when distributed.tp > 1, ahead of head divisibility, so the
error names the arch rather than a head count:
isinstance(vlm, MoTConfig) && distributed.tp > 1 → ValueError
vlm set && distributed.tp > 1 && sequence parallelism on → ValueError
The tensor-parallel plan
(apply_tensor_parallel)
is written for TransformerBlock and walks model.layers only. The
checks act on the class of the [vlm] config, and the errors name that
class’s arch.
mot:MoTBlockrenames the attention modules (attn_norm,attn) and holdsmlp_normandmlpas per-modalityModuleDicts, so the build fails withKeyError: 'parameter name can't contain "."'or no parameter is sharded.Every other arch, with sequence parallelism on: the plan shards the activations along the sequence for a dense model with untied embeddings (
ModelConfig.tp_sequence_parallel, without pipeline parallelism), and the first forward fails on mixedtorch.TensorandDTensoroperands, injoint_decoderandmomawhere the image prefix joins the token embeddings and incross_attentionin the first cross-attention block.
With sequence parallelism off, which an MoE model or tied embeddings give
(for moma only tied embeddings, since MoMa keeps model.num_experts = 0),
joint_decoder, cross_attention and moma train under tensor parallelism
and match an unsharded model with the same weights. The plan shards the
transformer blocks, and the cross-attention blocks and MoMa’s expert groups
stay whole on every tensor-parallel rank and compute the same result there,
as MoE experts do in text models. Otherwise set distributed.tp = 1.
Tensor-parallel head divisibility¶
When distributed.tp > 1:
model.n_heads % distributed.tp == 0model.n_kv_heads % distributed.tp == 0
FP8 + TP¶
train.is_fp8 && distributed.tp > 1 → ValueError
Rationale in the error message: torchao.Float8Linear does not compose
with DTensor sharding today.
FP8 geometry¶
train.is_fp8 && model.dim % 16 != 0 → ValueError
train.is_fp8 && vlm is None && (train.batch_size * train.seq_len) % 16 != 0 → ValueError
torch._scaled_mm needs both dimensions of an FP8 weight to be
multiples of 16, and every attention and MLP projection and the output
head has model.dim on one side, so with any other dim no layer
could run in FP8. Other unaligned layers are not errors: k_proj and
v_proj with a small n_kv_heads * head_dim, an output head with a
vocab_size such as 50257, or an explicit ffn_hidden_dim that is not
a multiple of 16 stay in bf16, and apply_float8 names them in a
startup warning (see
FP8 § Exclusion rules).
The second rule covers the weight gradient. torchao computes it as
grad_output.t() @ input, which multiplies over the micro-batch’s
batch_size * seq_len tokens, and torch._scaled_mm needs that
dimension to be a multiple of 16 as well. Without the check, such a run
passes the forward and fails in its first backward. Under pipeline
parallelism each micro-batch is also batch_size rows. VLM runs are
not checked, because their token counts depend on the data (image
tokens plus text) rather than on the config alone; a VLM micro-batch
whose token count is not a multiple of 16 fails in its first backward,
with an error such as Expected trailing dimension of mat1 to be divisible by 16 but got mat1 shape: (<out_features>x<tokens>). A
packed VLM run (data.pack_sequences = true) is refused with FP8 when
JobConfig is built (__post_init__), because its head runs over the
batch’s text tokens, a count that changes from batch to batch. With
data.hf_streaming, the last batch of each pass over the stream can be
short, so keep train.seq_len itself a multiple of 16 there.
MoE + PP¶
model.is_moe && distributed.pp > 1 → ValueError
Rationale: routing is data-dependent and resists pipeline-stage
splitting. Use FSDP, TP, or EP instead; for vlm.arch = "mot" the error
offers FSDP alone, since MoT runs neither TP nor EP.
Expert parallel¶
When distributed.ep > 1:
vlm.archmust not be"mot"or"moma". Checked first, so these jobs get their own reason whatevermodel.num_expertsis:mot: the FSDP2 wrap for expert-parallel blocks expectslayer.attentionandlayer.mlp, andMoTBlocknames its attentionattnand keeps its experts per modality, so the model build fails. MoT with MoE trains withep = 1.moma:apply_expert_parallelpartitionsMoEMLPexperts only, and MoMa’s per-modality expert groups need an EP-aware dispatch that is not wired yet. MoMa also requiresmodel.num_experts = 0, which the next check rejects, so this one has to come first to be seen at all.
model.is_moemust beTrue(the error reads"ep > 1 requires an MoE model (num_experts > 0)").model.num_experts % distributed.ep == 0.
bf16 gradient reduce without a data-parallel mesh¶
(train.grad_reduce_dtype == "bf16" || vision_encoder.grad_reduce_dtype == "bf16")
&& max(dp_replicate, dp_shard, tp, ep) == 1 → ValueError
FSDP2 wraps nothing without a data-parallel mesh, so a bf16 gradient
reduce would do nothing. That leaves one GPU and a pp-only mesh: with
tp > 1 or ep > 1 the mesh keeps a size-1 dp_shard dimension, so
FSDP2 wraps the model and the setting acts. The VLM field counts only
on a VLM run. validate(world_size, training=False), which
scripts/eval.py calls, skips the check: evaluation reduces no
gradient. The build also refuses vision_encoder.grad_reduce_dtype = "bf16" when no step of the run trains the encoder. See
FSDP2 § Gradient reduce dtype.
Vision encoder weights¶
vlm set && vision_encoder.type in {"siglip2", "clip"} && vision_encoder.path == "" → ValueError
The Hugging Face encoders load a pretrained model from vision_encoder.path,
a Hub id or a local directory, and the error asks for it. The check runs here,
on the config after the CLI overrides, so a TOML can leave the path to
--vision_encoder.path. The model’s own config is read only when the model is
built: with vision_encoder.feature_dim = 0, a model whose config has no
hidden_size fails there, with an error that names vision_encoder.path and
asks for vision_encoder.feature_dim, the width of the features its vision
tower returns.
[video] and the [data] Hugging Face fields¶
video set && a data.hf_* field differs from its default → ValueError
A video run builds its dataset from [video]. From [data] it reads
tokenizer_path and the loader settings (num_workers, pin_memory,
prefetch_factor), so a Hugging Face field set there would be dropped
silently. The error lists each such field, with the [video] field to set
instead where there is one, and the defaults to put back:
|
Set instead |
|---|---|
|
|
|
|
|
|
|
|
|
no counterpart |
The fields are compared with their defaults, so hf_dataset_split = "train"
or hf_image_size = 224 passes, and an empty hf_dataset_name or
hf_dataset_config counts as unset like their default None.
data.hf_max_images is refused with [video] when JobConfig is built.
MoE + torch.compile — warning, not error¶
model.is_moe && train.compile_model → logger.warning(…)
Routing produces data-dependent shapes that break torch.compile’s
graph, so the loop logs a warning but still runs. Set
train.compile_model=false for MoE runs.
Flash attention and masked runs¶
model.sdpa_backend == "flash" && (
data.pack_sequences && model.attention_backend == "sdpa" && a data source
|| video && vlm.arch in {"joint_decoder", "mot", "moma"}
&& the vlm section's class is not MoT
) → ValueError
Checked by the training setup on CUDA, after the CLI overrides and
before the process group starts
(JobConfig.check_flash_attention_masks). Evaluation and generation
are not checked at setup; on CUDA, a forward there that passes a dense
mask to Attention, such as video evaluation’s frame mask under
Joint-Decoder or MoMa, raises the ValueError from
Attention.forward. PyTorch’s CUDA FlashAttention
kernel takes no attention mask, and these runs build one: packed rows
read from a dataset mask their documents from each other, and the padded
frames of a video run are masked in self-attention, under
attention_backend = "flex" too, which turns only document and group
masks into a block mask. The modality strategy, which vlm.arch picks,
masks frames in self-attention under Joint-Decoder, MoT and MoMa, while
Cross-Attention masks them in its cross-attention layers only, and the
attention the model builds, which the section’s class picks, runs under
the configured backend except under MoT, so a run counts only when both
apply (JobConfig.masks_frames_in_backend_attention), as after a
--vlm.arch override. Image runs whose documents can hold several
images (data.hf_max_images != 1) are refused under "sdpa" when the
config is built, and on CUDA a dataset with text-only rows on the
single-image route (data.pack_sequences = false and
data.hf_max_images = 1) is refused by the same test when the data
pipeline is built, since only the dataset knows it has such rows. A
forward that passes a dense mask to SDPA some other way on CUDA, such as
attention groups from a collator of your own, raises a ValueError that
names the setting instead of PyTorch’s No available kernel.
Example: a failing config and its error¶
# configs/train/bad.toml
[model]
n_heads = 17 # prime → TP divisibility will fail
max_seq_len = 1024
[train]
seq_len = 2048 # exceeds max_seq_len
[distributed]
tp = 4
Loading works (no __post_init__ failure since each field is valid in
isolation), but validate(world_size=4) raises:
ValueError: train.seq_len (2048) exceeds model.max_seq_len (1024)
Fix seq_len, re-run, and the next error is:
ValueError: n_heads (17) must be divisible by tp (4)
validate is ordered — each call surfaces the first failing invariant.
See also¶
Config sections — every field that these rules reference.
Architecture § Parallelism order — the 5-step order these cross-section rules exist to protect.