Profiler#
- class ivy.utils.profiler.Profiler(*args, **kwargs)[source]#
Bases:
Profile
A Profiler class that allows code profiling.
- viz(bool, optional)#
- Type:
visualizes the results using snakeviz.
- Bonus args and kwargs are passed to cProfile.Profile __init__
Example
- with Profiler(print_stats=False, viz=True):
fn(x, y)
- ivy.utils.profiler.tensorflow_profile_start(logdir, host_tracer_level=2, python_tracer_level=0, device_tracer_level=1, delay_ms=None)[source]#
Initialize and start the profiler.
- Parameters:
logdir (str) –
to. (Directory where the profile data will be saved) –
host_tracer_level (int) – Adjust CPU tracing level. Values are: 1 - critical info only, 2 - info, 3 - verbose. [default value is 2]
python_tracer_level (int) – Toggle tracing of Python function calls. Values are: 1 - enabled, 0 - disabled [default value is 0]
device_tracer_level (int) – Adjust device (TPU/GPU) tracing level. Values are: 1 - enabled, 0 - disabled [default value is 1]
delay_ms (int) – Requests for all hosts to start profiling at a timestamp that is delay_ms away from the current time. delay_ms is in milliseconds. If zero, each host will start profiling immediately upon receiving the request. Default value is None, allowing the profiler guess the best value. Save the weights on the Module.
- Returns:
None
- ivy.utils.profiler.torch_profiler_init(logdir=None, activities=None, schedule=None, on_trace_ready=None, record_shapes=False, profile_memory=False, with_stack=False, with_flops=False, with_modules=False, experimental_config=None)[source]#
Initialize and returns a Torch profiler instance.
- Parameters:
logdir (str) – Directory where the profile data will be saved to.
activities (iterable) – list of activity groups (CPU, CUDA) to use in profiling, supported values:
torch.profiler.ProfilerActivity.CPU
,torch.profiler.ProfilerActivity.CUDA
. Default value: ProfilerActivity.CPU and (when available) ProfilerActivity.CUDA.schedule (Callable) – callable that takes step (int) as a single parameter and returns
ProfilerAction
value that specifies the profiler action to perform at each step.on_trace_ready (Callable) – callable that is called at each step when
schedule
returnsProfilerAction.RECORD_AND_SAVE
during the profiling.record_shapes (bool) – save information about operator’s input shapes.
profile_memory (bool) – track tensor memory allocation/deallocation.
with_stack (bool) – record source information (file and line number) for the ops.
with_flops (bool) – use formula to estimate the FLOPs (floating point operations) of specific operators (matrix multiplication and 2D convolution).
with_modules (bool) – record module hierarchy (including function names) corresponding to the callstack of the op. e.g. If module A’s forward call’s module B’s forward which contains an aten::add op, then aten::add’s module hierarchy is A.B Note that this support exist, at the moment, only for TorchScript models and not eager mode models.
_ExperimentalConfig (experimental_config) – A set of experimental options used for Kineto library features. Note, backward compatibility is not guaranteed.
- Returns:
Torch profiler instance.
- ivy.utils.profiler.torch_profiler_start(profiler)[source]#
Start the profiler.
- Parameters:
profiler (torch.profiler.profile) – Torch profiler instance.
- Returns:
None
- ivy.utils.profiler.torch_profiler_stop(profiler)[source]#
Start the profiler.
- Parameters:
profiler (torch.profiler.profile) – Torch profiler instance.
- Returns:
None
This should have hopefully given you an overview of the profiler submodule, if you have any questions, please feel free to reach out on our discord!