MCPcopy Create free account
hub / github.com/apple/axlearn / maybe_profile

Function maybe_profile

axlearn/cloud/gcp/examples/colocated_python_benchmark.py:42–56  ·  view source on GitHub ↗

JAX profiler context if enabled, otherwise a no-op. Args: enabled: Whether profiling is enabled. profile_dir: Directory to save profiling results.

(enabled: bool, profile_dir: Optional[str])

Source from the content-addressed store, hash-verified

40
41@contextmanager
42def maybe_profile(enabled: bool, profile_dir: Optional[str]):
43 """JAX profiler context if enabled, otherwise a no-op.
44
45 Args:
46 enabled: Whether profiling is enabled.
47 profile_dir: Directory to save profiling results.
48 """
49 if enabled:
50 assert profile_dir is not None, "profile_dir must be set when profiling is enabled"
51 jax.profiler.start_trace(profile_dir)
52 try:
53 yield
54 finally:
55 if enabled:
56 jax.profiler.stop_trace()
57
58
59def create_mesh(mesh_shape=(1, 1, 1, 1, 1, 16, -1)):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected