Skip to content

Commit cb41176

Browse files
committed
refactoring code + new more streamlined test scripts
1 parent fb89b8a commit cb41176

14 files changed

Lines changed: 2722 additions & 1635 deletions

src/maxdiffusion/configs/base_flux2klein.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,9 @@ width: 1024
270270
batch_size: 4
271271
interactive: False
272272

273+
# 4B Architecture Dimensions
274+
depth: 20 # num_single_layers
275+
num_double_layers: 5
276+
hidden_size: 3072
277+
num_attention_heads: 24
278+

src/maxdiffusion/configs/base_flux_dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ t5xxl_model_name_or_path: 'ariG23498/t5-v1-1-xxl-flax'
3333

3434
# Flux params
3535
flux_name: "flux-dev"
36+
scale_shift_order: "shift_scale"
3637
max_sequence_length: 512
3738
time_shift: True
3839
base_shift: 0.5

src/maxdiffusion/generate_flux2klein.py

Lines changed: 247 additions & 973 deletions
Large diffs are not rendered by default.

src/maxdiffusion/models/flux/util.py

Lines changed: 347 additions & 0 deletions
Large diffs are not rendered by default.

src/maxdiffusion/models/qwen3_flax.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,15 @@ def get_w(name: str, transpose: bool = True) -> np.ndarray:
462462

463463
else:
464464
print(f"WARNING: JAX parameter '{path_str}' did not match any PyTorch weights!")
465-
converted_flat[k] = v
465+
converted_flat[k] = np.zeros(v.shape, dtype=np.float32) if hasattr(v, 'shape') and not isinstance(v, np.ndarray) else v
466466

467467
# Clean up PyTorch memory immediately
468468
del torch_weights
469469
import gc
470470
gc.collect()
471471

472-
print("Qwen3 weight conversion completed successfully!")
473-
return flax.traverse_util.unflatten_dict(converted_flat)
472+
res = flax.traverse_util.unflatten_dict(converted_flat)
473+
return jax.tree_util.tree_map(
474+
lambda leaf: jnp.zeros(leaf.shape, dtype=leaf.dtype) if isinstance(leaf, jax.ShapeDtypeStruct) else leaf,
475+
res
476+
)

src/maxdiffusion/pipelines/flux/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
from .flux_pipeline import (
2020
FluxPipeline,
2121
)
22+
from .flux2klein_pipeline import (
23+
FlaxFlux2KleinPipeline,
24+
)

0 commit comments

Comments
 (0)