Profiler#

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_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 a cyclic_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,
        ),
    )
    

  • trace_handlers (TraceHandler | Sequence[TraceHandler]) โ€“ Trace handlers which record and save profiling data to traces.

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

  • 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_to_state(state)[source]#

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 document for 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 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.