TrainingStage<T, TInput, TOutput>

Models & Types · AiDotNet.Models.Options

Represents a single stage in a training pipeline with comprehensive configuration options.

For Beginners

Think of each stage as a chapter in a training book. Each chapter teaches the model something different, and you can configure exactly how that teaching happens.

How It Works

A training stage encapsulates all configuration needed for one step in a multi-stage training pipeline. Each stage can have its own:

Constructors

Constructor Summary
TrainingStage()

Properties

Property Summary
CheckpointMetricType BestCheckpointMetric { get; set; } Gets or sets the metric to use for determining the best checkpoint.
Dictionary<int, int> DistillationLayerMapping { get; set; } Gets or sets the layer mapping for intermediate distillation.
Dictionary<string, double> DataMixingRatios { get; set; } Gets or sets the data mixing ratio when combining multiple datasets.
Dictionary<string, object> Metadata { get; set; } Gets or sets custom metadata for this stage.
DistributedStrategy DistributedStrategy { get; set; } Gets or sets the distributed training strategy for this stage.
EarlyStoppingConfig EarlyStopping { get; set; } Gets or sets early stopping configuration specific to this stage.
FineTuningData<T, TInput, TOutput> TrainingData { get; set; } Gets or sets the training data for this stage.
FineTuningData<T, TInput, TOutput> ValidationData { get; set; } Gets or sets the validation data for this stage.
FineTuningMethodType FineTuningMethod { get; set; } Gets or sets the fine-tuning method to use in this stage.
FineTuningOptions<T> Options { get; set; } Gets or sets the fine-tuning options for this stage.
Func<FineTuningData<T, TInput, TOutput>, FineTuningData<T, TInput, TOutput>> DataPreprocessor { get; set; } Gets or sets custom data preprocessing for this stage.
Func<IFullModel<T, TInput, TOutput>, FineTuningData<T, TInput, TOutput>, CancellationToken, Task<IFullModel<T, TInput, TOutput>>> CustomTrainingFunction { get; set; } Gets or sets the custom training function for custom stages.
Func<IFullModel<T, TInput, TOutput>, FineTuningData<T, TInput, TOutput>, Task<Dictionary<string, double>>> CustomEvaluationFunction { get; set; } Gets or sets the custom evaluation function for this stage.
Func<TrainingStageResult<T, TInput, TOutput>, bool> RunCondition { get; set; } Gets or sets conditions that must be met to run this stage.
IFullModel<T, TInput, TOutput> CritiqueModel { get; set; } Gets or sets the model to use for generating critiques.
IFullModel<T, TInput, TOutput> RewardModel { get; set; } Gets or sets the reward model to use for RLHF stages.
IFullModel<T, TInput, TOutput> TeacherModel { get; set; } Gets or sets the teacher model for distillation stages.
ILossFunction<T> CustomLossFunction { get; set; } Gets or sets custom loss function for this stage.
LearningRateSchedulerType SchedulerType { get; set; } Gets or sets the learning rate scheduler type.
MixedPrecisionType MixedPrecisionDType { get; set; } Gets or sets the mixed precision data type.
OptimizerType OptimizerOverride { get; set; } Gets or sets the optimizer type override for this stage.
PreferenceLossType PreferenceLossType { get; set; } Gets or sets the loss type for preference optimization.
StageCallbacks<T, TInput, TOutput> Callbacks { get; set; } Gets or sets stage-specific callbacks.
TimeSpan MaxDuration { get; set; } Gets or sets the maximum duration for this stage.
TrainingStageType StageType { get; set; } Gets or sets the type of training stage.
bool BestCheckpointMetricMaximize { get; set; } Gets or sets whether higher is better for the best checkpoint metric.
bool Enabled { get; set; } Gets or sets whether this stage is enabled (skipped if false).
bool FreezeBaseModel { get; set; } Gets or sets whether to freeze the base model during this stage.
bool GRPOUseRelativeRewards { get; set; } Gets or sets whether to use relative rewards in GRPO.
bool IsEvaluationOnly { get; set; } Gets or sets whether this stage is evaluation-only (no training).
bool LogGradientNorms { get; set; } Gets or sets whether to log gradient norms.
bool LogLearningRate { get; set; } Gets or sets whether to log learning rate.
bool MergeLoRAAfterTraining { get; set; } Gets or sets whether to merge LoRA weights into base model after training.
bool SaveCheckpointAfter { get; set; } Gets or sets whether to save a checkpoint after this stage.
bool SaveOnlyBest { get; set; } Gets or sets whether to save only the best checkpoint based on validation metrics.
bool ShareReferenceModel { get; set; } Gets or sets whether to share reference model with the training model.
bool ShuffleData { get; set; } Gets or sets whether to shuffle the training data each epoch.
bool SyncBatchNorm { get; set; } Gets or sets whether to sync batch normalization across devices.
bool UpdateReferenceModel { get; set; } Gets or sets whether to update the reference model periodically.
bool UseDeterministicAlgorithms { get; set; } Gets or sets whether to use deterministic algorithms (may be slower).
bool UseDynamicLossScaling { get; set; } Gets or sets whether to use dynamic loss scaling for mixed precision.
bool UseGradientCheckpointing { get; set; } Gets or sets whether to use gradient checkpointing to save memory.
bool UseGradualUnfreezing { get; set; } Gets or sets whether to gradually unfreeze layers during training.
bool UseIntermediateDistillation { get; set; } Gets or sets whether to use intermediate layer distillation.
bool UseLoRA { get; set; } Gets or sets whether to use LoRA (Low-Rank Adaptation) for this stage.
bool UseMixedPrecision { get; set; } Gets or sets whether to use mixed precision training (FP16/BF16).
bool UseQLoRA { get; set; } Gets or sets whether to use QLoRA (quantized LoRA) for memory efficiency.
bool UseReferenceModel { get; set; } Gets or sets whether to use a reference model for preference methods.
double AdamBeta1 { get; set; } Gets or sets the Adam beta1 parameter (momentum).
double AdamBeta2 { get; set; } Gets or sets the Adam beta2 parameter (RMSprop-like).
double AdamEpsilon { get; set; } Gets or sets the Adam epsilon for numerical stability.
double ContrastiveMargin { get; set; } Gets or sets the margin for contrastive preference methods.
double DPOBeta { get; set; } Gets or sets the beta parameter for DPO/IPO loss.
double DistillationAlpha { get; set; } Gets or sets the alpha for balancing hard vs soft targets.
double DistillationTemperature { get; set; } Gets or sets the distillation temperature.
double EntropyCoefficient { get; set; } Gets or sets the entropy bonus coefficient for exploration.
double GAELambda { get; set; } Gets or sets the GAE lambda for advantage estimation.
double InitialLossScale { get; set; } Gets or sets the initial loss scale for mixed precision.
double KLPenaltyCoefficient { get; set; } Gets or sets the KL penalty coefficient for RLHF.
double LearningRate { get; set; } Gets or sets the learning rate for this stage.
double LoRAAlpha { get; set; } Gets or sets the LoRA alpha scaling factor.
double LoRADropout { get; set; } Gets or sets the LoRA dropout rate.
double MaxGradientNorm { get; set; } Gets or sets the maximum gradient norm for gradient clipping.
double MinLearningRate { get; set; } Gets or sets the minimum learning rate (for schedulers with decay).
double PPOClipRange { get; set; } Gets or sets the PPO clip range.
double PreferenceLabelSmoothing { get; set; } Gets or sets the label smoothing factor for preference learning.
double RejectionSamplingMinReward { get; set; } Gets or sets the minimum reward threshold for rejection sampling.
double SchedulerPower { get; set; } Gets or sets the power for polynomial decay scheduler.
double SelfPlayTemperature { get; set; } Gets or sets the generation temperature for self-play responses.
double ValueFunctionCoefficient { get; set; } Gets or sets the value function coefficient for PPO.
double WarmupRatio { get; set; } Gets or sets the warmup ratio (fraction of total steps for warmup).
double WeightDecay { get; set; } Gets or sets the weight decay (L2 regularization) coefficient.
int BatchSize { get; set; } Gets or sets the batch size for this stage.
int CheckpointSaveEpochs { get; set; } Gets or sets the checkpoint save interval (in epochs).
int CheckpointSaveSteps { get; set; } Gets or sets the checkpoint save interval (in steps).
int CritiqueRevisionRounds { get; set; } Gets or sets the number of critique-revision rounds.
int Epochs { get; set; } Gets or sets the number of epochs for this stage.
int EvaluationSteps { get; set; } Gets or sets the evaluation interval (in steps).
int GRPOGroupSize { get; set; } Gets or sets the group size for GRPO.
int GradientAccumulationSteps { get; set; } Gets or sets the gradient accumulation steps.
int GradualUnfreezingInterval { get; set; } Gets or sets the epoch interval for gradual unfreezing.
int LoRARank { get; set; } Gets or sets the LoRA rank (dimension of low-rank matrices).
int LoggingSteps { get; set; } Gets or sets the logging interval (in steps).
int MaxCheckpointsToKeep { get; set; } Gets or sets the maximum number of checkpoints to keep.
int MaxSteps { get; set; } Gets or sets the maximum number of steps for this stage.
int NumCycles { get; set; } Gets or sets the number of cycles for cosine scheduler with restarts.
int PPOEpochsPerBatch { get; set; } Gets or sets the number of PPO epochs per batch.
int QLoRABits { get; set; } Gets or sets the quantization bits for QLoRA.
int RandomSeed { get; set; } Gets or sets the random seed for this stage.
int ReferenceModelUpdateInterval { get; set; } Gets or sets the interval (in steps) for updating the reference model.
int RejectionSamplingN { get; set; } Gets or sets the number of samples to generate for rejection sampling.
int RejectionSamplingTopK { get; set; } Gets or sets the top-K samples to keep from rejection sampling.
int RolloutSamples { get; set; } Gets or sets the number of rollout samples per update.
int SelfPlayIterations { get; set; } Gets or sets the number of self-play iterations.
int SelfPlayResponsesPerPrompt { get; set; } Gets or sets the number of responses to generate per prompt in self-play.
int UnfreezeTopNLayers { get; set; } Gets or sets the number of layers to unfreeze from the top.
int WarmupSteps { get; set; } Gets or sets the number of warmup steps.
int? DataShuffleSeed { get; set; } Gets or sets the random seed for data shuffling (for reproducibility).
int? MaxTrainingSamples { get; set; } Gets or sets the maximum number of training samples to use.
string CustomMetricName { get; set; } Gets or sets custom metric name when BestCheckpointMetric is Custom.
string Description { get; set; } Gets or sets a description of what this stage accomplishes.
string Name { get; set; } Gets or sets the name of this stage for logging and identification.
string[] ConstitutionalPrinciples { get; set; } Gets or sets the constitutional principles for CAI stages.
string[] FrozenLayers { get; set; } Gets or sets layer names/patterns to freeze during this stage.
string[] LoRATargetModules { get; set; } Gets or sets which modules to apply LoRA to.
string[] MetricsToTrack { get; set; } Gets or sets the metrics to track during this stage.
string[] Tags { get; set; } Gets or sets tags for categorizing this stage.
string[] TrainableLayers { get; set; } Gets or sets layer names/patterns to unfreeze (train) during this stage.