Sets up the environment and configurations for training a model. Args: data_dir (Optional[Path]): Directory containing the training data. Defaults to None. out_dir (Optional[Path]): Directory to save the outputs. Defaults `models/{model_name}`. gpus (int): Number of
(
data_dir: Path,
out_dir: Optional[Path] = None,
gpus: int = 8,
global_batch_size=512,
learning_rate=4e-4,
micro_batch_size=8,
max_step=48090
* 2, # changes are made to global_batch_size, or dataset, this needs to change.
warmup_steps=2000,
log_step_interval=10,
eval_iters=100,
save_step_interval=4000,
eval_step_interval=4000,
weight_decay=0.1,
beta1=0.9,
beta2=0.95,
grad_clip=1.0,
decay_lr=True,
min_lr=4e-5,
precision: _PRECISION_INPUT = None,
tpu: bool = False,
resume: Union[bool, Path] = False,
model_name='1.5-Pints-2k',
wandb_name: Optional[str] = None,
wandb_project: Optional[str] = None,
tokenizer_dir: Optional[Path] = None,
)
| 211 | |
| 212 | |
| 213 | def setup( |
| 214 | data_dir: Path, |
| 215 | out_dir: Optional[Path] = None, |
| 216 | gpus: int = 8, |
| 217 | global_batch_size=512, |
| 218 | learning_rate=4e-4, |
| 219 | micro_batch_size=8, |
| 220 | max_step=48090 |
| 221 | * 2, # changes are made to global_batch_size, or dataset, this needs to change. |
| 222 | warmup_steps=2000, |
| 223 | log_step_interval=10, |
| 224 | eval_iters=100, |
| 225 | save_step_interval=4000, |
| 226 | eval_step_interval=4000, |
| 227 | weight_decay=0.1, |
| 228 | beta1=0.9, |
| 229 | beta2=0.95, |
| 230 | grad_clip=1.0, |
| 231 | decay_lr=True, |
| 232 | min_lr=4e-5, |
| 233 | precision: _PRECISION_INPUT = None, |
| 234 | tpu: bool = False, |
| 235 | resume: Union[bool, Path] = False, |
| 236 | model_name='1.5-Pints-2k', |
| 237 | wandb_name: Optional[str] = None, |
| 238 | wandb_project: Optional[str] = None, |
| 239 | tokenizer_dir: Optional[Path] = None, |
| 240 | ) -> None: |
| 241 | """ |
| 242 | Sets up the environment and configurations for training a model. |
| 243 | |
| 244 | Args: |
| 245 | data_dir (Optional[Path]): Directory containing the training data. Defaults to None. |
| 246 | out_dir (Optional[Path]): Directory to save the outputs. Defaults `models/{model_name}`. |
| 247 | gpus (int): Number of GPUs to use. Defaults to 8. GOTCHA: Somehow naming this `devices` will be ignored as a CLI param. |
| 248 | global_batch_size (int): This is the training batch size. A larger batch size accumulates more gradients and can be faster. A smaller batch size reduces parallelism, but improves stability. See Llama 3.1 paper https://arxiv.org/pdf/2407.21783 (3.4.1 Initial Pre-Training). Defaults to 512. |
| 249 | learning_rate (float): This is the max learning rate for the optimizer. Defaults to 4e-4. |
| 250 | micro_batch_size (int): Batch size for each device. Increase this to the memory limit of each GPU for faster training. Defaults to 8. |
| 251 | max_step (int): Maximum number of training steps, so that the optimizer can schedule the learning rate. Defaults to 48090 * 2. |
| 252 | warmup_steps (int): Number of steps for learning rate warmup. Defaults to 2000. |
| 253 | log_step_interval (int): Interval for logging training progress. Defaults to 10. |
| 254 | eval_iters (int): Number of iterations for evaluation. Defaults to 100. |
| 255 | save_step_interval (int): Interval for saving the model checkpoints. Defaults to 4000. |
| 256 | eval_step_interval (int): Interval for evaluation during training. Defaults to 4000. |
| 257 | weight_decay (float): Weight decay for regularization. Defaults to 0.1. |
| 258 | beta1 (float): Beta1 parameter for the Adam optimizer. Defaults to 0.9. |
| 259 | beta2 (float): Beta2 parameter for the Adam optimizer. Defaults to 0.95. |
| 260 | grad_clip (float): Gradient clipping value. Most people use 1.0. Defaults to 1.0. |
| 261 | decay_lr (bool): Whether to decay the learning rate during training. Defaults to True. |
| 262 | min_lr (float): Minimum learning rate if decay_lr is True. Defaults to 4e-5. |
| 263 | precision (Optional[Literal['32-true', 'bf16-mixed', 'bf16-true', '16-mixed', '16-true']]): Precision type for training. Defaults to None. |
| 264 | tpu (bool): Whether to use TPU for training. Defaults to False. |
| 265 | resume (Union[bool, Path]): Whether to resume training from a checkpoint. If a Path is provided, training will resume from the specified checkpoint. Defaults to False. |
| 266 | model_name (str): Name of the model. Used for organizing outputs and logging. Defaults to '1.5-Pints-2k'. |
| 267 | wandb_name (Optional[str]): Name for the Weights and Biases run. Defaults to None. |
| 268 | wandb_project (Optional[str]): Project name for Weights and Biases. Defaults to None. |
| 269 | tokenizer_dir (Optional[Path]): Directory containing the tokenizer. Must match the tokenizer used for preparing the data. Defaults to None. |
| 270 | checkpoint_path (Optional[Path]): Path to the checkpoint directory for continuing training. Defaults to None. |
nothing calls this directly
no test coverage detected