We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0eb3a58 commit bc5c0cbCopy full SHA for bc5c0cb
7 files changed
src/maxdiffusion/generate_flux2klein.py
@@ -58,7 +58,9 @@ def partition_prompts(prompt_str: str, batch_size: int) -> List[str]:
58
active.extend([raw_prompts[-1]] * (batch_size - len(active)))
59
return active
60
else:
61
- print(f"⚠️ Warning: Found {num_prompts} prompts, but batch_size is {batch_size}. Truncating to the first {batch_size}.")
+ max_logging.log(
62
+ f"⚠️ Warning: Found {num_prompts} prompts, but batch_size is {batch_size}. Truncating to the first {batch_size}."
63
+ )
64
return raw_prompts[:batch_size]
65
66
@@ -405,7 +407,7 @@ def unbox_fn(x):
405
407
)
406
408
409
# 10. Instantiate and invoke FlaxFlux2KleinPipeline
- print("Instantiating JAX FlaxFlux2KleinPipeline...")
410
+ max_logging.log("Instantiating JAX FlaxFlux2KleinPipeline...")
411
pipeline = FlaxFlux2KleinPipeline(
412
transformer=transformer,
413
vae=vae,
src/maxdiffusion/models/attention_flax.py
@@ -1697,11 +1697,21 @@ def apply_rope(xq: Array, xk: Array, freqs_cis: Any) -> tuple[Array, Array]:
1697
if isinstance(freqs_cis, (tuple, list)):
1698
cos, sin = freqs_cis
1699
if cos.ndim == 2:
1700
- cos = cos[None, :, None, :]
1701
- sin = sin[None, :, None, :]
+ seq_len = cos.shape[0]
+ if xq.ndim == 4 and xq.shape[2] == seq_len:
1702
+ cos = cos[None, None, :, :]
1703
+ sin = sin[None, None, :, :]
1704
+ else:
1705
+ cos = cos[None, :, None, :]
1706
+ sin = sin[None, :, None, :]
1707
elif cos.ndim == 3 and cos.shape[0] == 1:
- cos = cos[:, :, None, :]
- sin = sin[:, :, None, :]
1708
+ seq_len = cos.shape[1]
1709
1710
+ cos = cos[:, None, :, :]
1711
+ sin = sin[:, None, :, :]
1712
1713
+ cos = cos[:, :, None, :]
1714
+ sin = sin[:, :, None, :]
1715
1716
def _rotate(x):
1717
x_reshaped = x.reshape(*x.shape[:-1], -1, 2)
src/maxdiffusion/models/embeddings_flax.py
@@ -20,6 +20,7 @@
20
from .modeling_flax_utils import get_activation
21
from ..models.attention_flax import NNXSimpleFeedForward
22
from ..models.normalization_flax import FP32LayerNorm
23
+from maxdiffusion import max_logging
24
from maxdiffusion.tpu_utils import get_tpu_type, TpuType
25
from maxdiffusion.max_utils import safe_getattr
26
@@ -296,7 +297,7 @@ def __call__(self, encoder_hidden_states_image: jax.Array) -> tuple[jax.Array, j
296
297
# Apply pos_embed to the original sequence length
298
hidden_states = hidden_states.at[:, :add_len, :].add(self.pos_embed.value[:, :add_len, :])
299
if current_seq_len > pe_len:
- print(f"[WARN] Input seq_len {current_seq_len} > pos_embed len {pe_len}")
300
+ max_logging.log(f"[WARN] Input seq_len {current_seq_len} > pos_embed len {pe_len}")
301
302
hidden_states = self.norm1(hidden_states)
303
hidden_states = self.ff(hidden_states)
src/maxdiffusion/pipelines/flux/flux2klein_pipeline.py
@@ -110,7 +110,7 @@ def _prepare_latents(self, config, batch_size, height, width):
110
seed_val = getattr(config, "seed", None)
111
if seed_val is None:
112
seed_val = int(time.time()) & 0x7FFFFFFF
113
- print(
114
f"Generating random gaussian noise in unpacked space (32 channels) with seed: {seed_val} and shape: {latent_shape}..."
115
116
np.random.seed(seed_val)
@@ -215,7 +215,10 @@ def __call__(
215
tokenizer = Qwen2TokenizerFast.from_pretrained(tokenizer_path, subfolder="tokenizer", local_files_only=True)
216
217
# Tokenize using deterministic explicit template string (version-agnostic across transformers versions)
218
- templated_texts = [f"<|im_start|>user\n{p}<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n" for p in prompts]
+ templated_texts = [
219
+ f"<|im_start|>user\n{p}<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
220
+ for p in prompts
221
+ ]
222
max_logging.log(f"DEBUG: templated_texts[0] = {repr(templated_texts[0])}")
223
inputs = tokenizer(templated_texts, return_tensors="np", padding="max_length", truncation=True, max_length=seq_len_txt)
224
prompt_ids = jnp.array(inputs["input_ids"])
@@ -243,9 +246,7 @@ def __call__(
243
246
# ---------------------------------------------------------------------
244
247
# PHASE B: Denoising Loop (Flux Transformer)
245
248
- max_logging.log(
- f"[PHASE B] Running {num_inference_steps}-step E2E Denoising Loop on a batch of {batch_size} images..."
- )
249
+ max_logging.log(f"[PHASE B] Running {num_inference_steps}-step E2E Denoising Loop on a batch of {batch_size} images...")
250
t0 = time.perf_counter()
251
252
guidance_vec_val = None
@@ -270,9 +271,7 @@ def __call__(
270
271
272
# Print progress
273
sigma_val = scheduler_state.sigmas[step_idx]
274
- f" -> Step {step_idx}: Timestep = {scheduler_state.timesteps[step_idx]:.4f}, Sigma = {sigma_val:.4f}"
275
+ max_logging.log(f" -> Step {step_idx}: Timestep = {scheduler_state.timesteps[step_idx]:.4f}, Sigma = {sigma_val:.4f}")
276
277
latents_jax.block_until_ready()
278
src/maxdiffusion/tests/generate_flux2klein_e2e_test.py
@@ -156,6 +156,7 @@ def main():
156
"python3",
157
"src/maxdiffusion/generate_flux2klein.py",
158
"src/maxdiffusion/configs/base_flux2klein.yml",
159
+ "skip_jax_distributed_system=True",
160
f"prompt={prompt}",
161
"output_dir=/tmp/",
162
f"seed={seed}",
@@ -175,14 +176,13 @@ def main():
175
176
jax_4b_paths = [f"/tmp/jax_4b_dancing_b{b}.png" for b in range(batch_size)]
177
print(f"[JAX 4B] Execution complete! Verifying outputs at: {jax_4b_paths}")
178
179
+ # =========================================================================
180
# =========================================================================
181
# PART II: FLUX.2-KLEIN-9B PARITY
182
183
print("\n" + "#" * 80)
184
print("🎬 STARTING PARITY EVALUATION FOR FLUX.2-KLEIN-9B")
185
print("#" * 80)
-
- # 1. Run PyTorch 9B (FP32 & BF16)
186
pt_9b_fp32_paths, pt_9b_bf16_paths = run_pytorch_pipeline(
187
model_id="black-forest-labs/FLUX.2-klein-9B",
188
prompt=prompt,
@@ -195,12 +195,12 @@ def main():
195
prefix="9b",
196
197
198
- # 2. Run JAX 9B (via generate_flux2klein.py)
199
print("\n[JAX 9B] Executing pipeline script generate_flux2klein.py...")
200
cmd_jax_9b = [
201
202
203
"src/maxdiffusion/configs/base_flux2klein_9B.yml",
204
205
206
src/maxdiffusion/tests/generate_flux2klein_smoke_test.py
@@ -118,3 +118,7 @@ def test_flux2klein_9b_smoke(self):
118
ssim_compare = ssim(base_image, test_image, channel_axis=-1, data_range=255)
119
print(f"\n[SMOKE TEST 9B] SSIM Score: {ssim_compare:.6f}")
120
self.assertGreaterEqual(ssim_compare, 0.80)
121
+
122
123
+if __name__ == "__main__":
124
+ unittest.main()
src/maxdiffusion/tests/images/ref_flux2klein_4b.png
-1.93 KB
0 commit comments