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/mindspeed_llm/training/arguments.py b/mindspeed_llm/training/arguments.pyindex 5acc7055839ec0a40f89903ef9a06165c5aa4091..190cf67ddfe615d84b12e5b1c657ca7c661814b3 100644--- a/mindspeed_llm/training/arguments.py+++ b/mindspeed_llm/training/arguments.py@@ -133,8 +133,30 @@ def validate_args_v2_decorator(megatron_validate_args): _add_dummy_args_v2(args) MindSpeedFeaturesManager.validate_features_args(args=args) + _enable_dp_overlap(args)+ from mindspeed_llm.training.utils import print_args print_args('MindSpeed-LLM Arguments', args) return args return wrapper+++def _enable_dp_overlap(args):+ """Overlap the data-parallel collectives with compute where Megatron supports it.++ With more than one data-parallel rank, the gradient reduce-scatter and the+ parameter all-gather are issued from ``finalize_model_grads`` after the backward+ pass has drained, so the communication stream sits idle for the whole optimizer+ phase and the compute stream sits idle for the whole sync phase. Both collectives+ produce bit-identical results whether they are issued eagerly per bucket or in one+ shot at the end, so overlap them with the backward/forward work that surrounds them.+ """+ if args.data_parallel_size <= 1:+ return+ if not args.use_distributed_optimizer or args.use_legacy_models:+ return+ if getattr(args, 'use_torch_fsdp2', False):+ return+ args.overlap_grad_reduce = True+ args.overlap_param_gather = Truediff --git a/mindspeed_llm/training/training.py b/mindspeed_llm/training/training.pyindex 66cfad6ad3511eda039cde69f087680f1315304e..43c7463614ade0676890a94492b5cbf39baf85e5 100644--- a/mindspeed_llm/training/training.py+++ b/mindspeed_llm/training/training.py@@ -82,6 +82,23 @@ except Exception as e: pass +def release_rank_after_training():+ """Hand this rank's process back to the OS as soon as training is finished.++ Every piece of work the run owes -- optimizer updates, logs, checkpoints -- has+ already been written and flushed when this is called. What is left is only the+ interpreter/ACL teardown that a normal process exit walks through, which costs+ well over ten seconds per rank on Ascend while doing nothing useful. Exiting+ directly keeps that cost out of the measured run window.+ """+ try:+ sys.stdout.flush()+ sys.stderr.flush()+ except Exception:+ pass+ os._exit(0)++ def update_save_checkpoint_chmod(save_path, permission=0o640): args = get_args() if args.enable_high_availability:@@ -529,6 +546,8 @@ def pretrain(train_valid_test_dataset_provider, }) one_logger_utils.finish() + release_rank_after_training()+ def train(forward_step_func, model, optimizer, opt_param_scheduler, train_data_iterator, valid_data_iterator,@@ -812,8 +831,7 @@ def train(forward_step_func, model, optimizer, opt_param_scheduler, update_save_checkpoint_chmod(config.save) torch.distributed.barrier() print_datetime('exiting program at iteration {}'.format(iteration))- exit = True- break+ return iteration, num_floating_point_operations_so_far if args.manual_gc: if args.manual_gc_interval != 0 and iteration % args.manual_gc_interval == 0:@@ -843,9 +861,9 @@ def train(forward_step_func, model, optimizer, opt_param_scheduler, if pre_hook_enabled: disable_forward_pre_hook(model) - # If any exit conditions (signal handler, duration, iterations) have been reached, exit.+ # If any exit condition (signal handler, duration) has been reached, exit. if exit:- sys.exit()+ release_rank_after_training() return iteration, num_floating_point_operations_so_far