Skip to content

Commit f89feef

Browse files
committed
Align generate_flux2klein.py entry point with reference FLUX/SDXL/WAN architecture
1 parent e2d2f1c commit f89feef

1 file changed

Lines changed: 35 additions & 39 deletions

File tree

src/maxdiffusion/generate_flux2klein.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,10 @@ def encode_prompt(prompt: str, snapshot_dir: str = None, repo_id: str = "black-f
9797
return prompt_embeds.cpu().numpy()
9898

9999

100-
def main(argv):
100+
def run(config):
101101
# Enable shardy partitioner for TPU execution
102102
jax.config.update("jax_use_shardy_partitioner", True)
103103

104-
# 1. Load configurations
105-
config_path = "src/maxdiffusion/configs/base_flux2klein.yml"
106-
custom_overrides = []
107-
if len(argv) > 1:
108-
if argv[1].endswith(".yml") or argv[1].endswith(".yaml"):
109-
config_path = argv[1]
110-
if len(argv) > 2:
111-
custom_overrides = argv[2:]
112-
else:
113-
custom_overrides = argv[1:]
114-
115-
max_logging.log(f"Initializing pyconfig with config: {config_path}")
116-
default_args = [
117-
None,
118-
config_path,
119-
"run_name=flux2klein_generation",
120-
"output_dir=output/",
121-
]
122-
default_args.extend(custom_overrides)
123-
124-
is_interactive = any(arg and "interactive=True" in arg.replace(" ", "") for arg in default_args)
125-
if is_interactive:
126-
max_logging.log("ℹ️ Interactive mode detected: overriding use_latents=False for dynamic inputs.")
127-
default_args.append("use_latents=False")
128-
129-
pyconfig.initialize(default_args)
130-
131104
# Import modules after jax.distributed.initialize() has run via pyconfig.initialize()
132105
from jax.experimental import multihost_utils
133106
from maxdiffusion.max_utils import device_put_replicated
@@ -138,17 +111,6 @@ def main(argv):
138111
)
139112
from maxdiffusion.pipelines.flux.flux2klein_pipeline import FlaxFlux2KleinPipeline
140113

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-
151-
config = pyconfig.config
152114
os.makedirs(config.output_dir, exist_ok=True)
153115

154116
# 2. Setup device mesh
@@ -569,6 +531,40 @@ def _put_leaf(param, sharding):
569531
multihost_utils.sync_global_devices("flux2klein_generation_complete")
570532

571533

534+
def main(argv):
535+
def handle_exception(exc_type, exc_value, exc_traceback):
536+
rank = jax.process_index()
537+
cnt = jax.process_count()
538+
print(f"\n❌ [HOST {rank}/{cnt}] UNCAUGHT FATAL EXCEPTION: {exc_value}", flush=True)
539+
import traceback
540+
traceback.print_exception(exc_type, exc_value, exc_traceback)
541+
sys.stdout.flush()
542+
543+
sys.excepthook = handle_exception
544+
545+
config_path = "src/maxdiffusion/configs/base_flux2klein.yml"
546+
custom_overrides = []
547+
if len(argv) > 1:
548+
if argv[1].endswith(".yml") or argv[1].endswith(".yaml"):
549+
config_path = argv[1]
550+
if len(argv) > 2:
551+
custom_overrides = argv[2:]
552+
else:
553+
custom_overrides = argv[1:]
554+
555+
default_args = [
556+
None,
557+
config_path,
558+
"run_name=flux2klein_generation",
559+
"output_dir=output/",
560+
]
561+
default_args.extend(custom_overrides)
562+
563+
pyconfig.initialize(default_args)
564+
max_utils.ensure_machinelearning_job_runs(pyconfig.config)
565+
run(pyconfig.config)
566+
567+
572568
if __name__ == "__main__":
573569
with transformer_engine_context():
574570
app.run(main)

0 commit comments

Comments
 (0)