Skip to content

training_config

orchard.core.config.training_config

Optimization & Regularization Configuration Schema.

Declarative schema for training lifecycle, orchestrating optimization landscape and regularization boundaries. Synchronizes learning rate dynamics (Cosine Annealing) with data augmentation (Mixup) and precision policies (AMP).

Key Features
  • Optimization dynamics: LR schedules and momentum for loss landscape navigation
  • Regularization suite: Label smoothing and Mixup for generalization
  • Precision & stability: AMP and gradient clipping for hardware throughput and stability
  • Reproducibility: Global seeding for experiment replication (determinism in HardwareConfig)

Strict boundary validation (probability ranges, LR bounds) prevents unstable training states before first batch processing.

TrainingConfig

Bases: BaseModel

Optimization landscape and regularization strategies.

Validates training hyperparameters and provides structure for reproducibility, optimization, regularization, and scheduling.

Attributes:

Name Type Description
seed int

Random seed for reproducibility.

batch_size BatchSize

Training samples per batch (1-128).

epochs PositiveInt

Maximum training epochs.

patience NonNegativeInt

Early stopping patience in epochs.

use_tqdm bool

Enable progress bar display.

optimizer_type Literal['sgd', 'adamw']

Optimizer algorithm ('sgd' or 'adamw').

learning_rate LearningRate

Initial learning rate (1e-8 to 1.0).

min_lr LearningRate

Minimum learning rate for scheduler.

momentum Momentum

SGD momentum coefficient.

weight_decay WeightDecay

L2 regularization strength.

grad_clip GradNorm | None

Maximum gradient norm for clipping.

label_smoothing SmoothingValue

Label smoothing factor (0.0-0.3).

mixup_alpha NonNegativeFloat

Mixup interpolation coefficient.

mixup_epochs NonNegativeInt

Number of epochs to apply mixup.

use_tta bool

Enable test-time augmentation.

scheduler_type Literal['cosine', 'plateau', 'step', 'none']

LR scheduler type ('cosine', 'plateau', 'step', 'none').

monitor_metric Literal['auc', 'accuracy', 'f1']

Metric driving checkpointing and early stopping ('auc', 'accuracy', or 'f1').

scheduler_patience NonNegativeInt

ReduceLROnPlateau patience epochs (ignored by other schedulers).

scheduler_factor Probability

LR reduction factor (plateau factor and StepLR gamma).

step_size PositiveInt

StepLR decay period in epochs.

use_amp bool

Enable Automatic Mixed Precision training.

criterion_type Literal['cross_entropy', 'focal']

Loss function ('cross_entropy' or 'focal').

weighted_loss bool

Enable class-frequency loss weighting.

focal_gamma NonNegativeFloat

Focal loss focusing parameter.

validate_amp()

Validate AMP compatibility with batch size.

Raises:

Type Description
OrchardConfigError

If AMP enabled with batch_size < 4.

Returns:

Type Description
'TrainingConfig'

Validated TrainingConfig instance.

Source code in orchard/core/config/training_config.py
@model_validator(mode="after")
def validate_amp(self) -> "TrainingConfig":
    """
    Validate AMP compatibility with batch size.

    Raises:
        OrchardConfigError: If AMP enabled with batch_size < 4.

    Returns:
        Validated TrainingConfig instance.
    """
    if self.use_amp and self.batch_size < 4:
        raise OrchardConfigError(
            "AMP enabled with very small batch size (<4) can cause NaN gradients."
        )
    return self