Skip to content

Commit ef7b8d5

Browse files
committed
Add global exception hook and post_param_placement_sync barrier
1 parent 900dbe9 commit ef7b8d5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/maxdiffusion/generate_flux2klein.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ def main(argv):
138138
)
139139
from maxdiffusion.pipelines.flux.flux2klein_pipeline import FlaxFlux2KleinPipeline
140140

141+
def handle_exception(exc_type, exc_value, exc_traceback):
142+
rank = jax.process_index()
143+
cnt = jax.process_count()
144+
print(f"\n❌ [HOST {rank}/{cnt}] UNCAUGHT FATAL EXCEPTION: {exc_value}", flush=True)
145+
import traceback
146+
traceback.print_exception(exc_type, exc_value, exc_traceback)
147+
sys.stdout.flush()
148+
149+
sys.excepthook = handle_exception
150+
141151
config = pyconfig.config
142152
os.makedirs(config.output_dir, exist_ok=True)
143153

@@ -399,6 +409,9 @@ def _put_leaf(param, sharding):
399409
max_logging.log("All parameters placed on TPU HBM successfully!")
400410
gc.collect()
401411
jax.effects_barrier()
412+
from jax.experimental import multihost_utils
413+
multihost_utils.sync_global_devices("post_param_placement_sync")
414+
print(f"[HOST {jax.process_index()}/{jax.process_count()}] Passed post_param_placement_sync barrier successfully! ✅", flush=True)
402415

403416
load_time = time.time() - t_load_start
404417
max_logging.log(f" -> [TIMING] Total Model Loading & Device Placement: {load_time:.2f} seconds ⏱️\n")

0 commit comments

Comments
 (0)