Skip to content

Commit

Permalink
enable profiler for specific ranks (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranzhejiang authored Oct 8, 2024
1 parent 8be7f48 commit 4448492
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions megatron/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,5 +1570,11 @@ def _add_profiler_args(parser):
type=str,
default='2,3',
help="Which steps to profile. Format: <start step>,<end step>")

group.add_argument("--profile-ranks",
type=int,
nargs='+',
default=None,
help="Which ranks to profile. Format: 0 1 2 3")

return parser
4 changes: 3 additions & 1 deletion megatron/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def is_end_step():
def is_capture_step():
return cur_step >= start_step and cur_step <= end_step

if args.profile.startswith('pt'):
if args.profile.startswith('pt') and (
args.profile_ranks is None or torch.distributed.get_rank() in args.profile_ranks
):
schedule = torch.profiler.schedule(wait=0, warmup=0, active=active_steps, repeat=1)
activities = [torch.profiler.ProfilerActivity.CPU]
activities.extend([torch.profiler.ProfilerActivity.HPU] if device.startswith("hpu") else [])
Expand Down

0 comments on commit 4448492

Please sign in to comment.