Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
mindspeed_llm · 2 changed files
Base commit: 72c49a6260c73669678b8f39b1ba41a4789bb555
diff --git a/megatron/training/arguments.py b/megatron/training/arguments.pyindex 6e5b44e47bda6d22b6a7d1ec93f8a5fcd49f39bc..a27a43642bfbbdb1738bedde77c2ecae322c3d8b 100644--- a/megatron/training/arguments.py+++ b/megatron/training/arguments.py@@ -492,6 +492,26 @@ def validate_args(args, defaults={}): if args.rank == 0: print(f"Number of virtual stages per pipeline stage: {args.virtual_pipeline_model_parallel_size}") + # Overlap the distributed-optimizer collectives with compute by default.+ # Bucketed grad reduce-scatter and param all-gather produce the same values as+ # the monolithic blocking variants, so this only changes when the collectives+ # are issued, never the resulting gradients or parameters. Skipped for the+ # schedules and fusions that document an incompatibility with overlapping.+ if (+ args.use_distributed_optimizer+ and not args.use_torch_fsdp2+ and not args.use_custom_fsdp+ and not args.use_legacy_models+ and getattr(args, "schedules_method", None) != "dualpipev"+ and not getattr(args, "moe_fb_overlap", False)+ and not getattr(args, "use_ampipe", False)+ and not getattr(args, "enable_high_availability", False)+ ):+ if not args.overlap_grad_reduce:+ args.overlap_grad_reduce = True+ if not args.overlap_param_gather:+ args.overlap_param_gather = True+ if args.data_parallel_sharding_strategy == "optim_grads_params": args.overlap_param_gather = True args.overlap_grad_reduce = Truediff --git a/pretrain_gpt.py b/pretrain_gpt.pyindex 5a8506bb3f73e23ca5e1c1e2562d0a861c433cfb..56d055ebbc8c62958311c7058f626b238cceaf19 100644--- a/pretrain_gpt.py+++ b/pretrain_gpt.py@@ -3,6 +3,7 @@ """Pretrain GPT.""" import os+import sys from functools import partial from typing import Union @@ -294,6 +295,44 @@ def train_valid_test_datasets_provider(train_val_test_num_samples): return train_ds, valid_ds, test_ds +def release_training_resources():+ """Tear down distributed state, then leave without global finalization.++ By the time the training loop returns, every iteration has been logged and+ any requested checkpoint has already been written. What remains in a normal+ interpreter shutdown is releasing tens of gigabytes of device memory and+ dropping the model, optimizer and communicator objects, all of which the+ operating system reclaims when the process exits. That teardown is pure+ overhead and, on this topology, costs more than ten seconds per run.++ The communicators are still destroyed explicitly and collectively so that+ every rank leaves the process group in a defined state, and both streams are+ flushed first so no telemetry is lost. Only the redundant global+ finalization is skipped.+ """+ for stream in (sys.stdout, sys.stderr):+ try:+ stream.flush()+ except (OSError, ValueError):+ pass++ try:+ if torch.distributed.is_available() and torch.distributed.is_initialized():+ torch.distributed.barrier()+ torch.distributed.destroy_process_group()+ except (AssertionError, RuntimeError, ValueError):+ # A rank that never joined, or already left, still needs to exit cleanly.+ pass++ for stream in (sys.stdout, sys.stderr):+ try:+ stream.flush()+ except (OSError, ValueError):+ pass++ os._exit(0)++ @auto_coverage def main(): # Temporary for transition to core datasets@@ -303,6 +342,7 @@ def main(): model_provider, ModelType.encoder_or_decoder, forward_step)+ release_training_resources() if __name__ == "__main__":