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

Function main

axlearn/cloud/gcp/examples/colocated_python_benchmark.py:230–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228
229
230def main():
231 parser = argparse.ArgumentParser(description="Preload model from GCS checkpoint")
232 parser.add_argument(
233 "--ckpt_path",
234 required=True,
235 help="GCS path to checkpoint directory (e.g., gs://bucket/path/to/checkpoint)",
236 )
237 parser.add_argument(
238 "--method",
239 choices=["colocated", "default"],
240 default="colocated",
241 help="Loading method to benchmark: 'colocated' (CPU preload) or 'default' (direct to TPU)",
242 )
243 parser.add_argument(
244 "--profile",
245 action="store_true",
246 help="Enable JAX profiler (adds overhead, disable for accurate benchmarking)",
247 )
248 parser.add_argument(
249 "--num_iters",
250 type=int,
251 default=1,
252 help="Number of times to repeat the load benchmark (default: 1)",
253 )
254 args = parser.parse_args()
255
256 # Disable persistent compilation cache for fair benchmarking
257 # This ensures benchmarks compile fresh and don't benefit from cached kernels
258 os.environ["JAX_ENABLE_COMPILATION_CACHE"] = "0"
259
260 if os.getenv("JAX_PLATFORMS") == "proxy":
261 pathwaysutils.initialize()
262 else:
263 jax.distributed.initialize()
264
265 print(f"JAX devices: {jax.devices()}")
266
267 # Validate checkpoint path
268 if not args.ckpt_path.startswith("gs://"):
269 raise ValueError(f"Only GCS paths (gs://) are supported, got: {args.ckpt_path}")
270 profile_dir = None
271 if args.profile:
272 # Create timestamped profile directory (minute-level granularity)
273 timestamp = datetime.now().strftime("%Y%m%d%H%M")
274 base_path = args.ckpt_path.split("/checkpoints")[0]
275 profile_dir = f"{base_path}/profiles/{args.method}_{timestamp}/"
276 print(f"Profiling enabled - results will be saved to {profile_dir}")
277
278 step = parse_step_from_dir(args.ckpt_path)
279 print(f"Starting model preload from: {args.ckpt_path} (step {step})")
280
281 # Read checkpoint structure (doesn't need mesh)
282 print("Reading checkpoint structure...")
283 state_spec = create_state_spec_from_checkpoint(args.ckpt_path)
284 print(f"Found {len(jax.tree_util.tree_leaves(state_spec))} tensors in checkpoint")
285
286 num_iterations = args.num_iters
287 print(f"--- Running {args.method} benchmark ({num_iterations} iterations) ---")

Callers 1

Calls 7

parse_step_from_dirFunction · 0.90
create_meshFunction · 0.85
maybe_profileFunction · 0.85
load_modelFunction · 0.85
initializeMethod · 0.45

Tested by

no test coverage detected