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])
| 40 | |
| 41 | @contextmanager |
| 42 | def 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 | |
| 59 | def create_mesh(mesh_shape=(1, 1, 1, 1, 1, 16, -1)): |