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.

  • schedule ((State) -> ProfilerAction) โ€“

    The profiling scheduling function.

    It takes the training state and returns a ProfilerAction. For convenience, Composer includes a cyclic_schedule() helper.

    from composer.profiler import Profiler, cyclic_schedule
    profiler = Profiler(

  • 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.


The Trainer automatically invokes this method.


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.


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.

  • 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.


Marker โ€“ Marker instance.


Record trace events in Chrome JSON format in the trace handlers.

See this document for more information about Chrome JSON format.


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 the TorchProfiler). 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.