File size: 30,697 Bytes
feba2ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 |
"""
Pico Language Model Trainer
This Trainer implements a minimalistic end-to-end training pipeline of the Pico language model with
distributed training support via Lightning Fabric. It provides a modular and configurable training
pipeline with the features:
- Configuration Management: YAML-based configuration for all aspects of training
- Distributed Training: Multi-GPU support via Lightning Fabric
- Checkpointing: Regular model saving and training state recovery
- Evaluation: Periodic model evaluation on validation datasets
- Logging: Comprehensive metric tracking and experiment monitoring
- Optimization: Support for gradient accumulation, clipping, and LR scheduling
"""
import logging
import os
import platform
from typing import Any, Dict
import lightning as L
import psutil
import torch
import torch.nn.functional as F
import yaml
from datasets import Dataset, load_dataset
from lightning.fabric.utilities.rank_zero import rank_zero_only
from src.checkpointing import (
compute_learning_dynamics_states,
load_checkpoint,
save_checkpoint,
save_evaluation_results,
save_learning_dynamics_states,
)
from src.evaluation import run_evaluation
from src.training.utils import (
initialize_configuration,
initialize_dataloader,
initialize_dataset,
initialize_fabric,
initialize_hf_checkpointing,
initialize_logging,
initialize_lr_scheduler,
initialize_model,
initialize_optimizer,
initialize_run_dir,
initialize_tokenizer,
initialize_wandb,
)
from src.training.utils.logging import pretty_print_yaml_config
class Trainer:
def __init__(self, config_path: str):
"""
Initializes the Trainer class. This Trainer class implements a `train` method, which is the
main entry point for training the Pico model. Before calling `train`, the Trainer class
initializes the following:
- Configuration loading and validation
- Model, optimizer, and dataset setup
- Logging and experiment tracking setup
- Checkpoint management
Args:
config_path (str): Path to the YAML configuration file containing any overrides.
"""
########################################################
#
# Basic Initialization of Configs, Fabric, Model, Optimizer, etc.
#
########################################################
# Setup Config
self.configs = initialize_configuration(config_path)
# Setup Run Directory (i.e. where we store checkpoints, logs, etc.)
initialize_run_dir(checkpointing_config=self.configs["checkpointing"])
# Setup Logger
if self.configs["monitoring"].save_to_wandb:
wandb_logger = initialize_wandb(
monitoring_config=self.configs["monitoring"],
checkpointing_config=self.configs["checkpointing"],
)
else:
wandb_logger = None
# Setup Fabric
self.fabric = initialize_fabric(
training_config=self.configs["training"],
wandb_logger=wandb_logger,
)
L.seed_everything(42, verbose=False)
# Optimize for Tensor Cores on RTX 5090
if self.fabric.device.type == "cuda":
torch.set_float32_matmul_precision(
"high"
) # Best performance for Tensor Cores
print(
"Enabled Tensor Core optimization: torch.set_float32_matmul_precision('high')"
)
# Set up logging
self.logger = initialize_logging(
monitoring_config=self.configs["monitoring"],
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
)
# Setup Model, Optimizer, and Dataloaders
self.model = initialize_model(model_config=self.configs["model"])
self.optimizer = initialize_optimizer(
training_config=self.configs["training"], model=self.model
)
self.lr_scheduler = initialize_lr_scheduler(
training_config=self.configs["training"], optimizer=self.optimizer
)
# Wrap model and optimizer with Fabric
self.model, self.optimizer = self.fabric.setup(self.model, self.optimizer)
# Setup HuggingFace Checkpointing
if self.configs["checkpointing"].save_to_hf:
initialize_hf_checkpointing(
checkpointing_config=self.configs["checkpointing"], fabric=self.fabric
)
########################################################
#
# Boilerplate to deal with loading/resuming from checkpoints
#
########################################################
self.should_load_checkpoint = self.configs["checkpointing"].training.auto_resume
# Possibly load a checkpoint
if self.should_load_checkpoint:
resume_checkpoint = load_checkpoint(
checkpointing_config=self.configs["checkpointing"],
checkpoint_step="latest",
fabric=self.fabric,
model=self.model,
optimizer=self.optimizer,
lr_scheduler=self.lr_scheduler,
)
if resume_checkpoint:
(
self.model,
self.optimizer,
self.lr_scheduler,
self.initial_batch_step,
) = resume_checkpoint
else:
self.initial_batch_step = 0
else:
self.initial_batch_step = 0
########################################################
#
# Initialization of Dataset & DataLoader (possibly fast-forwarding to correct batch)
#
########################################################
self.train_dataset, fast_forward_steps = initialize_dataset(
data_config=self.configs["data"],
fabric=self.fabric,
initial_batch_step=self.initial_batch_step,
return_fast_forward_steps=True,
)
self.train_dataloader = initialize_dataloader(
data_config=self.configs["data"],
training_config=self.configs["training"],
fabric=self.fabric,
dataset=self.train_dataset,
)
self.train_dataloader = self.fabric.setup_dataloaders(
self.train_dataloader, use_distributed_sampler=False
)
self.tokenizer = initialize_tokenizer(data_config=self.configs["data"])
# NOTE: We may need to fast-forward the iterator to the correct step so that we can
# continue from the correct batch of data we would have seen had training not
# previously stopped.
train_iterator = iter(self.train_dataloader)
if fast_forward_steps > 0:
fast_forward_sub_steps = (
fast_forward_steps
* self.configs["training"].optimization.gradient_accumulation_steps
)
for _ in range(fast_forward_sub_steps):
next(train_iterator)
self.train_iterator = train_iterator
# NOTE: Sychronizing processes after fast-forwarding iterator
self.fabric.barrier()
########################################################
#
# Helper flags used during training for checkpointing and evaluation
#
########################################################
# Helper flag to determine if we should evaluate the model
self.should_evaluate = (
self.configs["evaluation"].metrics is not None
and len(self.configs["evaluation"].metrics) > 0
)
self.should_compute_learning_dynamics = (
self.configs["checkpointing"].learning_dynamics.layer_suffixes is not None
and len(self.configs["checkpointing"].learning_dynamics.layer_suffixes) > 0
)
if self.should_compute_learning_dynamics:
if self.configs["checkpointing"].learning_dynamics.eval_data is not None:
self.learning_dynamics_eval_dataset = load_dataset(
self.configs["checkpointing"].learning_dynamics.eval_data,
split="val",
)
else:
self.learning_dynamics_eval_dataset = None
def train(self) -> None:
"""Execute the main training pipeline.
This method orchestrates the complete training process by:
1. Creating an initial checkpoint to save the starting state and evaluate the model as a
baseline
2. Running the main training loop via `_training_loop`
3. Handling final checkpointing and evaluation
The training progress is tracked through checkpoints and evaluations
at intervals specified in the configuration.
"""
########################################################
#
# Initial Checkpointing and Evaluation
#
########################################################
# Save Initial Checkpoint -- If the checkpoint already exists, this performs a no-op
save_checkpoint(
configs=self.configs,
checkpoint_step=self.initial_batch_step,
fabric=self.fabric,
model=self.model,
optimizer=self.optimizer,
lr_scheduler=self.lr_scheduler,
tokenizer=self.tokenizer,
)
# Save Initial Evaluation Results
if self.should_evaluate:
if self.initial_batch_step == 0:
evaluation_results = run_evaluation(
evaluation_config=self.configs["evaluation"],
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
)
self._log_evaluation_results(
evaluation_results, self.initial_batch_step
)
save_evaluation_results(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
evaluation_results=evaluation_results,
checkpoint_step=self.initial_batch_step,
)
else:
# NOTE: If the run crashed while evaluating, we need to restart the evaluation
eval_results_path = os.path.join(
self.configs["checkpointing"].evaluation.eval_results_dir,
f"step_{self.initial_batch_step}.json",
)
if not os.path.exists(eval_results_path):
evaluation_results = run_evaluation(
evaluation_config=self.configs["evaluation"],
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
)
self._log_evaluation_results(
evaluation_results, self.initial_batch_step
)
save_evaluation_results(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
evaluation_results=evaluation_results,
checkpoint_step=self.initial_batch_step,
)
########################################################
#
# Main Training Loop (see `_training_loop` for details)
#
########################################################
if self.initial_batch_step < self.configs["training"].max_steps:
self._log_training_configuration()
final_step = self._training_loop()
else:
final_step = self.initial_batch_step
########################################################
#
# Final Checkpointing and Evaluation
#
########################################################
# Save Learning Dynamics States
if self.should_compute_learning_dynamics:
if self.learning_dynamics_eval_dataset is not None:
self.log(f"Step {final_step} -- π Saving Learning Dynamics")
learning_dynamics_val_states = compute_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
dataset=self.learning_dynamics_eval_dataset,
compute_gradients=True,
)
save_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
learning_dynamics_states=learning_dynamics_val_states,
checkpoint_step=final_step,
prefix="val",
)
# Handle checkpointing and final evaluation
if final_step % self.configs["checkpointing"].save_every_n_steps != 0:
self.log(f"Step {final_step} -- πΎ Saving Final Checkpoint")
save_checkpoint(
configs=self.configs,
checkpoint_step=final_step,
fabric=self.fabric,
model=self.model,
optimizer=self.optimizer,
lr_scheduler=self.lr_scheduler,
tokenizer=self.tokenizer,
)
# Final evaluation
if self.should_evaluate:
evaluation_results = run_evaluation(
evaluation_config=self.configs["evaluation"],
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
)
self._log_evaluation_results(evaluation_results, final_step)
save_evaluation_results(
checkpointing_config=self.configs["checkpointing"],
checkpoint_step=final_step,
fabric=self.fabric,
evaluation_results=evaluation_results,
)
self.log(f"π Training complete! Final step: {final_step}")
if final_step < self.configs["training"].max_steps:
self.log(
f"\t Note: Training stopped before max steps ({self.configs['training'].max_steps})",
level=logging.WARNING,
)
# Cleanup distributed training
self.fabric.barrier()
if torch.cuda.is_available():
torch.cuda.empty_cache()
if torch.distributed.is_initialized():
torch.distributed.destroy_process_group()
del self.train_dataloader # NOTE: shutting down worker nodes
self.fabric.barrier()
def _training_loop(self) -> int:
"""Execute the main training loop.
This method orchestrates the core training loop and includes the following features:
- Gradient accumulation
- Gradient clipping
- Periodic model evaluation and checkpointing
- Learning Dynamics Checkpointing
- Learning rate scheduling
- Logging of training metrics including loss and learning rate
- Handling of infinite/NaN losses
Returns:
int: The final step count reached during training.
NOTE: A complete training run should match the configured max_steps.
"""
# Setup training loop variables
batch_step = self.initial_batch_step
# NOTE: these are used to compute the average loss over a training interval.
# This is more accurate than using the loss at the end of the interval.
interval_loss = torch.tensor(0.0, device=self.fabric.device)
interval_steps = torch.tensor(0, device=self.fabric.device)
interval_inf_or_nan_count = torch.tensor(0, device=self.fabric.device)
if self.should_compute_learning_dynamics:
# NOTE: we basically re-construct the full batch here so that we can compute learning dynamics
training_batch = {"input_ids": []}
# NOTE: determine what sub-batch we should start from
initial_sub_batch_step = (
batch_step
* self.configs["training"].optimization.gradient_accumulation_steps
)
###############################################################
#
# Core loop starts here
# NOTE: the ratio between sub_batch_step and batch_step
# is the configured number of gradient_accumulation_steps
# i.e. with 32 configured gradient accumulation steps,
# there are 32 sub_batch_steps for each batch_step
#
###############################################################
for sub_batch_step, sub_batch in enumerate(
self.train_iterator, start=initial_sub_batch_step
):
# NOTE: We want to store the entire training batch whenever we are computing learning dynamics
# and we are at a checkpointing step.
should_store_training_batch = self.should_compute_learning_dynamics and (
batch_step % self.configs["checkpointing"].save_every_n_steps == 0
)
########################################################
#
# Forward Pass
#
########################################################
_input_ids = torch.tensor(sub_batch["input_ids"], device=self.fabric.device)
input_ids = _input_ids[:, :-1]
labels = _input_ids[:, 1:]
if should_store_training_batch:
gathered_input_ids = self.fabric.all_gather(_input_ids)
# NOTE: On multi-GPU, we need to reshape the input_ids to be a 2D tensor; on
# a single GPU, the input_ids are already a 2D tensor.
if self.fabric.world_size > 1:
gathered_input_ids = gathered_input_ids.reshape(
-1, *gathered_input_ids.shape[2:]
)
training_batch["input_ids"].extend(gathered_input_ids.tolist())
# Forward pass
model_output, _ = self.model(input_ids)
model_output = model_output.transpose(1, 2)
########################################################
#
# Gradient accumulation
#
########################################################
should_accumulate_gradients = (sub_batch_step + 1) % self.configs[
"training"
].optimization.gradient_accumulation_steps != 0
with self.fabric.no_backward_sync(
self.model, enabled=should_accumulate_gradients
):
loss = F.cross_entropy(model_output, labels)
self.fabric.backward(
loss
/ self.configs["training"].optimization.gradient_accumulation_steps,
model=self.model,
)
if torch.isnan(loss) or torch.isinf(loss):
interval_inf_or_nan_count += 1
else:
interval_loss += loss.item()
interval_steps += 1
# NOTE: if we are not accumulating gradients, we should skip the logging and optimization steps
if should_accumulate_gradients:
continue
########################################################
#
# Logging
#
########################################################
if batch_step % self.configs["monitoring"].logging.log_every_n_steps == 0:
self._log_training_metrics(
interval_loss=interval_loss,
interval_steps=interval_steps,
interval_inf_or_nan_count=interval_inf_or_nan_count,
batch_step=batch_step,
)
interval_loss = torch.tensor(0.0, device=self.fabric.device)
interval_steps = torch.tensor(0, device=self.fabric.device)
interval_inf_or_nan_count = torch.tensor(0, device=self.fabric.device)
########################################################
#
# Learning Dynamics Checkpointing
#
########################################################
if batch_step % self.configs["checkpointing"].save_every_n_steps == 0:
if self.should_compute_learning_dynamics:
self.log(f"Step {batch_step} -- π Saving Learning Dynamics")
# Training Batch Learning Dynamics
training_batch_dataset = Dataset.from_dict(training_batch)
learning_dynamics_train_states = compute_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
dataset=training_batch_dataset,
compute_gradients=True,
)
save_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
checkpoint_step=batch_step,
prefix="train",
fabric=self.fabric,
learning_dynamics_states=learning_dynamics_train_states,
learning_dynamics_dataset=training_batch_dataset,
tokenizer=self.tokenizer,
)
training_batch = {
"input_ids": []
} # Resetting training_batch for next training batch
# Validation Data Learning Dynamics
if self.learning_dynamics_eval_dataset is not None:
learning_dynamics_val_states = compute_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
dataset=self.learning_dynamics_eval_dataset,
compute_gradients=True,
)
save_learning_dynamics_states(
checkpointing_config=self.configs["checkpointing"],
checkpoint_step=batch_step,
prefix="val",
fabric=self.fabric,
learning_dynamics_states=learning_dynamics_val_states,
)
########################################################
#
# Optimization step
#
########################################################
self.optimizer.step()
self.optimizer.zero_grad()
self.lr_scheduler.step()
batch_step += 1
########################################################
#
# Training Checkpointing and evaluation
#
########################################################
if batch_step % self.configs["checkpointing"].save_every_n_steps == 0:
self.log(f"Step {batch_step} -- πΎ Saving Checkpoint")
save_checkpoint(
configs=self.configs,
checkpoint_step=batch_step,
fabric=self.fabric,
model=self.model,
optimizer=self.optimizer,
lr_scheduler=self.lr_scheduler,
tokenizer=self.tokenizer,
)
if self.should_evaluate:
evaluation_results = run_evaluation(
evaluation_config=self.configs["evaluation"],
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
model=self.model,
)
if evaluation_results is not None:
self._log_evaluation_results(evaluation_results, batch_step)
save_evaluation_results(
checkpointing_config=self.configs["checkpointing"],
fabric=self.fabric,
evaluation_results=evaluation_results,
checkpoint_step=batch_step,
)
# Break if we've reached training steps
if batch_step >= self.configs["training"].max_steps:
break
return batch_step
########################################################
#
# Trainer Logging Functinalities
#
########################################################
def _log_training_metrics(
self,
interval_loss: torch.Tensor,
interval_steps: torch.Tensor,
interval_inf_or_nan_count: torch.Tensor,
batch_step: int,
):
"""
Gathers together the training metrics computed across all processes in distributed training
and logs them in a tree-style format.
"""
gathered_interval_loss = self.fabric.all_reduce(
interval_loss, reduce_op="sum"
).item()
gathered_interval_inf_or_nan_count = self.fabric.all_reduce(
interval_inf_or_nan_count, reduce_op="sum"
).item()
gathered_interval_steps = self.fabric.all_reduce(
interval_steps, reduce_op="sum"
).item()
avg_loss = (
gathered_interval_loss / gathered_interval_steps
if gathered_interval_steps > 0
else float("inf")
)
self.fabric.log("train/loss", avg_loss, step=batch_step)
self.fabric.log(
"trainer/inf_or_nan_count",
gathered_interval_inf_or_nan_count,
step=batch_step,
)
self.fabric.log(
"trainer/learning_rate",
self.lr_scheduler.get_last_lr()[0],
step=batch_step,
)
# Log to console in tree format
self.log(f"Step {batch_step} -- π Training Metrics")
self.log(f"βββ Loss: {avg_loss:.4f}")
self.log(f"βββ Learning Rate: {self.lr_scheduler.get_last_lr()[0]:.2e}")
self.log(f"βββ Inf/NaN count: {gathered_interval_inf_or_nan_count}")
def _log_evaluation_results(
self, evaluation_results: Dict[str, Any], batch_step: int
):
"""Log model evaluation metrics to experiment tracking system and console."""
self.log(f"Step {batch_step} -- π Evaluation Results")
for i, (metric, result) in enumerate(evaluation_results.items()):
prefix = "βββ" if i == len(evaluation_results) - 1 else "βββ"
self.log(f"{prefix} {metric}: {result}")
self.fabric.log(f"eval/{metric}", result, step=batch_step)
def _log_training_configuration(self):
"""
Log training configuration details as well as runtime information about the hardware,
software, and batch settings.
This function is called at the beginning of the training loop to provide a summary of the
training configuration.
"""
total_params = sum(p.numel() for p in self.model.parameters())
trainable_params = sum(
p.numel() for p in self.model.parameters() if p.requires_grad
)
global_batch_size = self.configs["data"].dataloader.batch_size
per_device_batch_size = self.train_dataloader.batch_size
gradient_accumulation_steps = self.configs[
"training"
].optimization.gradient_accumulation_steps
device_type = ""
fabric_device = str(self.fabric.device)
if torch.cuda.is_available() and "cuda" in fabric_device:
device_type = torch.cuda.get_device_name(self.fabric.device)
elif torch.backends.mps.is_available() and "mps" in fabric_device:
device_type = "MPS (Apple Silicon)"
else:
device_type = "CPU"
training_config_path = os.path.join(
self.configs["checkpointing"].runs_dir,
self.configs["checkpointing"].run_name,
"training_config.yaml",
)
if os.path.exists(training_config_path):
self.log("=" * 50)
self.log("β¨ Training Configuration")
self.log("=" * 50)
training_config = yaml.safe_load(open(training_config_path, "r"))
pretty_print_yaml_config(self.logger, training_config)
self.log("=" * 50)
self.log("β Runtime Summary:")
self.log("=" * 50)
self.log(f"Starting from step: {self.initial_batch_step}")
self.log("Model Setup:")
self.log(f"ββ Total Parameters: {total_params:,}")
self.log(f"ββ Trainable Parameters: {trainable_params:,}")
self.log("Distributed Setup:")
self.log(f"ββ Number of Devices: {self.fabric.world_size}")
self.log(f"ββ Device Type: {device_type}")
self.log(
f"ββ Available Memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.2f} GB"
if torch.cuda.is_available()
else f"ββ Available Memory: {psutil.virtual_memory().total / 1e9:.2f} GB"
)
self.log("Software Setup:")
self.log(f"ββ Python Version: {platform.python_version()}")
self.log(f"ββ PyTorch Version: {torch.__version__}")
self.log(
f"ββ CUDA Version: {torch.version.cuda if torch.cuda.is_available() else 'N/A'}"
)
self.log(f"ββ Operating System: {platform.system()} {platform.release()}")
self.log("Batch Size Configuration:")
self.log(f"ββ Global Batch Size: {global_batch_size}")
self.log(f"ββ Per Device Batch Size: {per_device_batch_size}")
self.log(f"ββ Gradient Accumulation Steps: {gradient_accumulation_steps}")
self.log("=" * 50)
@rank_zero_only
def log(self, msg: str, level: int = logging.INFO) -> None:
"""NOTE: Log messages only from rank zero process."""
self.logger.log(level, msg)
|