trainer.training_configurations
TrainArguments
Bases: OrderedDict
Source code in src/python/easydel/trainer/training_configurations.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
__init__(model_name, num_train_epochs, model_class=None, model_huggingface_repo_id=None, total_batch_size=32, max_training_steps=None, max_evaluation_steps=None, optimizer=EasyDeLOptimizers.ADAMW, scheduler=EasyDeLSchedulers.NONE, learning_rate=5e-05, learning_rate_end=5e-06, gradient_accumulation_steps=1, weight_decay=0.01, label_smoothing_factor=0.0, z_loss=0.0, gradient_checkpointing=EasyDeLGradientCheckPointers.NOTHING_SAVEABLE, max_sequence_length=4096, sharding_array=(1, -1, 1, 1), is_fine_tuning=True, do_train=True, do_eval=False, do_test=False, train_on_inputs=True, backend=None, extra_optimizer_kwargs=None, save_steps=None, save_dir='EasyDeL-Checkpoints', save_total_limit=None, dtype=jnp.bfloat16, param_dtype=jnp.bfloat16, fully_sharded_data_parallel=True, use_wandb=True, custom_rule=None, extra_configs=None, ids_to_pop_from_dataset=None, remove_ckpt_after_load=False, configs_to_initialize_model_class=None, do_last_save=True, model_parameters=None, do_shard_fns=True, track_memory=None, loss_re_mat='', loss_chunk=1024, truncation_mode='keep_end', warmup_steps=500, init_input_shape=(1, 1), step_partition_spec=PartitionSpec(('dp', 'fsdp'), 'sp'), training_time=None, dataloader_num_workers=0, dataloader_pin_memory=False, jax_distributed_config=None, log_all_workers=False, wandb_entity=None, save_optimizer_state=False, step_start_point=None, verbose=True, offload_device=jax.devices('cpu')[0], rapture_config=None, merge_lora_rapture_parameters=True, state_apply_fn_kwarguments_to_model=None, remove_unused_columns=True, force_batch_and_gradient_accumulation_steps_calculation=False, performance_mode=False, neftune_noise_alpha=None, log_grad_norms=True, loaded_model_config_kwargs=None, **kwargs)
The init function is called when the class is instantiated. It sets up the attributes of an object, which are sometimes called fields or properties. The init function can accept arguments, just like a normal function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required | |
model_name |
str
|
str: Specify the model name |
required |
num_train_epochs |
int
|
int: Set the number of epochs for training |
required |
model_huggingface_repo_id |
Optional[str]
|
Optional[str]: Load a pretrained model from the huggingface model hub |
None
|
model_class |
Optional[EasyDeLFlaxPretrainedModel | Type[EasyDeLFlaxPretrainedModel]]
|
Optional[EasyDeLFlaxPretrainedModel]: Pass a model class to the trainer |
None
|
total_batch_size |
int
|
int: Set the batch size of the model |
32
|
max_training_steps |
Optional[int]
|
Optional[int]: Set the maximum total number of training steps across all epochs |
None
|
max_evaluation_steps |
Optional[int]
|
Optional[int]: Set the maximum number of steps to evaluate for |
None
|
optimizer |
AVAILABLE_OPTIMIZERS
|
AVAILABLE_OPTIMIZERS: Specify the optimizer used to train the model |
ADAMW
|
scheduler |
AVAILABLE_SCHEDULERS
|
AVAILABLE_SCHEDULERS: Set the learning rate scheduler |
NONE
|
learning_rate |
Union[int, float]
|
Union[int, float] : Set the learning rate for the optimizer |
5e-05
|
learning_rate_end |
Optional[float]
|
Optional[float]: Set the learning rate at the end of training |
5e-06
|
gradient_accumulation_steps |
int
|
int: Accumulate gradients over multiple batches |
1
|
weight_decay |
float
|
float: Specify the weight decay to be used by the optimizer |
0.01
|
label_smoothing_factor |
float
|
float: Set the label smoothing factor to be used by the loss function |
0.0
|
z_loss |
float
|
float: Set the z loss factor to be used by the loss function |
0.0
|
gradient_checkpointing |
AVAILABLE_GRADIENT_CHECKPOINTS
|
AVAILABLE_GRADIENT_CHECKPOINTS: Determine how to use gradient checkpointing |
NOTHING_SAVEABLE
|
max_sequence_length |
Optional[int]
|
Optional[int]: Set the maximum length of the input sequence |
4096
|
sharding_array |
Union[tuple, int]
|
Union[tuple,int]: Specify the mesh of devices to use for training |
(1, -1, 1, 1)
|
is_fine_tuning |
bool
|
bool: Tell the model whether or not to initialize the weights of |
True
|
do_train |
bool
|
bool: Indicate whether to train the model or not |
True
|
do_eval |
bool
|
bool: Determine whether to run evaluation on the validation set after training |
False
|
do_test |
Optional[bool]
|
Optional[bool]: Determine if the model should be tested |
False
|
train_on_inputs |
bool
|
bool: Use input_ids instead of labels, overrides ignored (-100) tokens in the labels |
True
|
backend |
Optional[str]
|
Optional[str]: Specify the backend of jax |
None
|
extra_optimizer_kwargs |
dict
|
dict: Pass extra arguments to the optimizer |
None
|
save_steps |
Optional[int]
|
Optional[int]: Save the model after every n steps |
None
|
save_dir |
str
|
str: Define the directory where the checkpoints will be saved |
'EasyDeL-Checkpoints'
|
save_total_limit |
Optional[int]
|
int: Set the maximum number of checkpoints to keep, older checkpoints will be deleted |
None
|
dtype |
dtype
|
jnp.dtype: Set the dtype of the model parameters |
bfloat16
|
param_dtype |
dtype
|
jnp.dtype: Specify the data type of the model parameters |
bfloat16
|
fully_sharded_data_parallel |
bool
|
bool: Determine if the model should be fully fsdp or not |
True
|
use_wandb |
bool
|
bool: Enable or disable the wandb logging |
True
|
custom_rule |
Mapping[str, PartitionSpec]
|
Mapping[str, PartitionSpec]: Specify the partitioning rules of the model |
None
|
extra_configs |
Optional[dict]
|
Optional[dict]: Pass extra configurations to the model class |
None
|
ids_to_pop_from_dataset |
Optional[list]
|
Optional[list]: Remove some of the ids from the dataset |
None
|
remove_ckpt_after_load |
bool
|
bool: Remove the checkpoint after loading it |
False
|
configs_to_initialize_model_class |
Optional[dict]
|
Optional[dict]: Pass extra configurations to the model class |
None
|
do_last_save |
bool
|
bool: Save the model after training is complete |
True
|
model_parameters |
Optional[dict]
|
Optional[dict]: Pass the model parameters to the model class |
None
|
do_shard_fns |
bool
|
bool: Shard the model functions across devices |
True
|
track_memory |
Optional[bool]
|
bool: Track the memory usage of the model |
None
|
loss_re_mat |
str
|
str: Specify the regular expression to match the loss function name |
''
|
loss_chunk |
int
|
int: Chunk the loss to avoid memory overflow |
1024
|
truncation_mode |
Literal['keep_end', 'keep_start']
|
typing.Literal["keep_end", "keep_start"]: Determine if the input is left padded or not and which side of the array should remain in case of using maximum padding. |
'keep_end'
|
warmup_steps |
int
|
int: Specify the number of steps to warm up the learning rate |
500
|
init_input_shape |
Tuple[int, int]
|
Tuple[int, int]: Initialize the model with a shape that is not (batch_size, length) |
(1, 1)
|
step_partition_spec |
PartitionSpec
|
PartitionSpec: Partition the model for training |
PartitionSpec(('dp', 'fsdp'), 'sp')
|
training_time |
Optional[str]
|
Optional[str]: Set a time limit for the training process |
None
|
dataloader_num_workers |
Optional[int]
|
Optional[int]: Set the number of workers used by pytorch's |
0
|
dataloader_pin_memory |
Optional[bool]
|
Optional[bool]: Pin the memory of the dataloader |
False
|
jax_distributed_config |
Optional[dict]
|
Optional[dict]: Configure the jax distributed backend |
None
|
log_all_workers |
bool
|
bool: Log all workers in wandb, |
False
|
wandb_entity |
Optional[str]
|
Optional[str]: Specify the entity to use when logging to weights & biases |
None
|
|
save_optimizer_state
|
bool: when ever to save optimizer state and other args in checkpoint |
required |
step_start_point |
Optional[int]
|
Optional[int]: start training from given step for example instead of starting training from step 0 it will start from 20000 and leave the data behind |
None
|
verbose |
bool
|
bool: when ever to turn verbose mode of or on |
True
|
offload_device |
Device
|
jax.Device: device to be used to offload parameters on |
devices('cpu')[0]
|
rapture_config |
Optional[EasyDeLXRapTureConfig]
|
Optional[EasyDeLXRaptureConfig]: LoRA Config for models |
None
|
merge_lora_rapture_parameters |
bool
|
bool: whenever to merge lora parameters with original parameters before saving |
True
|
state_apply_fn_kwarguments_to_model |
Optional[dict]
|
Optional[dict]: state_apply_fn_kwarguments_to_model is a dictionary that be used to apply the parameters and extra things that you want to deliver to model. |
None
|
remove_unused_columns |
bool
|
bool: when ever to remove the unused data columns from dataset |
True
|
force_batch_and_gradient_accumulation_steps_calculation |
bool
|
bool: whether to force batch and gradient to be applied as total batch_size (e.g total_batch_size = total_batch_size * gradient_accumulation_steps be applied) |
False
|
performance_mode |
bool
|
bool: whether to optimize the whole training process this will cut off some logging options and optimize training process. |
False
|
neftune_noise_alpha |
Optional[float]
|
Optional[float]: If not |
None
|
loaded_model_config_kwargs |
Optional[dict]
|
Optional[dict]: config key arguments to be passed to the model while being loaded from checkpoint |
None
|
**kwargs |
Pass keyword, variable-length argument list |
{}
|
Source code in src/python/easydel/trainer/training_configurations.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
ckpt_path_exists()
The ckpt_path_exists function checks to see if the path exists. If it does not, then it creates a new directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A path |
Source code in src/python/easydel/trainer/training_configurations.py
445 446 447 448 449 450 451 452 453 454 455 |
|
get_board()
The get_board function is a helper function that returns a TensorBoard object. The TensorBoard object is used to log the training and validation loss, as well as the accuracy of the model during training. The get_board function takes no arguments, and returns an instance of torch.utils.tensorboard SummaryWriter class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A summary-writer object |
Source code in src/python/easydel/trainer/training_configurations.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
get_mesh()
The get_mesh function is used to create a mesh object that can be used to define the geometry of the device. The mesh object contains two arrays: a list of vertices and a list of faces. Each face is defined by three indices, which correspond to three vertices in the vertex array. The get_mesh function is called when creating an instance of DeviceGeometry, which is then passed into an instance of DeviceSimulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the object itself |
required |
Returns:
Type | Description |
---|---|
A mesh object with the device array shape and the mesh names |
Source code in src/python/easydel/trainer/training_configurations.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
|
get_meter_dict()
The get_meter_dict function is used to return a dictionary of the hyperparameters. The function iterates through all the attributes in the class and returns a dictionary with the key as "hyperparameters/{k}" and value as v for each attribute k,v in self.dict if it is an instance of int, float, str, bool or torch.Tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A dictionary of hyperparameters |
Source code in src/python/easydel/trainer/training_configurations.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
get_path()
The get_path function returns a pathlib.Path object, which is a class that represents file paths and provides methods for interacting with the files at those paths. The get_path function takes no arguments and returns an instance of the Path class initialized with two arguments: self.save_dir (a string) and self.model_name (also a string). The save directory is the directory where we'll store our model checkpoints, while the model name will be used to create unique filenames for each checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A pathlib |
Source code in src/python/easydel/trainer/training_configurations.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
get_streaming_checkpointer()
The get_streaming_checkpointer function is used to save the model's weights. The streaming checkpointer saves the model's weights in a file called "checkpoint" and then saves a copy of that file with an incrementing number appended to it (e.g., checkpoint_001, checkpoint_002, etc.). This allows you to keep multiple versions of your trained models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A CheckpointManager object |
Source code in src/python/easydel/trainer/training_configurations.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
get_wandb_init()
The get_wandb_init function is a helper function that returns the wandb.init() call with the project name, config object, and tags set to appropriate values for this model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Pass the class instance to the function |
required |
Returns:
Type | Description |
---|---|
Run | RunDisabled | None
|
A wandb or None |
Source code in src/python/easydel/trainer/training_configurations.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|