Skip to content

Commit 942e517

Browse files
committed
more verbose timing
1 parent a837ca1 commit 942e517

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/maxdiffusion/generate_flux2klein.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import gc
1616
import os
17+
import time
1718
from typing import List
1819

1920
from absl import app
@@ -300,6 +301,7 @@ def qwen3_init_fn():
300301

301302
# 8. Load weights on Host CPU
302303
print("Loading parameters on Host CPU...")
304+
t_load_start = time.time()
303305
cpu_device = jax.devices("cpu")[0]
304306
with jax.default_device(cpu_device):
305307
with mesh, nn_partitioning.axis_rules(config.logical_axis_rules):
@@ -378,6 +380,9 @@ def unbox_fn(x):
378380
gc.collect()
379381
jax.effects_barrier()
380382

383+
load_time = time.time() - t_load_start
384+
print(f" -> [TIMING] Total Model Loading & Device Placement: {load_time:.2f} seconds ⏱️\n")
385+
381386
# 9. Setup FlowMatch Scheduler
382387
scheduler = FlaxFlowMatchScheduler(
383388
num_train_timesteps=1000,
@@ -453,6 +458,7 @@ def unbox_fn(x):
453458
print("\n" + "=" * 80)
454459
print("🚀 Running initial dry run (Warmup Pass) to compile XLA graphs...")
455460
print("=" * 80)
461+
t_warmup_start = time.time()
456462
pipeline(
457463
prompt=active_prompts,
458464
params=params,
@@ -472,10 +478,12 @@ def unbox_fn(x):
472478
output_dir=config.output_dir,
473479
output_name="flux2klein_warmup.png",
474480
)
481+
warmup_time = time.time() - t_warmup_start
475482

476483
print("\n" + "=" * 80)
477484
print("⏱️ Running timed pass at full TPU speed...")
478485
print("=" * 80)
486+
t_main_start = time.time()
479487
pipeline(
480488
prompt=active_prompts,
481489
params=params,
@@ -495,6 +503,15 @@ def unbox_fn(x):
495503
output_dir=config.output_dir,
496504
output_name="flux2klein_generated_image.png",
497505
)
506+
main_time = time.time() - t_main_start
507+
508+
print("\n" + "=" * 80)
509+
print("📊 FLUX.2-KLEIN LATENCY & TIMING BREAKDOWN")
510+
print("=" * 80)
511+
print(f"1) Total Model Loading & Placement Time: {load_time:.2f} seconds ⏱️")
512+
print(f"2) Cold-Start / Warmup Pass (XLA Compilation): {warmup_time:.2f} seconds ⏱️")
513+
print(f"3) Main Warmed-Up Pass (Full-Speed Inference): {main_time:.2f} seconds ⏱️")
514+
print("=" * 80)
498515

499516
print("\n=======================================================")
500517
print(f"SUCCESS! Batched generation complete for {config.batch_size} images! 🎨🎉")

0 commit comments

Comments
 (0)