When performing fine-tuning, you can use the Hyperparameters class to control the training process. This includes settings for standard training (epochs, batch size, learning rate), early stopping logic, and Low-Rank Adaptation (LoRA) specific parameters.
Standard Training Parameters
train_batch_size (int): The number of training examples included in a single training pass.train_epochs (int): The total number of epochs to train for.learning_rate (float): The learning rate used during training.
Early Stopping
To prevent overfitting, you can configure early stopping:
early_stopping_patience (int): Stops training if the loss metric does not improve beyond the early_stopping_threshold after this many evaluation cycles.early_stopping_threshold (float): The minimum amount the loss must improve to prevent early stopping.
LoRA (Low-Rank Adaptation) Parameters
If using LoRA, you can tune the following:
lora_alpha (int): Controls the scaling factor for LoRA updates. Higher values make updates more impactful.lora_rank (int): Specifies the rank for low-rank matrices. Lower ranks reduce parameter count but may limit model flexibility.lora_target_modules (LoraTargetModules): The specific combination of LoRA modules to target.
from cohere.finetuning.finetuning.types import Hyperparameters
hyperparameters = Hyperparameters(
train_batch_size=32,
train_epochs=3,
learning_rate=0.0001,
lora_rank=8,
lora_alpha=16,
early_stopping_patience=2,
early_stopping_threshold=0.01
)