@@ -81,12 +81,16 @@ def prepare_text_ids(batch_size, seq_len):
8181class GenerateFlux2KleinTest (unittest .TestCase ):
8282
8383 def test_generate_random_latents_shape (self ):
84+ import torch
85+
8486 latents = torch .randn ((2 , 32 , 1024 // 8 , 512 // 8 ))
8587 expected_shape = (2 , 32 , 1024 // 8 , 512 // 8 )
8688 self .assertEqual (tuple (latents .shape ), expected_shape )
8789
8890 def test_load_golden_latents_shape (self ):
8991 # Deterministically generate initial latents on CPU using seed 0
92+ import torch
93+
9094 generator = torch .Generator (device = "cpu" ).manual_seed (0 )
9195 latents_pt = torch .randn ((1 , 32 , 64 , 64 ), generator = generator , dtype = torch .float32 )
9296 expected_shape = (1 , 32 , 512 // 8 , 512 // 8 )
@@ -110,6 +114,7 @@ def test_qwen3_prompt_embeddings(self):
110114 self .fail (f"Failed to generate prompt embeddings: { e } " )
111115
112116 def test_context_embedder_projection (self ):
117+ import os
113118 import torch
114119 import jax
115120 import jax .numpy as jnp
@@ -329,11 +334,14 @@ def test_scheduler_timesteps_parity(self):
329334
330335 def test_attention_blocks_parity (self ):
331336 """Verifies that JAX joint-attention (double) and single-stream blocks match PyTorch golden outputs."""
337+ import os
338+ import torch
332339 import jax
333340 import jax .numpy as jnp
334341 import flax
335342 from flax .linen import partitioning as nn_partitioning
336343 from jax .sharding import Mesh
344+ from safetensors .torch import load_file
337345
338346 from maxdiffusion .models .flux .transformers .transformer_flux_flax import FluxTransformer2DModel
339347 from maxdiffusion import pyconfig
@@ -491,6 +499,7 @@ def test_attention_blocks_parity(self):
491499
492500 def test_full_transformer_and_multistep_parity (self ):
493501 """Verifies full JAX transformer forward pass (all blocks) and 4-step denoising loop parity against PyTorch."""
502+ import os
494503 import torch
495504 import jax
496505
@@ -704,6 +713,7 @@ def callback_fn(pipe, step_idx, timestep, callback_kwargs):
704713
705714 def test_vae_decoder_parity (self ):
706715 """Verifies JAX FlaxAutoencoderKL VAE Decoder parity against PyTorch."""
716+ import os
707717 import jax
708718 import jax .numpy as jnp
709719 import numpy as np
@@ -876,7 +886,7 @@ def get_w(key):
876886
877887 # 7. Compare raw decoder output
878888 diff_raw = jnp .abs (jax_decoder_out .sample - golden_decoder_out_pt )
879- print ("\n [VAE DIAG] Raw Decoder Output Comparison:" )
889+ print (f "\n [VAE DIAG] Raw Decoder Output Comparison:" )
880890 print (f"[VAE DIAG] Max absolute diff: { jnp .max (diff_raw )} " )
881891 print (f"[VAE DIAG] Mean absolute diff: { jnp .mean (diff_raw )} " )
882892
@@ -904,6 +914,7 @@ def test_10_point_isolated_parity_benchmark(self):
904914
905915 def test_swiglu_mlp_math_parity (self ):
906916 """Verifies SwiGLU MLP mathematical parity between JAX and PyTorch."""
917+ import torch
907918 import jax
908919 import jax .numpy as jnp
909920 import numpy as np
@@ -956,6 +967,7 @@ def test_attention_math_parity(self):
956967 pyconfig ._config .keys ["activations_dtype" ] = "float32"
957968 config = pyconfig .config
958969
970+ import torch
959971 import jax
960972 import jax .numpy as jnp
961973 import numpy as np
@@ -1052,6 +1064,8 @@ def test_attention_math_parity(self):
10521064
10531065 def test_flowmatch_scheduler_parity (self ):
10541066 """Verifies FlowMatch Euler Discrete Scheduler stepping parity against PyTorch."""
1067+ import torch
1068+ import jax
10551069 import jax .numpy as jnp
10561070 import numpy as np
10571071 from diffusers import FlowMatchEulerDiscreteScheduler
@@ -1103,6 +1117,7 @@ def test_double_transformer_block_dummy_parity(self):
11031117 pyconfig ._config .keys ["activations_dtype" ] = "float32"
11041118 config = pyconfig .config
11051119
1120+ import torch
11061121 import jax
11071122 import jax .numpy as jnp
11081123 import numpy as np
@@ -1231,6 +1246,7 @@ def test_single_transformer_block_dummy_parity(self):
12311246 pyconfig ._config .keys ["activations_dtype" ] = "float32"
12321247 config = pyconfig .config
12331248
1249+ import torch
12341250 import jax
12351251 import jax .numpy as jnp
12361252 import numpy as np
0 commit comments