constants
constants
¶
Constants and enums for training configuration.
PrecisionType
¶
Bases: StrEnum
PyTorch Lightning precision types.
See: https://lightning.ai/docs/pytorch/stable/common/trainer.html#precision
get_model_dtype
¶
Get the dtype to convert model parameters to for this precision type.
For mixed precision types, converts to the lower precision dtype to avoid dtype mismatch errors during inference (e.g., bfloat16 input vs float32 bias).
Returns:
| Type | Description |
|---|---|
dtype
|
torch.dtype to convert model to |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For INT8 precision (requires specialized quantization) |
Source code in src/versatil/training/constants.py
is_mixed
¶
Check if this precision type autocasts compute around float32 weights.
Returns:
| Type | Description |
|---|---|
bool
|
True for the mixed half-precision types, where trainable parameters |
bool
|
must stay in float32 storage so optimizer updates are not rounded |
bool
|
away by the low-precision dtype. |
Source code in src/versatil/training/constants.py
autocast
¶
Return an autocast context matching this precision.
Enabled only for the mixed half-precision types, where forward passes outside the Lightning training loop must reproduce the training-time autocast over mixed float32/low-precision parameters. For all other precisions the returned context is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_type
|
str
|
Device type string for |
required |
Source code in src/versatil/training/constants.py
should_convert_model
¶
Check if model should be converted to a specific dtype for this precision.
Returns:
| Type | Description |
|---|---|
bool
|
True if model should be converted (for mixed/true half precision types) |
Source code in src/versatil/training/constants.py
CheckpointFilename
¶
Bases: StrEnum
Standard filenames within a training checkpoint directory.
CheckpointKey
¶
Bases: StrEnum
Keys used within checkpoint state dicts and normalizer params.
CompileMode
¶
Bases: StrEnum
torch.compile optimization modes.
See: https://pytorch.org/docs/stable/generated/torch.compile.html
Float32MatmulPrecision
¶
Bases: StrEnum
Float32 matrix multiplication precision for Tensor Cores.
Controls the precision of float32 matrix multiplications on GPUs with Tensor Cores.
See: https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html