Skip to content

Commit 9e66dd9

Browse files
committed
Add memory profiler arguments to Python frontend
1 parent bce00f8 commit 9e66dd9

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

applications/nlp/transformer/trainer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ def make_batch_script(model: lbann.Model,
172172
if args.progress:
173173
model.callbacks.append(lbann.CallbackProgressBar(newline_interval=100))
174174

175-
profiler = lbann.contrib.args.create_profile_callback(args)
176-
if profiler is not None:
177-
model.callbacks.append(profiler)
175+
model.callbacks.extend(lbann.contrib.args.create_profile_callbacks(args))
178176

179177
script_params = lbann.contrib.args.get_scheduler_kwargs(args)
180178
script_params['work_dir'] = work_dir

applications/physics/cosmology/cosmoflow/train_cosmoflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,8 @@ def create_synthetic_data_reader(input_width: int, num_responses: int) -> Any:
201201
mlperf=args.mlperf,
202202
transform_input=args.transform_input)
203203

204-
# Add profiling callback if needed.
205-
profiler = lbann.contrib.args.create_profile_callback(args)
206-
if profiler is not None:
207-
model.callbacks.append(profiler)
204+
# Add profiling callbacks if needed.
205+
model.callbacks.extend(lbann.contrib.args.create_profile_callbacks(args))
208206

209207
# Setup optimizer
210208
optimizer = lbann.contrib.args.create_optimizer(args)

applications/vision/resnet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@
136136
callbacks.append(
137137
lbann.CallbackLinearGrowthLearningRate(
138138
target=0.1 * args.mini_batch_size / 256, num_epochs=5))
139-
profiler = lbann.contrib.args.create_profile_callback(args)
140-
if profiler is not None:
141-
callbacks.append(profiler)
139+
callbacks.extend(lbann.contrib.args.create_profile_callbacks(args))
142140
model = lbann.Model(args.num_epochs,
143141
layers=layers,
144142
objective_function=obj,

python/lbann/contrib/args.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def add_profiling_arguments(parser: argparse.ArgumentParser) -> None:
209209
"""Add command-line arguments for common profiler settings within
210210
LBANN.
211211
212-
Adds the following options: `--profile`, `--profile-init`,
213-
`--caliper` and `--caliper-config`.
212+
Adds the following options: `--profile`, `--memory-profile`,
213+
`--profile-init`, `--caliper` and `--caliper-config`.
214214
215215
`--caliper-config` implies `--caliper`. `--caliper` without a
216216
`--caliper-config` will use the default configuration in LBANN.
@@ -229,6 +229,10 @@ def add_profiling_arguments(parser: argparse.ArgumentParser) -> None:
229229
action='store_true',
230230
default=False,
231231
help='enable profiling instrumentation and markers')
232+
parser.add_argument('--memory-profile',
233+
action='store_true',
234+
default=False,
235+
help='enable itemized memory usage analysis')
232236
parser.add_argument('--profile-init',
233237
action='store_true',
234238
default=False,
@@ -242,9 +246,12 @@ def add_profiling_arguments(parser: argparse.ArgumentParser) -> None:
242246
default=None,
243247
type=str,
244248
help='Configuration string for Caliper')
249+
parser.add_argument('--memory-profile-verbose',
250+
action='store_true',
251+
default=False,
252+
help='increase memory usage analysis verbosity')
245253

246-
247-
def create_profile_callback(args: argparse.Namespace) -> Any:
254+
def create_profile_callbacks(args: argparse.Namespace) -> Any:
248255
"""Create a profiler callback from command-line arguments.
249256
250257
The parsed arguments must be generated by an
@@ -262,13 +269,20 @@ def create_profile_callback(args: argparse.Namespace) -> Any:
262269
try:
263270
profile = args.profile
264271
profile_init = not args.profile_init
272+
memprofile = args.memory_profile
273+
memprof_verbose = args.memory_profile_verbose
265274
except AttributeError:
266275
raise ValueError('passed arguments have not been processed by '
267276
'`add_profiling_arguments`')
268277

278+
result = []
269279
if profile:
270-
return lbann.CallbackProfiler(skip_init=profile_init)
271-
return None
280+
result.append(lbann.CallbackProfiler(skip_init=profile_init))
281+
if memprofile:
282+
result.append(lbann.CallbackMemoryProfiler(
283+
detailed_first_step=memprof_verbose))
284+
285+
return result
272286

273287

274288
def get_profile_args(args: argparse.Namespace) -> list[str]:

0 commit comments

Comments
 (0)