Trainers¶
Forgather provides a hierarchy of trainer classes for single-GPU through multi-node distributed training.
| Trainer | Use case |
|---|---|
Trainer |
Single-GPU, the fast path for small-model experiments |
DDPTrainer |
Multi-GPU DistributedDataParallel, with optional PostLocalSGD |
FSDP2Trainer |
FSDP-2 sharded data parallel with CPU offload support |
PipelineTrainer |
Pipeline parallelism for bandwidth-limited environments |
For a complete reference of every training argument and constructor parameter across all trainers, see also:
Core Types¶
Shared types and protocols used across all trainers.
forgather.ml.distributed.DistributedEnvironment
¶
Bases: DistributedEnvInterface
Initialize and manage the PyTorch distributed training environment.
This class handles the complete setup of distributed training, including: - Synchronizing with environment variables set by launchers (torchrun, etc.) - Setting up the appropriate device (GPU or CPU) - Initializing the torch.distributed process group
The distributed environment must be initialized before any torch.distributed calls can be made. In forgather configurations, this is typically included as an early dependency to ensure proper initialization order.
Environment Variable Behavior: - If environment variables are set (e.g., by torchrun), they override the values passed to init - If environment variables are not set, this class exports the init values to the environment for consistency
Device Selection: - With GPU available and no_accelerator=False: Uses GPU with nccl backend - With no_accelerator=True or no GPU: Uses CPU with gloo backend - Device is automatically assigned based on local_rank (or device_map)
Attributes: rank: Global rank of this process local_rank: Rank within the local node world_size: Total number of processes local_world_size: Number of processes on this node master_addr: Address of rank 0 for rendezvous master_port: Port for rendezvous backend: Distributed backend ("nccl", "gloo", etc.) device: Device string for this rank (e.g., "cuda:0", "cpu") device_type: Device type string (e.g., "cuda", "cpu") use_accelerator: Whether to use GPU acceleration
Example: In a forgather YAML configuration::
distributed_env: &distributed_env !singleton:forgather.ml.distributed:DistributedEnvironment
backend: "nccl"
For CPU-only testing::
distributed_env: &distributed_env !singleton:forgather.ml.distributed:DistributedEnvironment
no_accelerator: True
Source code in src/forgather/ml/distributed.py
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 755 756 757 758 759 760 761 762 | |
__init__(rank=0, local_rank=0, world_size=1, local_world_size=1, master_addr='localhost', master_port=29501, backend=None, log_level='INFO', device_map=None, always=True, no_accelerator=False)
¶
Initialize the distributed environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rank
|
int
|
Global rank. Default 0, typically overridden by launcher environment. |
0
|
local_rank
|
int
|
Local rank within node. Default 0. |
0
|
world_size
|
int
|
Total number of processes. Default 1. |
1
|
local_world_size
|
int
|
Number of processes per node. Default 1. |
1
|
master_addr
|
str
|
Rendezvous address for rank 0. Default "localhost". |
'localhost'
|
master_port
|
int
|
Rendezvous port. Default 29501. |
29501
|
backend
|
str or None
|
Distributed backend. If None, auto-selected based on device (nccl for GPU, gloo for CPU). |
None
|
log_level
|
str
|
Logging level for the distributed module. Default "INFO". |
'INFO'
|
device_map
|
dict or None
|
Mapping from rank to device index for custom device assignment. If None, uses local_rank. |
None
|
always
|
bool
|
If True, initialize distributed even for single process. Useful for consistent behavior across configurations. Default True. |
True
|
no_accelerator
|
bool
|
If True, force CPU execution even if GPU is available. Useful for testing distributed configurations without GPUs. Default False. |
False
|
Source code in src/forgather/ml/distributed.py
forgather.ml.trainer.trainer_types.MinimalTrainingArguments
dataclass
¶
Minimal training configuration compatible with HuggingFace Trainer.
Provides a subset of transformers.TrainingArguments sufficient for basic
training. This is the base configuration class; extend it for additional
features rather than adding fields here.
Direct subclasses: BaseTrainingArguments (checkpoint control, PyTorch
optimisations) and TrainingArguments (simple single-GPU memory options).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory where model predictions and checkpoints are written. |
OUTPUTDIR_NAME
|
logging_dir
|
str or None
|
TensorBoard log directory. Defaults to |
None
|
per_device_train_batch_size
|
int
|
Training batch size per device. Effective global batch size is
|
16
|
per_device_eval_batch_size
|
int
|
Evaluation batch size per device. |
16
|
num_train_epochs
|
int
|
Total training epochs (may be fractional, e.g. |
1
|
max_steps
|
int
|
If > 0, total optimiser steps to perform (overrides |
-1
|
device
|
Any
|
Device to use ( |
None
|
seed
|
int
|
Random seed for reproducibility. Default |
-1
|
use_cpu
|
bool
|
Force CPU usage even when CUDA is available. |
False
|
epoch_train_steps
|
int
|
Fallback epoch length when the dataset does not support |
100000
|
dataloader_num_workers
|
int
|
Subprocesses for data loading. |
0
|
dataloader_pin_memory
|
bool
|
Pin memory in DataLoader for faster GPU transfer. |
True
|
dataloader_persistent_workers
|
bool
|
Keep worker processes alive between epochs (faster, uses more RAM). |
False
|
dataloader_prefetch_factor
|
int or None
|
Batches prefetched per worker. Defaults to |
None
|
dataloader_drop_last
|
bool
|
Drop the last incomplete batch when the dataset is not evenly divisible. |
False
|
eval_strategy
|
str
|
When to run evaluation: |
'no'
|
eval_steps
|
int
|
Evaluation frequency in steps (when |
100
|
eval_delay
|
int
|
Epochs or steps to wait before the first evaluation. |
0
|
logging_strategy
|
str
|
When to log metrics: |
'steps'
|
logging_steps
|
int
|
Logging frequency in steps (when |
50
|
logging_first_step
|
bool
|
Log metrics at the very first global step. |
False
|
torch_compile
|
bool
|
Compile the model with |
False
|
torch_compile_backend
|
str or None
|
Backend for |
None
|
torch_compile_mode
|
str or None
|
Compilation mode: |
'default'
|
torch_compile_dynamic
|
bool
|
Allow dynamic shapes in the compiled model. |
True
|
torch_compile_full_graph
|
bool
|
Force compilation of the entire model as a single graph. |
False
|
max_grad_norm
|
float or None
|
Maximum gradient norm for clipping. |
None
|
gradient_accumulation_steps
|
int
|
Accumulate gradients over this many steps before an optimiser update. |
1
|
save_strategy
|
str
|
Checkpoint save strategy: |
'steps'
|
save_steps
|
int
|
Checkpoint save frequency in steps (when |
1000
|
save_total_limit
|
int
|
Maximum number of checkpoints to keep; oldest are deleted first. |
2
|
save_safetensors
|
bool
|
Write weights as Safetensors (safer and HF-compatible) rather than pickle. |
True
|
save_on_each_node
|
bool
|
In multi-node training, save on every node rather than only rank 0. Do not enable when using shared storage. |
False
|
overwrite_output_dir
|
bool
|
Overwrite |
False
|
resume_from_checkpoint
|
bool or str
|
|
True
|
load_best_model_at_end
|
bool
|
Restore the best checkpoint at the end of training. Requires
|
False
|
metric_for_best_model
|
str
|
Metric used to compare checkpoints when |
'loss'
|
greater_is_better
|
bool or None
|
Whether a higher metric value is better. Auto-determined from the metric
name when |
None
|
lr_scheduler_type
|
str
|
LR scheduler type for the built-in AdamW path ( |
'linear'
|
lr_scheduler_kwargs
|
dict or None
|
Additional keyword arguments forwarded to the LR scheduler constructor. |
None
|
warmup_steps
|
int
|
Linear warmup steps from 0 to |
0
|
learning_rate
|
float
|
Initial learning rate for the built-in AdamW optimiser. |
5e-05
|
weight_decay
|
float
|
Weight decay applied to all parameters except bias and LayerNorm weights. |
0.0
|
adam_beta1
|
float
|
Beta1 for the built-in AdamW optimiser. |
0.9
|
adam_beta2
|
float
|
Beta2 for the built-in AdamW optimiser. |
0.999
|
adam_epsilon
|
float
|
Epsilon for the built-in AdamW optimiser. |
1e-08
|
gradient_checkpointing
|
bool
|
Enable activation checkpointing on models that support the HF API.
Pass |
False
|
Source code in src/forgather/ml/trainer/trainer_types.py
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 | |
forgather.ml.trainer.trainer_types.TrainerState
dataclass
¶
Trainer state tracking training progress and configuration.
Maintains compatibility with HuggingFace Trainer API for easier porting. Passed to callbacks to allow them to inspect and log training progress.
Key training progress fields: - global_step: Total optimizer updates since start (0-indexed) - raw_epoch: Integer epoch counter (increments at end of each dataset iteration) - epoch_start_step: Global step when current epoch started - epoch: Continuous epoch value = raw_epoch + fractional progress through current epoch Computed as: epoch = raw_epoch + (global_step - epoch_start_step) / epoch_train_steps
Best model tracking (for load_best_model_at_end): - best_metric: Best metric value seen during training - best_model_checkpoint: Path to checkpoint with best metric
See: https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_callback.py
Source code in src/forgather/ml/trainer/trainer_types.py
forgather.ml.trainer.trainer_types.TrainerControl
dataclass
¶
Control flags for trainer execution flow.
Callbacks can return a modified TrainerControl to influence trainer behavior: - Trigger checkpointing: Set should_save = True - Trigger evaluation: Set should_evaluate = True - Trigger logging: Set should_log = True - Stop training gracefully: Set should_training_stop = True - Stop current epoch: Set should_epoch_stop = True - Abort without saving: Set should_abort_without_save = True
Compatible with HuggingFace Trainer API for easier callback porting.
Example callback usage: def on_step_end(self, args, state, control, **kwargs): if state.global_step % 1000 == 0: control.should_save = True # Force checkpoint every 1000 steps return control
Source code in src/forgather/ml/trainer/trainer_types.py
forgather.ml.trainer.trainer_types.TrainOutput
¶
Base Classes¶
Abstract base from which all concrete trainers derive. Implement these three
methods to build a custom trainer: _prepare, _train_loop, _eval_loop.
forgather.ml.trainer.base_trainer.BaseTrainer
¶
Bases: ExtensibleTrainer, Stateful, StatefulProvider, Generic[TBaseTrainingArguments]
Abstract base class implementing common trainer infrastructure.
Provides callback management, checkpoint coordination, training-state tracking,
and the PyTorch Stateful interface. The actual training and evaluation loops
are left abstract so that concrete subclasses (Trainer, AccelTrainer,
PipelineTrainer) can implement them with their own parallelism strategy.
This class intentionally mirrors the public surface of transformers.Trainer
to make porting existing training scripts straightforward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
TBaseTrainingArguments
|
Training configuration dataclass. Must be an instance of
|
required |
model
|
Module or None
|
Pre-constructed model. Either |
None
|
data_collator
|
DataCollatorT or None
|
Callable that collates a list of dataset examples into a batch dict.
Default is |
None
|
train_dataset
|
IterableDatasetT or None
|
Training dataset ( |
None
|
eval_dataset
|
IterableDatasetT or None
|
Evaluation dataset. Default is |
None
|
processing_class
|
PreprocessingClassT or None
|
Tokenizer or feature extractor saved alongside model weights.
Default is |
None
|
model_init
|
Callable[[], Module] or None
|
Zero-argument factory that constructs the model. Required when |
None
|
callbacks
|
list of TrainerCallback or None
|
Callbacks to install. When |
None
|
compute_loss_func
|
LossFunctionT or None
|
Custom loss function. When |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
state |
TrainerState
|
Mutable training progress state (global step, epoch, log history, etc.). |
control |
TrainerControl
|
Mutable flags set by callbacks to signal save/eval/stop actions. |
checkpoint_manager |
CheckpointInterface or None
|
Set by |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If neither |
AssertionError
|
If |
Notes
Concrete subclasses must implement three abstract methods:
_prepare(train_dataset, eval_dataset)— set up dataloaders, model, optimizer, and checkpoint manager._train_loop()— the main training iteration loop, returningTrainOutput._eval_loop()— the evaluation loop, returning a metrics dict.
Source code in src/forgather/ml/trainer/base_trainer.py
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 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | |
default_callbacks()
classmethod
¶
Return the default callbacks for this trainer class.
Subclasses override this to provide callbacks that are always installed
(e.g. ProgressCallback, InfoCallback). The base implementation
returns an empty list.
Returns:
| Type | Description |
|---|---|
list of TrainerCallback
|
Default callback instances. |
Source code in src/forgather/ml/trainer/base_trainer.py
train(**kwargs)
¶
Run the full training loop.
Applies any configured PyTorch context managers (SDPA backend, activation
offloading), calls _prepare() to set up all components, then delegates
to _train_loop().
Returns:
| Type | Description |
|---|---|
TrainOutput
|
Named tuple with |
Source code in src/forgather/ml/trainer/base_trainer.py
evaluate(eval_dataset=None, **kwargs)
¶
Run evaluation on the given dataset.
Applies the configured SDPA backend context, calls _prepare() with
train_dataset=None, then delegates to _eval_loop().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eval_dataset
|
BaseDataset or None
|
Dataset to evaluate on. Falls back to |
None
|
Returns:
| Type | Description |
|---|---|
dict of str to float
|
Evaluation metrics, e.g. |
Source code in src/forgather/ml/trainer/base_trainer.py
log(logs)
¶
Log metrics and dispatch the on_log event to all callbacks.
Appends the metrics dict to state.log_history, then fires the
on_log callback event. Callbacks use this to write to TensorBoard,
wandb, or other logging backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logs
|
dict of str to float
|
Metrics to record, e.g. |
required |
Returns:
| Type | Description |
|---|---|
TrainerControl
|
Updated control object (callbacks may have set |
Source code in src/forgather/ml/trainer/base_trainer.py
unwrapped_model()
¶
Return the underlying model, free of any distributed wrappers.
Subclasses that wrap self.model in DDP, FSDP, Accelerate, or
pipeline-parallel containers override this method to strip those wrappers
before the model is passed to callbacks.
Returns:
| Type | Description |
|---|---|
Module
|
The bare model without any framework wrapper. |
Source code in src/forgather/ml/trainer/base_trainer.py
save_model(output_dir=None)
¶
Save model weights and the preprocessing class (HF Trainer API compatibility).
Writes only the model weights to output_dir (or args.output_dir
when output_dir is None). The full training state (optimizer,
scheduler, RNG, etc.) is not saved. For resumable training, prefer
save_checkpoint().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
path - like or str
|
Destination directory. Defaults to |
None
|
Source code in src/forgather/ml/trainer/base_trainer.py
save_checkpoint(checkpoint_path=None)
¶
Save a complete training checkpoint.
Writes all training state to a timestamped directory under
args.output_dir. The following components are always saved:
- Model weights (required for resuming)
- Optimizer state (momentum buffers, adaptive learning rates, etc.)
- LR scheduler state (current step position)
- Training progress (
global_step, epoch counter, etc.) - Dataset position (when the dataloader is stateful)
- Random number generator states (for bit-exact reproducibility)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path
|
path - like or str
|
Explicit checkpoint directory path. When |
None
|
Source code in src/forgather/ml/trainer/base_trainer.py
load_checkpoint(checkpoint_path=None)
¶
Load a training checkpoint to resume training.
Restores all available training state from the specified checkpoint directory. Each component is loaded only if its file exists:
- Model weights (always required — raises if missing)
- Optimizer state
- LR scheduler state
- Training progress (
global_step, epoch, etc.) - Dataset position
- Random number generator states
When checkpoint_path is None, the latest checkpoint under
args.output_dir is located automatically.
To intentionally skip reloading a component, delete its file from the checkpoint directory before calling this method. The checkpoint system logs a warning for each missing file but continues loading the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path
|
path - like or str
|
Path to the checkpoint directory. |
None
|
Source code in src/forgather/ml/trainer/base_trainer.py
get_state_components()
¶
Return state components for checkpoint save/load.
Describes every piece of training state that should be persisted. The checkpoint manager calls this method to determine what to save and how state is shared across distributed ranks.
For the single-GPU base trainer all components use GLOBAL sharing
except RNG which uses PER_RANK.
Returned components (in order):
"model"— model weights, required"optimizer"— optimizer state (optional)"scheduler"— LR scheduler state (optional)"trainer"— training progress counters (optional)"dataset"— dataloader position, only when stateful (optional)"rng"— per-rank RNG state (optional)
Returns:
| Type | Description |
|---|---|
list of StateComponent
|
All checkpointable state components with their sharing patterns. |
Source code in src/forgather/ml/trainer/base_trainer.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
get_process_groups()
¶
Return named process groups for PER_GROUP sharing pattern.
The checkpoint manager uses this to coordinate group-level saves (e.g. tensor-parallel replicas). Single-GPU trainers have no process groups. Subclasses implementing hybrid parallelism should override this method.
Returns:
| Type | Description |
|---|---|
dict of str to Any
|
Empty dict for the single-GPU base trainer. |
Source code in src/forgather/ml/trainer/base_trainer.py
load_state_dict(state_dict)
¶
Restore trainer progress state from a checkpoint state dict.
Implements the torch.distributed.checkpoint.stateful.Stateful
interface. Restores step counters and progress tracking so training
resumes at the exact point where it was saved. Also restores the
GradScaler state when fp16 AMP is active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
dict
|
State dictionary previously returned by |
required |
Source code in src/forgather/ml/trainer/base_trainer.py
state_dict()
¶
Return trainer progress state for checkpointing.
Implements the torch.distributed.checkpoint.stateful.Stateful
interface. The returned dict is consumed by load_state_dict() to
restore training from the exact saved point.
Returns:
| Type | Description |
|---|---|
dict
|
Training state with the following keys:
|
Source code in src/forgather/ml/trainer/base_trainer.py
forgather.ml.trainer.base_trainer.BaseTrainingArguments
dataclass
¶
Bases: MinimalTrainingArguments
Extended training arguments with checkpoint management and PyTorch optimizations.
Extends MinimalTrainingArguments with full checkpoint state preservation and a
range of PyTorch runtime optimizations (mixed precision, FP8, SDPA backend
selection, activation offloading, etc.).
All training state (model, optimizer, scheduler, dataset position, RNG state) is
automatically saved in checkpoints. To skip loading a specific component when
resuming, manually delete its file from the checkpoint directory before calling
train().
.. note::
The checkpoint-related options in this class are not compatible with the
HuggingFace Trainer. Use MinimalTrainingArguments when HF compatibility
is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_dtype
|
str or None
|
Default |
None
|
max_eval_steps
|
int
|
Maximum number of evaluation steps per evaluation call. |
-1
|
preserve_best_model
|
bool
|
If |
False
|
best_model_metric
|
str
|
Name of the metric used to select the best checkpoint when
|
'loss'
|
best_model_greater_is_better
|
bool or None
|
Whether higher values of |
None
|
preserve_n_best
|
int
|
Number of best checkpoints to keep safe from |
1
|
eval_on_save
|
bool
|
Force an evaluation pass before each checkpoint save. Useful for
decoupling the save and eval schedules. Default is |
False
|
enable_activation_offloading
|
bool
|
Offload saved activation tensors to CPU during the backward pass to
reduce peak GPU memory. Best combined with activation checkpointing.
Trades GPU memory for CPU memory bandwidth. Default is |
False
|
detect_anomaly
|
bool
|
Enable |
False
|
sdpa_backend
|
list of str, str, or None
|
Scaled Dot-Product Attention backend(s). Valid string values are
|
None
|
sdpa_set_priority
|
bool
|
When |
False
|
float32_matmul_precision
|
str or None
|
Float32 matrix-multiplication precision on Ampere+ GPUs. One of
|
None
|
dynamo_recompile_limit
|
int or None
|
Override |
None
|
mixed_precision
|
str or None
|
Automatic Mixed Precision mode. |
None
|
fp8_recipe
|
str or None
|
FP8 training recipe via |
None
|
fp8_dim_alignment
|
int
|
Minimum alignment for FP8 |
16
|
qat_recipe
|
str or None
|
Quantization-aware training recipe via |
None
|
Source code in src/forgather/ml/trainer/base_trainer.py
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 | |
Single-GPU Trainer¶
forgather.ml.trainer.trainer.Trainer
¶
Bases: BaseTrainer[TTrainingArguments], Generic[TTrainingArguments]
A lightweight, single-device trainer with API close to transformers.Trainer.
This trainer provides a simplified, more comprehensible implementation of the HuggingFace Trainer, intended as a drop-in replacement for basic use cases.
Key features: - Compatible with HF Trainer API for basic training workflows - Memory optimizations: fused loss, fused optimizer/backward, activation checkpointing - Flexible model construction: default/meta/device modes for different memory/speed tradeoffs - Full checkpoint management: saves/restores model, optimizer, scheduler, dataset state - Best model tracking via load_best_model_at_end
For distributed training, see AccelTrainer (data parallel via Accelerate) and PipelineTrainer (pipeline parallelism).
Basic usage: trainer = Trainer( model=model, args=TrainingArguments(...), train_dataset=train_dataset, eval_dataset=eval_dataset, optimizer_factory=optimizer_factory, lr_scheduler_factory=lr_scheduler_factory, ) trainer.train()
Source code in src/forgather/ml/trainer/trainer.py
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 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 | |
__init__(*, args, distributed_env, optimizer_factory=None, optimizer_cls_and_kwargs=None, lr_scheduler_factory=None, enable_activation_checkpoint_fn=enable_hf_activation_checkpointing, fused_loss_factory=None, optimizer_groups=None, **kwargs)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
TrainingArguments or dict
|
Training configuration. Accepts a |
required |
distributed_env
|
DistributedEnvInterface
|
Distributed environment object providing rank/device information.
Use |
required |
optimizer_factory
|
callable
|
Callable that accepts |
None
|
optimizer_cls_and_kwargs
|
tuple
|
HuggingFace Trainer-compatible alternative to |
None
|
lr_scheduler_factory
|
callable
|
Callable that accepts the optimizer and returns an LR scheduler.
If not provided and |
None
|
enable_activation_checkpoint_fn
|
callable
|
Called as |
enable_hf_activation_checkpointing
|
fused_loss_factory
|
callable
|
If provided, enables fused logits-loss computation. Called with the model's
output embedding layer and returns a loss function. Requires the model to
support |
None
|
optimizer_groups
|
OptimGroupMap
|
Parameter group configuration for the optimizer. Allows different hyperparameters (lr, weight_decay) for different parameter subsets. |
None
|
**kwargs
|
Passed to |
{}
|
Source code in src/forgather/ml/trainer/trainer.py
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 | |
load_best_model()
¶
Load the best model from the best checkpoint.
Called at end of training when load_best_model_at_end=True to restore the checkpoint with the best metric value seen during training.
Source code in src/forgather/ml/trainer/trainer.py
forgather.ml.trainer.trainer.TrainingArguments
dataclass
¶
Bases: BaseTrainingArguments
Training arguments specific to the simple Trainer implementation.
Extends BaseTrainingArguments with memory optimization and model construction options. Maintains compatibility with HuggingFace Trainer API where possible.
Source code in src/forgather/ml/trainer/trainer.py
Distributed Data Parallel (DDP) Trainer¶
forgather.ml.trainer.ddp.ddp_trainer.DDPTrainer
¶
Bases: Trainer[TDDPTrainingArguments], Generic[TDDPTrainingArguments]
Multi-GPU trainer using DistributedDataParallel (DDP).
Wraps the base Trainer with DDP for data-parallel training across multiple GPUs
or nodes. Each rank receives a different batch; gradients are all-reduced automatically
after each backward pass. Optionally uses PostLocalSGD for bandwidth-limited environments.
Launch with torchrun (or the forgather train -d ... shortcut)::
torchrun --nproc_per_node=4 train.py
Key differences from single-GPU Trainer:
- Model wrapped in
torch.nn.parallel.DistributedDataParallel - Gradient accumulation uses DDP's
no_sync()context to skip reductions on intermediate steps - Dataset loading via
DataloaderDispatcher(dispatch_batches=True, default) orSynchronizedDataLoader(dispatch_batches=False) - Optional PostLocalSGD communication hook for reduced all-reduce frequency
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
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 755 756 757 758 759 760 761 762 763 764 765 | |
__init__(*, args, fused_loss_factory=None, **kwargs)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
DDPTrainingArguments or dict
|
Training configuration including DDP-specific options ( |
required |
fused_loss_factory
|
callable
|
Factory for fused logits-loss computation. See |
None
|
**kwargs
|
Forwarded to |
{}
|
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
unwrapped_model()
¶
Get and returned the wrapped model
In the case of DDP, the original model is stored in the model's "module" attribute.
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
get_state_components()
¶
Get state components for DDP training.
All training state is always saved to checkpoints. To skip loading a component, delete its file from the checkpoint directory.
DDP uses data parallelism where model and optimizer state are replicated across all ranks. DDP automatically synchronizes model weights and gradients, so these components use REPLICATED pattern with validation enabled to catch synchronization bugs.
Dataset pattern depends on dispatch_batches setting: - dispatch_batches=True: GLOBAL (rank 0 loads and dispatches) - dispatch_batches=False: PER_RANK (each rank has independent dataloader)
Returns:
| Type | Description |
|---|---|
list of StateComponent
|
State components with REPLICATED sharing patterns for DDP. |
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
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 | |
get_process_groups()
¶
Get named process groups for checkpoint coordination.
Returns:
| Type | Description |
|---|---|
dict
|
Mapping of group names to ProcessGroup objects. For DDP, returns the data parallel group. |
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
forgather.ml.trainer.ddp.ddp_trainer.DDPTrainingArguments
dataclass
¶
Bases: TrainingArguments
Source code in src/forgather/ml/trainer/ddp/ddp_trainer.py
Fully Sharded Distributed Data Parallel (FSDP2) Trainer¶
forgather.ml.trainer.fsdp2.fsdp2_trainer.FSDP2Trainer
¶
Bases: Trainer[TFSDP2TrainingArguments], Generic[TFSDP2TrainingArguments]
Trainer that shards model, gradients, and optimizer state via FSDP2.
Uses torch.distributed.fsdp.fully_shard (PyTorch's FSDP2 API) to distribute
parameters, gradients, and optimizer state across all ranks. Provides ZeRO-3-style
memory savings, making it suitable for models that don't fit in a single GPU's memory.
Launch with torchrun (or the forgather train -d ... shortcut)::
torchrun --nproc_per_node=4 train.py
Key differences from DDP:
- Each rank stores only a shard of parameters, gradients, and optimizer state
- Parameters are all-gathered before each forward/backward and re-sharded after
(controlled by
fsdp2.reshard_after_forward) - Model checkpoints are saved as full HuggingFace safetensors gathered on rank 0,
making them loadable by
from_pretrainedwithout special tooling - Optimizer state is saved per-rank (sharded) and tied to the world size
See FSDP2Arguments for sharding configuration options (mixed precision policy,
CPU offload, transformer-layer-wise sharding).
Source code in src/forgather/ml/trainer/fsdp2/fsdp2_trainer.py
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 | |
__init__(*, args, fused_loss_factory=None, **kwargs)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
FSDP2TrainingArguments or dict
|
Training configuration including FSDP2-specific options under the |
required |
fused_loss_factory
|
callable
|
Factory for fused logits-loss computation. See |
None
|
**kwargs
|
Forwarded to |
{}
|
Source code in src/forgather/ml/trainer/fsdp2/fsdp2_trainer.py
pipeline_generate(input_ids, **kwargs)
¶
All-rank generate: FSDP2 forward pass needs every rank in the
all_gather, so generation must run collectively. The
TextgenCallback detects this method and uses a coordinated
broadcast-then-generate flow (same path as PipelineTrainer).
Source code in src/forgather/ml/trainer/fsdp2/fsdp2_trainer.py
get_state_components()
¶
State components for FSDP2.
The model is saved/loaded as HuggingFace safetensors via the model
hooks wired in _init_checkpoint_manager; it is NOT registered as
a StateComponent. Optimizer state stays sharded per rank because
the DTensor layout of the optimizer moments cannot cheaply round-
trip through a gather/broadcast. Scheduler, trainer progress,
dataset and RNG mirror DDPTrainer.
Source code in src/forgather/ml/trainer/fsdp2/fsdp2_trainer.py
forgather.ml.trainer.fsdp2.fsdp2_trainer.FSDP2Arguments
dataclass
¶
Source code in src/forgather/ml/trainer/fsdp2/fsdp2_trainer.py
Pipeline Parallel Trainer¶
forgather.ml.trainer.pipeline.pipeline_trainer.PipelineTrainer
¶
Bases: Trainer[TPipelineTrainingArguments], Generic[TPipelineTrainingArguments]
Trainer for pipeline parallel training using PyTorch distributed pipelining.
Partitions a model across multiple GPUs — each GPU hosts one or more sequential pipeline stages. Input batches are split into microbatches that flow through the stages with multiple microbatches in flight simultaneously, keeping all GPUs busy.
This trainer is designed for environments where inter-GPU bandwidth is limited (consumer GPUs over PCIe, multi-node over Ethernet) where all-reduce–based DDP or FSDP would be communication-bound.
Key differences from the single-device Trainer:
- Model is constructed on the meta device, then each stage is materialised on its assigned GPU — no full model ever lives on one GPU.
- Rank 0 constructs a fully-initialised CPU model and distributes parameters to other ranks via point-to-point sends, avoiding N redundant initialisations.
- All ranks receive the same batch (pure model parallelism); rank 0 loads data
via
DataloaderDispatcherand broadcasts it. - Gradient norm is all-reduced across ranks because each rank holds only a subset of the model's parameters.
- Effective batch size does not scale with
num_processes(the same batch flows through all stages; unlike DDP, there is no data replication).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
PipelineTrainingArguments or dict
|
Pipeline training configuration. Dicts are converted via
|
required |
model_splitter
|
ModelSplitter
|
Callable that splits the model into pipeline stages and returns
|
required |
pipe_schedule_factory
|
callable
|
Factory for the pipeline scheduler (e.g. |
ScheduleGPipe
|
**kwargs
|
Additional arguments forwarded to the base |
{}
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
AssertionError
|
If |
AssertionError
|
If batch size is not divisible by |
AssertionError
|
If |
AssertionError
|
If |
AssertionError
|
If a zero-bubble schedule is used with |
AssertionError
|
If |
Examples:
>>> from torch.distributed.pipelining import ScheduleGPipe
>>> args = PipelineTrainingArguments(
... n_microbatches=8,
... per_device_train_batch_size=64,
... stages_per_rank=1,
... )
>>> trainer = PipelineTrainer(
... args=args,
... model_init=model_factory,
... model_splitter=my_splitter_fn,
... pipe_schedule_factory=ScheduleGPipe,
... train_dataset=train_dataset,
... optimizer_factory=optimizer_factory,
... )
>>> trainer.train()
See Also
ModelSplitter : Protocol for the model-splitting callable.
References
PyTorch pipeline parallelism: https://docs.pytorch.org/docs/stable/distributed.pipelining.html
Source code in src/forgather/ml/trainer/pipeline/pipeline_trainer.py
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 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 | |
__init__(*, args, model_splitter, pipe_schedule_factory=ScheduleGPipe, **kwargs)
¶
Initialise the pipeline parallel trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
PipelineTrainingArguments or dict
|
Pipeline training configuration. Dicts are converted via
|
required |
model_splitter
|
ModelSplitter
|
Callable that accepts the model on the meta device and returns
all pipeline stage modules, the rank-local stage modules, and
|
required |
pipe_schedule_factory
|
callable
|
Pipeline scheduler factory. |
ScheduleGPipe
|
**kwargs
|
Forwarded to the base |
{}
|
Source code in src/forgather/ml/trainer/pipeline/pipeline_trainer.py
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 | |
pipeline_generate(input_ids, max_new_tokens, eos_token_id, pad_token_id, do_sample=True, temperature=1.0, top_k=0, repetition_penalty=1.0)
¶
Generate text autoregressively through all pipeline stages.
Bypasses the pipeline scheduler so input shapes are not constrained to the fixed training batch dimensions. All ranks must call this method simultaneously. The full generated sequence (prompt + new tokens) is returned on every rank.
No KV caching is used; each decoding step reprocesses the entire sequence. This is acceptable for infrequent, qualitative generation checks (e.g. during a callback).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
max_new_tokens
|
int
|
Maximum number of new tokens to generate. |
required |
eos_token_id
|
int
|
Token id that signals end of sequence. Once all sequences in the batch have emitted this token, generation stops early. |
required |
pad_token_id
|
int
|
Token id used to pad sequences that have already finished. |
required |
do_sample
|
bool
|
If |
True
|
temperature
|
float
|
Softmax temperature applied before top-k filtering. Values |
1.0
|
top_k
|
int
|
When |
0
|
repetition_penalty
|
float
|
Multiplicative penalty applied to logits of tokens already present
in the sequence. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Generated token ids of shape |
Source code in src/forgather/ml/trainer/pipeline/pipeline_trainer.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
get_state_components()
¶
Return state components for pipeline parallel training.
Because the model is split across ranks, each rank saves only its own stage parameters. The sharing patterns reflect this:
"model"— PER_RANK (each rank holds different stages), required."optimizer"— PER_RANK (optimises different parameters), optional."scheduler"— REPLICATED (same LR schedule on all ranks), optional."trainer"— REPLICATED (same global step on all ranks), optional."dataset"— GLOBAL (DataloaderDispatcherwithdp_mesh_dim=None; rank 0 loads and broadcasts), optional."rng"— PER_RANK (each stage may have different dropout), optional.
Returns:
| Type | Description |
|---|---|
list of StateComponent
|
All checkpointable state components with their sharing patterns. |
Source code in src/forgather/ml/trainer/pipeline/pipeline_trainer.py
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 | |
get_process_groups()
¶
Return named process groups for checkpoint coordination.
The checkpoint manager uses this mapping to implement PER_GROUP
sharing patterns (e.g. saving one copy per pipeline-parallel group).
Returns:
| Type | Description |
|---|---|
dict of str to ProcessGroup
|
|
Source code in src/forgather/ml/trainer/pipeline/pipeline_trainer.py
forgather.ml.trainer.pipeline.pipeline_trainer.PipelineTrainingArguments
dataclass
¶
Bases: TrainingArguments
Training arguments for pipeline parallel training.
Pipeline parallelism partitions a model across multiple GPUs, each handling one or more sequential stages. Input batches are split into microbatches that flow through the stages, allowing overlapped computation to keep all GPUs busy.
See the PyTorch pipeline parallelism documentation for background: https://docs.pytorch.org/docs/stable/distributed.pipelining.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_microbatches
|
int
|
Number of microbatches to split each batch into. More microbatches
improve pipeline efficiency (fewer bubbles) but increase memory usage.
The batch size must be evenly divisible by |
4
|
stages_per_rank
|
int
|
Number of pipeline stages hosted on each GPU. Most schedulers use
|
1
|
pp_stage_type
|
str
|
Stage-to-rank assignment pattern. |
'loop'
|
is_multistage
|
bool
|
Set |
False
|
debug_pipeline
|
bool
|
Enable debug-level logging for the pipeline scheduler. Internal
development flag. Default is |
False
|
debug_split_model
|
bool
|
Log pipeline module details after splitting. Internal development
flag. Default is |
False
|
debug_model_params
|
bool
|
Log all parameter and buffer devices/dtypes after model construction.
Internal development flag. Default is |
False
|
debug_model_init
|
bool
|
Log every send/recv during parameter distribution from rank 0.
Internal development flag. Default is |
False
|
Notes
model_splitter is passed to PipelineTrainer.__init__() rather than
stored here because it is a callable, not a primitive serialisable type.