@@ -242,6 +242,14 @@ def __call__(
242242 trace ["prompt_encoding" ] = time .perf_counter () - t0
243243 max_logging .log (f" -> [TIMING] Prompt Encoding (Qwen3): { trace ['prompt_encoding' ]:.4f} seconds ⏱️" )
244244
245+ proc_id = jax .process_index ()
246+ proc_cnt = jax .process_count ()
247+ host_prefix = f"[HOST { proc_id } /{ proc_cnt } ] "
248+
249+ # Stage Sync 1: Phase A Complete
250+ multihost_utils .sync_global_devices ("phase_a_complete" )
251+ max_logging .log (f"{ host_prefix } Passed Phase A Sync Barrier (phase_a_complete) successfully! ✅" , flush = True )
252+
245253 # Shard pipeline batch inputs across data axis ("data") for SPMD multi-host execution
246254 data_sharding = jax .sharding .NamedSharding (self .mesh , P ("data" ))
247255
@@ -257,11 +265,25 @@ def put_data_on_devices(x, sharding):
257265 txt_ids_val = put_data_on_devices (txt_ids_val , data_sharding )
258266 img_ids_val = put_data_on_devices (img_ids_val , data_sharding )
259267
268+ max_logging .log (
269+ f"{ host_prefix } DIAGNOSTIC TENSORS BEFORE PHASE B:\n "
270+ f" latents_jax: shape={ latents_jax .shape } , dtype={ latents_jax .dtype } , sharding={ getattr (latents_jax , 'sharding' , None )} \n "
271+ f" prompt_embeds_jax: shape={ prompt_embeds_jax .shape } , dtype={ prompt_embeds_jax .dtype } , sharding={ getattr (prompt_embeds_jax , 'sharding' , None )} \n "
272+ f" txt_ids_val: shape={ txt_ids_val .shape } , dtype={ txt_ids_val .dtype } , sharding={ getattr (txt_ids_val , 'sharding' , None )} \n "
273+ f" img_ids_val: shape={ img_ids_val .shape } , dtype={ img_ids_val .dtype } , sharding={ getattr (img_ids_val , 'sharding' , None )} " ,
274+ flush = True ,
275+ )
276+
277+ # Stage Sync 2: Pre-Phase B Start
278+ multihost_utils .sync_global_devices ("pre_phase_b_start" )
279+ max_logging .log (f"{ host_prefix } Passed Pre-Phase B Sync Barrier (pre_phase_b_start) successfully! ✅" , flush = True )
280+
260281 # ---------------------------------------------------------------------
261282 # PHASE B: Denoising Loop (Flux Transformer - Fused JAX fori_loop)
262283 # ---------------------------------------------------------------------
263284 max_logging .log (
264- f"[PHASE B] Running { num_inference_steps } -step E2E Denoising Loop on a batch of { batch_size } images..."
285+ f"{ host_prefix } [PHASE B] Running { num_inference_steps } -step E2E Denoising Loop on a batch of { batch_size } images..." ,
286+ flush = True ,
265287 )
266288 t0 = time .perf_counter ()
267289
@@ -291,15 +313,27 @@ def step_fn(step_idx, current_latents):
291313
292314 return jax .lax .fori_loop (0 , num_inference_steps , step_fn , latents )
293315
294- latents_jax = denoise_loop (
295- params ,
296- latents_jax ,
297- prompt_embeds_jax ,
298- txt_ids_val ,
299- img_ids_val ,
300- scheduler_state ,
301- )
302- latents_jax .block_until_ready ()
316+ try :
317+ latents_jax = denoise_loop (
318+ params ,
319+ latents_jax ,
320+ prompt_embeds_jax ,
321+ txt_ids_val ,
322+ img_ids_val ,
323+ scheduler_state ,
324+ )
325+ latents_jax .block_until_ready ()
326+ except Exception as e :
327+ max_logging .log (f"❌ { host_prefix } EXCEPTION IN DENOISE LOOP: { e } " , flush = True )
328+ import traceback
329+
330+ traceback .print_exc ()
331+ sys .stdout .flush ()
332+ raise e
333+
334+ # Stage Sync 3: Phase B Complete
335+ multihost_utils .sync_global_devices ("phase_b_complete" )
336+ max_logging .log (f"{ host_prefix } Passed Phase B Sync Barrier (phase_b_complete) successfully! ✅" , flush = True )
303337
304338 trace ["denoise_loop" ] = time .perf_counter () - t0
305339 max_logging .log (f" -> [TIMING] Denoising Loop (Flux): { trace ['denoise_loop' ]:.4f} seconds ⏱️" )
0 commit comments