-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathprofiling.py
More file actions
40 lines (32 loc) · 1 KB
/
profiling.py
File metadata and controls
40 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Wrapper to handle PyTorch profiling and benchmarking.
Author:
* Titouan Parcollet 2024
"""
import os
from torch import profiler
def prepare_profiler(
profile_warmup=5, profile_steps=5, logdir="tensorboard_logs"
):
"""Wrapper to create a PyTorch profiler to benchmark training of speechbrain.core.Brain instances.
See ``torch.profiler.profile`` documentation for details (brief summary below).
Arguments
---------
profile_warmup: int
Number of warmup step before starting to log.
profile_steps: int
Number of steps to log after warmup.
logdir: str
Path to the output folder of the logs.
Returns
-------
profiler
"""
logdir = os.path.join(logdir, "profiler_logs")
return profiler.profile(
schedule=profiler.schedule(
wait=0, warmup=profile_warmup, active=profile_steps, repeat=1
),
on_trace_ready=profiler.tensorboard_trace_handler(logdir),
record_shapes=True,
with_stack=True,
)