Skip to content

Commit 753f68b

Browse files
committed
Clean test paths and organize FLUX.2-Klein image edit reference assets
- Move reference images ref_image_0..3 to tests/images/flux2klein/ - Remove dev-specific hardcoded paths from edit_flux2klein_e2e_test.py - Use standard /tmp output directories across smoke tests - Format tests with pyink and ruff
1 parent da9db0e commit 753f68b

6 files changed

Lines changed: 41 additions & 25 deletions

File tree

src/maxdiffusion/tests/edit_flux2klein_e2e_test.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,46 @@ def setUp(self):
5454
jax.config.update("jax_default_matmul_precision", "highest")
5555
jax.config.update("jax_use_shardy_partitioner", True)
5656

57-
candidates = [
58-
"/mnt/data/hf_cache/hub/models--black-forest-labs--FLUX.2-klein-4B/snapshots",
59-
"/mnt/hyperdisk_weights/hub/models--black-forest-labs--FLUX.2-klein-4B/snapshots",
60-
os.path.expanduser("~/.cache/huggingface/hub/models--black-forest-labs--FLUX.2-klein-4B/snapshots"),
61-
]
62-
self.model_dir = None
63-
for c in candidates:
64-
if os.path.exists(c):
65-
snaps = os.listdir(c)
66-
if snaps:
67-
self.model_dir = os.path.join(c, snaps[0])
68-
self.transformer_path = os.path.join(self.model_dir, "transformer")
69-
self.vae_path = os.path.join(self.model_dir, "vae", "diffusion_pytorch_model.safetensors")
70-
self.text_encoder_path = os.path.join(self.model_dir, "text_encoder")
71-
self.tokenizer_path = os.path.join(self.model_dir, "tokenizer")
72-
if os.path.exists(self.transformer_path) and os.path.exists(self.vae_path):
73-
break
74-
self.assertIsNotNone(self.model_dir, "FLUX.2-Klein 4B model directory not found!")
75-
76-
self.output_dir = "/mnt/data/e2e_parity" if os.path.exists("/mnt/data") else "/tmp/e2e_parity"
57+
if "FLUX2_KLEIN_4B_MODEL_PATH" in os.environ:
58+
self.model_dir = os.environ["FLUX2_KLEIN_4B_MODEL_PATH"]
59+
else:
60+
hf_home = os.environ.get("HF_HOME", os.path.expanduser("~/.cache/huggingface"))
61+
candidates = [
62+
os.path.join(hf_home, "hub/models--black-forest-labs--FLUX.2-klein-4B/snapshots"),
63+
os.path.join(hf_home, "hub/models--black-forest-labs--FLUX.2-klein-4b/snapshots"),
64+
"/mnt/hyperdisk_weights/hub/models--black-forest-labs--FLUX.2-klein-4B/snapshots",
65+
"/mnt/data/models/flux2klein-4b",
66+
]
67+
self.model_dir = None
68+
for c in candidates:
69+
if os.path.exists(c):
70+
if "snapshots" in c:
71+
snaps = os.listdir(c)
72+
if snaps:
73+
self.model_dir = os.path.join(c, snaps[0])
74+
else:
75+
self.model_dir = c
76+
if self.model_dir:
77+
self.transformer_path = os.path.join(self.model_dir, "transformer")
78+
self.vae_path = os.path.join(self.model_dir, "vae", "diffusion_pytorch_model.safetensors")
79+
self.text_encoder_path = os.path.join(self.model_dir, "text_encoder")
80+
self.tokenizer_path = os.path.join(self.model_dir, "tokenizer")
81+
if os.path.exists(self.transformer_path) and os.path.exists(self.vae_path):
82+
break
83+
if self.model_dir is None:
84+
self.model_dir = "black-forest-labs/FLUX.2-klein-4B"
85+
86+
if hasattr(self, "model_dir") and self.model_dir and not hasattr(self, "transformer_path"):
87+
self.transformer_path = os.path.join(self.model_dir, "transformer")
88+
self.vae_path = os.path.join(self.model_dir, "vae", "diffusion_pytorch_model.safetensors")
89+
self.text_encoder_path = os.path.join(self.model_dir, "text_encoder")
90+
self.tokenizer_path = os.path.join(self.model_dir, "tokenizer")
91+
92+
self.output_dir = "/tmp/e2e_parity"
7793
os.makedirs(self.output_dir, exist_ok=True)
7894

7995
# Resolve reference images
80-
ref_dir = "/mnt/data/golden_image_edit_data/ref_images"
96+
ref_dir = os.path.join(THIS_DIR, "images", "flux2klein")
8197
self.ref_images = []
8298
if os.path.exists(ref_dir):
8399
for i in range(4):

src/maxdiffusion/tests/generate_flux2klein_smoke_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_flux2klein_4b_smoke(self):
4141
self.assertTrue(os.path.exists(ref_path), f"Reference image not found: {ref_path}")
4242
base_image = np.array(Image.open(ref_path)).astype(np.uint8)
4343

44-
output_dir = "/mnt/data/smoke_test_4b" if os.path.exists("/mnt/data") else "/tmp/smoke_test_4b"
44+
output_dir = "/tmp/smoke_test_4b"
4545
os.makedirs(output_dir, exist_ok=True)
4646
out_path = os.path.join(output_dir, "flux2klein_generated_image.png")
4747
if os.path.exists(out_path):
@@ -86,7 +86,7 @@ def test_flux2klein_9b_smoke(self):
8686
self.assertTrue(os.path.exists(ref_path), f"Reference image not found: {ref_path}")
8787
base_image = np.array(Image.open(ref_path)).astype(np.uint8)
8888

89-
output_dir = "/mnt/data/smoke_test_9b" if os.path.exists("/mnt/data") else "/tmp/smoke_test_9b"
89+
output_dir = "/tmp/smoke_test_9b"
9090
os.makedirs(output_dir, exist_ok=True)
9191
out_path = os.path.join(output_dir, "flux2klein_generated_image.png")
9292
if os.path.exists(out_path):
@@ -134,7 +134,7 @@ def test_flux2klein_4b_image_edit_smoke(self):
134134
input_img_path = os.path.join(THIS_DIR, "images", "ref_flux2klein_4b.png")
135135
self.assertTrue(os.path.exists(input_img_path), f"Input reference image not found: {input_img_path}")
136136

137-
output_dir = "/mnt/data/smoke_test_image_edit_4b" if os.path.exists("/mnt/data") else "/tmp/smoke_test_image_edit_4b"
137+
output_dir = "/tmp/smoke_test_image_edit_4b"
138138
os.makedirs(output_dir, exist_ok=True)
139139
out_path = os.path.join(output_dir, "flux2klein_generated_image.png")
140140
if os.path.exists(out_path):
@@ -183,7 +183,7 @@ def test_flux2klein_9b_image_edit_smoke(self):
183183
input_img_path = os.path.join(THIS_DIR, "images", "ref_flux2klein_4b.png")
184184
self.assertTrue(os.path.exists(input_img_path), f"Input reference image not found: {input_img_path}")
185185

186-
output_dir = "/mnt/data/smoke_test_image_edit_9b" if os.path.exists("/mnt/data") else "/tmp/smoke_test_image_edit_9b"
186+
output_dir = "/tmp/smoke_test_image_edit_9b"
187187
os.makedirs(output_dir, exist_ok=True)
188188
out_path = os.path.join(output_dir, "flux2klein_generated_image.png")
189189
if os.path.exists(out_path):
429 KB
Loading
406 KB
Loading
384 KB
Loading
320 KB
Loading

0 commit comments

Comments
 (0)