Skip to content

Commit d841294

Browse files
xunnanxufacebook-github-bot
authored andcommitted
support active profiler iters
Summary: * Support optional profiler active iter via `--pa` * If not used, default is to log all batches, otherwise we log this many only. Differential Revision: D79471053
1 parent 85737e6 commit d841294

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

train/comms/pt/comms.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import logging
1111
import time
12+
from typing import Final
1213

1314
import numpy as np
1415

@@ -18,7 +19,6 @@
1819
from param_bench.train.comms.pt import comms_utils
1920
from param_bench.train.comms.pt.comms_utils import (
2021
bootstrap_info_holder,
21-
commsParamsHolder,
2222
commsParamsHolderBase,
2323
ensureTensorFlush,
2424
MultilineFormatter,
@@ -33,9 +33,7 @@
3333
commsQuantCollPerfMetrics,
3434
customized_perf_loggers,
3535
)
36-
3736
from param_bench.train.comms.pt.pytorch_backend_utils import (
38-
backendFunctions,
3937
pt2ptPatterns,
4038
supportedC10dBackends,
4139
supportedCollectives,
@@ -174,6 +172,16 @@ def readArgs(self, parser):
174172
default=None,
175173
help="execute pytorch profiler at specified size",
176174
) # execute pytorch profiler at specified size if applicable
175+
parser.add_argument(
176+
"--profiler-active-iters",
177+
"--pa",
178+
type=int,
179+
required=False,
180+
help=(
181+
"If set, profiler will only record these many iters. "
182+
"Otherwise it records the full --num_iters across one benchmark size iteration."
183+
),
184+
)
177185
parser.add_argument(
178186
"--tag",
179187
type=str,
@@ -1319,14 +1327,20 @@ def benchComm(self, index, commsParams, backendFuncs):
13191327
results["numElements"] = numElements
13201328

13211329
self.collectiveArgs.data_type = commsParams.data_type
1330+
profiler_active_iters = commsParams.profiler_active_iters
1331+
if profiler_active_iters is None:
1332+
# not specified in arg
1333+
profiler_active_iters = (
1334+
self.collectiveArgs.graph_launches
1335+
if self.collectiveArgs.graph_launches
1336+
else self.collectiveArgs.numIters
1337+
)
13221338
if commsParams.size_start_profiler == curSize:
13231339
self.collectiveArgs.enable_profiler = comms_utils.startProfiler(
13241340
rank=self.backendFuncs.get_global_rank(),
13251341
device=self.collectiveArgs.device,
13261342
numWarmupIters=self.collectiveArgs.numWarmupIters,
1327-
numIters=self.collectiveArgs.graph_launches
1328-
if self.collectiveArgs.graph_launches
1329-
else self.collectiveArgs.numIters,
1343+
numIters=profiler_active_iters,
13301344
)
13311345

13321346
# self.collectiveArgs has all the information on the experiment.

train/comms/pt/comms_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,12 @@ def startProfiler(rank: int, device: str, numWarmupIters: int, numIters: int) ->
526526
rank=rank,
527527
device=device,
528528
warmup=numWarmupIters,
529-
iters=numIters,
529+
active=numIters,
530530
)
531531
fbStartProfiler()
532532
return True
533533
else:
534-
logger.debug("Internal profiler is not available, skip...")
534+
logger.warning("Internal profiler is not available, skip...")
535535
return False
536536

537537

@@ -901,6 +901,7 @@ def __init__(
901901
self.bootstrap_info = bootstrap_info
902902

903903
self.size_start_profiler = args.size_start_profiler
904+
self.profiler_active_iters = args.profiler_active_iters
904905
self.groupRanks = groupRanks
905906

906907
self.include_0B = args.include_0B

0 commit comments

Comments
 (0)