Profiler (original) (raw)
Toggle table of contents sidebar
class composer.profiler.Profiler(schedule, trace_handlers, sys_prof_cpu=True, sys_prof_memory=False, sys_prof_disk=False, sys_prof_net=False, sys_prof_stats_thread_interval_seconds=0.5, torch_prof_folder='{run_name}/torch_traces', torch_prof_filename='rank{rank}.{batch}.pt.trace.json', torch_prof_remote_file_name='{run_name}/torch_traces/rank{rank}.{batch}.pt.trace.json', torch_prof_memory_filename=None, torch_prof_memory_remote_file_name='{run_name}/torch_memory_traces/rank{rank}.{batch}.pt.memory_trace.html', torch_prof_overwrite=False, torch_prof_use_gzip=False, torch_prof_record_shapes=False, torch_prof_profile_memory=True, torch_prof_with_stack=False, torch_prof_with_flops=True, torch_prof_num_traces_to_keep=- 1)[source]#
Composer Profiler.
See the Profiling Guide for additional information.
Parameters
- schedule ((State) -> ProfilerAction) –
The profiling scheduling function.
It takes the training state and returns a ProfilerAction. For convenience, Composer includes acyclic_schedule()
helper.
from composer.profiler import Profiler, cyclic_schedule
profiler = Profiler(
...,
schedule=cyclic_schedule(
skip_first=1,
wait=0,
warmup=1,
active=4,
repeat=1,
),
torch_prof_memory_filename=None,
) - trace_handlers (TraceHandler | Sequence _[_TraceHandler]) – Trace handlers which record and save profiling data to traces. Additionally supports full object store paths.
- sys_prof_cpu (bool, optional) – Whether to record cpu statistics. (default:
True
). - sys_prof_memory (bool, optional) – Whether to record memory statistics. (default:
False
). - sys_prof_disk (bool, optional) – Whether to record disk statistics. (default:
False
). - sys_prof_net (bool, optional) – Whether to record network statistics. (default:
False
). - sys_prof_stats_thread_interval_seconds (float, optional) – Interval to record stats, in seconds. (default:
0.5
). - torch_prof_folder (str, optional) – See TorchProfiler.
- torch_prof_filename (str, optional) – See TorchProfiler.
- torch_prof_remote_file_name (str, optional) – See TorchProfiler. Additionally supports full object store paths e.g: s3://bucket/path/to/file.
- torch_prof_memory_filename (str, optional) – See TorchProfiler.
- torch_prof_memory_remote_file_name (str, optional) – See TorchProfiler. Additionally supports full object store paths e.g: s3://bucket/path/to/file.
- torch_prof_overwrite (bool, optional) – See TorchProfiler.
- torch_prof_use_gzip (bool, optional) – See TorchProfiler.
- torch_prof_record_shapes (bool, optional) – See TorchProfiler.
- torch_prof_profile_memory (bool, optional) – See TorchProfiler.
- torch_prof_with_stack (bool, optional) – See TorchProfiler.
- torch_prof_with_flops (bool, optional) – See TorchProfiler.
- torch_prof_num_traces_to_keep (int, optional) – See TorchProfiler.
Bind the profiler to the state
.
Note
The Trainer automatically invokes this method.
Parameters
state (State) – The training state.
marker(name, actions=(<ProfilerAction.WARMUP: 'warmup'>, <ProfilerAction.ACTIVE: 'active'>, <ProfilerAction.ACTIVE_AND_SAVE: 'active_and_save'>), record_instant_on_start=False, record_instant_on_finish=False, categories=())[source]#
Create and get an instance of a Marker.
If a Marker with the specified name
does not already exist, it will be created. Otherwise, the existing instance will be returned.
Note
Profiler.marker() should be used to construct markers. Marker should not be instantiated directly by the user.
For example:
marker = profiler.marker("foo") marker <composer.profiler.marker.Marker object at ...>
Please see Marker.start() and Marker.finish() for usage on creating markers to measure duration events,Marker.instant() for usage on creating markers to mark instant events and Marker.counter() for usage on creating markers for counting.
Parameters
- name (str) – The name for the Marker.
- actions (Sequence _[_ProfilerAction] , optional) – ProfilerAction states to record on. Defaults to (WARMUP, ACTIVE,ACTIVE_AND_SAVE).
- record_instant_on_start (bool, optional) – Whether to record an instant event whenever the marker is started. Defaults to
False
. - record_instant_on_finish (bool, optional) – Whether to record an instant event whenever the marker is finished. Defaults to
False
. - categories (Union _[_list[_str] , tuple[_str, ... ] ] , optional) – Categories for this marker. Defaults to
None
.
Returns
Marker – Marker instance.
record_chrome_json_trace_file(filepath)[source]#
Record trace events in Chrome JSON format in the trace handlers.
See this documentfor more information about Chrome JSON format.
Note
For custom profiling, it is recommended to use marker() instead of manually creating a Chrome JSON trace file. By default, the Composer Profiler will automatically saving Marker events in Chrome JSON format.
This method exists for external profilers that natively record events in Chrome JSON format (such as theTorchProfiler). These profilers can use this method to route their profiling traces to the Composer profiler trace_handlers so events from both the Composer Profiler and external profilers are recorded in the same trace file.
property trace_handlers#
Profiler trace handlers.