kempnerforge.config.training¶
Training configuration.
Module Attributes
What |
|
|
Classes
Training hyperparameters. |
- kempnerforge.config.training.NaNAction¶
What
NaNDetectordoes on a step whose loss or gradient norm is NaN/Inf.alias of
Literal[‘warn’, ‘skip’, ‘raise’]
- kempnerforge.config.training.FP8_DIM_MULTIPLE = 16¶
torch._scaled_mmneeds both dimensions of an FP8 weight to be multiples of this.
- class kempnerforge.config.training.ActivationCheckpointing[source]¶
Bases:
StrEnum- none = 'none'¶
- full = 'full'¶
- selective = 'selective'¶
- __new__(value)¶
- class kempnerforge.config.training.TrainConfig[source]¶
Bases:
objectTraining hyperparameters.
"fp16"stays in themixed_precisionLiteralonly so the config loader passes it on to__post_init__, which rejects it with the reason; without it the loader would fail first with a generic Literal error.nan_actionandnan_max_consecutiveset the training loop’sNaNDetector: its response to a NaN/Inf step, and how many in a row stop the loop.grad_reduce_dtypeis the dtype FSDP2 reduces gradients in (reduce-scatter and, with replicas, all-reduce) for every unit the training build wraps with the language model’s policy: the transformer, and on a VLM the adapter."fp32"is the default;"bf16"halves the reduce traffic and rounds each rank’s gradient to bf16 before the sum. With"bf16"andgrad_accum_steps > 1every micro-step is reduced, one reduce-scatter per micro-step instead of one per step, and FSDP2 adds each reduced gradient into the sharded gradient, so the running sum is kept inmaster_dtypeand never in bf16."fp32"keeps one reduce per step, at the last micro-step, with the running sum held unsharded in fp32. Neither changes the stored parameter dtype or the dtype gradients are stepped in (master_dtype); a VLM’s vision encoder takesvision_encoder.grad_reduce_dtypeinstead.JobConfig.validaterefuses"bf16"on a run FSDP2 does not wrap (one GPU, a pp-only mesh), since nothing would be reduced.shutdown_timeout_secbounds a rank’s shutdown with a forced exit;0disables it, and left unset aSIGTERM’s fits the launch script’s signal lead (seekempnerforge.resilience.signal_handler.resolve_shutdown_timeouts).- activation_checkpointing: ActivationCheckpointing = 'none'¶
- property param_dtype: torch.dtype¶
Resolve mixed_precision to the compute dtype, also the master weight dtype by default.
FP8 resolves to bf16 – FP8 is a compute mode, not a storage dtype. The storage dtype is
master_dtype, which is fp32 withfp32_master_weights. A config switched to"fp16"after construction skips__post_init__, so"fp16"raises the sameValueErrorhere.
- property master_dtype: torch.dtype¶
Dtype the parameters, their gradients and the optimizer state are kept in.
- property reduce_dtype: torch.dtype¶
Dtype FSDP2 reduces the transformer’s and adapter’s gradients in.
- property reduces_every_micro_step: bool¶
Whether the transformer’s FSDP2 units reduce every micro-step, as a pipeline stage.
- __init__(batch_size=8, seq_len=2048, max_steps=100000, grad_accum_steps=1, grad_clip_norm=1.0, seed=42, data_seed=None, compile_model=True, mixed_precision='bf16', fp32_master_weights=False, tf32=False, grad_reduce_dtype='fp32', activation_checkpointing=ActivationCheckpointing.none, loss_fn='cross_entropy', z_loss_weight=0.0, ce_chunk_size=0, fp32_cross_entropy=False, shutdown_timeout_sec=None, nccl_health_check_interval=0, nan_action='warn', nan_max_consecutive=10)¶
- Parameters:
batch_size (int)
seq_len (int)
max_steps (int)
grad_accum_steps (int)
grad_clip_norm (float)
seed (int)
data_seed (int | None)
compile_model (bool)
mixed_precision (Literal['bf16', 'fp16', 'fp32', 'fp8'])
fp32_master_weights (bool)
tf32 (bool)
grad_reduce_dtype (Literal['fp32', 'bf16'])
activation_checkpointing (ActivationCheckpointing)
loss_fn (str)
z_loss_weight (float)
ce_chunk_size (int)
fp32_cross_entropy (bool)
shutdown_timeout_sec (float | None)
nccl_health_check_interval (int)
nan_action (Literal['warn', 'skip', 'raise'])
nan_max_consecutive (int)
- Return type:
None
- property effective_data_seed: int¶
Seed for data shuffling / batch composition.
Falls back to
seedwhendata_seedis unset, so existing configs reproduce their current trajectory. Kept independent fromseed(parameter init) so stability studies can vary batch order while holding initialization fixed. Must stay identical across data-parallel ranks so the global shuffle is consistent before rank partitioning.