Skip to main content

Python module

max.profiler

Performance profiling and tracing utilities for MAX.

This module provides tools for profiling and tracing MAX operations to analyze performance characteristics. Profiling captures timing information for code execution, which helps identify bottlenecks and optimize your models.

To enable profiling, set the MODULAR_ENABLE_PROFILING=1 environment variable before running your code. Without this variable, profiling calls will be no-ops with minimal overhead.

The profiler supports three usage patterns:

  1. Context manager: Use Tracer as a context manager to profile a code block.
  2. Decorator: Use @traced to profile entire functions.
  3. Manual stack: Use Tracer methods to explicitly control profiling spans.

Tracing

TracerA stack-based profiling manager for creating nested profiling spans.
tracedDecorator for creating a profiling span for a function.

Configuration

is_profiling_enabledis_profiling_enabled() -> bool
set_gpu_profiling_statestr, /) -> None