Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/maxdiffusion/generate_wan.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,15 @@ def run(config, pipeline=None, filename_prefix="", commit_hash=None):
vae_decode_total = trace.get("vae_decode", 0.0)
vae_decode_tpu = trace.get("vae_decode_tpu", 0.0)
vae_decode_post = vae_decode_total - vae_decode_tpu
summary.extend(
[
f" {'─' * 40}",
f" Conditioning: {trace.get('conditioning', 0.0):>7.1f}s",
f" - VAE Encode: {trace.get('vae_encode', 0.0):>7.1f}s",
f" Denoise Total: {trace.get('denoise_total', 0.0):>7.1f}s",
f" VAE Decode: {vae_decode_total:>7.1f}s",
f" - TPU Compute: {vae_decode_tpu:>7.1f}s",
f" - Host Formatting: {vae_decode_post:>7.1f}s",
]
)
summary.extend([
f" {'─' * 40}",
f" Conditioning: {trace.get('conditioning', 0.0):>7.1f}s",
f" - VAE Encode: {trace.get('vae_encode', 0.0):>7.1f}s",
f" Denoise Total: {trace.get('denoise_total', 0.0):>7.1f}s",
f" VAE Decode: {vae_decode_total:>7.1f}s",
f" - TPU Compute: {vae_decode_tpu:>7.1f}s",
f" - Host Formatting: {vae_decode_post:>7.1f}s",
])
summary.append(f"{'=' * 50}")
max_logging.log("\n".join(summary))

Expand Down
16 changes: 7 additions & 9 deletions src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,13 @@ def run_inference_2_1(
transformer_obj = nnx.merge(graphdef, sharded_state, rest_of_state)

# Compute RoPE once as it only depends on shape
dummy_hidden_states = jnp.zeros(
(
latents.shape[0],
latents.shape[2],
latents.shape[3],
latents.shape[4],
latents.shape[1],
)
)
dummy_hidden_states = jnp.zeros((
latents.shape[0],
latents.shape[2],
latents.shape[3],
latents.shape[4],
latents.shape[1],
))
rotary_emb = transformer_obj.rope(dummy_hidden_states)

kv_cache = None
Expand Down
24 changes: 11 additions & 13 deletions src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,19 +971,17 @@ def scan_body(carry, t):
# tracing both 14B branches per step and keeps the AOT cache usable.
use_high_noise = bool(np.asarray(scheduler_state.timesteps)[step] >= np.asarray(boundary))
branch = high_noise_branch if use_high_noise else low_noise_branch
noise_pred, _ = branch(
(
latent_model_input,
timestep,
prompt_embeds_combined,
image_embeds_combined,
kv_cache_high,
kv_cache_low,
rotary_emb,
encoder_attention_mask_high,
encoder_attention_mask_low,
)
)
noise_pred, _ = branch((
latent_model_input,
timestep,
prompt_embeds_combined,
image_embeds_combined,
kv_cache_high,
kv_cache_low,
rotary_emb,
encoder_attention_mask_high,
encoder_attention_mask_low,
))
noise_pred = jnp.transpose(noise_pred, (0, 2, 3, 4, 1))
latents, scheduler_state = scheduler.step(scheduler_state, noise_pred, t, latents).to_tuple()

Expand Down
36 changes: 17 additions & 19 deletions src/maxdiffusion/tests/aot_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,23 @@ def test_signature_deterministic_across_processes(self):
import subprocess
import sys

snippet = "\n".join(
(
"import os",
"os.environ['JAX_PLATFORMS'] = 'cpu'",
"import jax",
"import jax.numpy as jnp",
"from flax import nnx",
"from maxdiffusion import aot_cache",
"",
"class T(nnx.Module):",
" def __init__(self, rngs):",
" self.lin = nnx.Linear(4, 4, rngs=rngs)",
"",
"graphdef, state = nnx.split(T(nnx.Rngs(0)))",
"sig = aot_cache._dynamic_signature(",
" (graphdef, state.to_pure_dict(), jnp.ones((2, 4))), {})",
"print(sig)",
)
)
snippet = "\n".join((
"import os",
"os.environ['JAX_PLATFORMS'] = 'cpu'",
"import jax",
"import jax.numpy as jnp",
"from flax import nnx",
"from maxdiffusion import aot_cache",
"",
"class T(nnx.Module):",
" def __init__(self, rngs):",
" self.lin = nnx.Linear(4, 4, rngs=rngs)",
"",
"graphdef, state = nnx.split(T(nnx.Rngs(0)))",
"sig = aot_cache._dynamic_signature(",
" (graphdef, state.to_pure_dict(), jnp.ones((2, 4))), {})",
"print(sig)",
))
outs = [
subprocess.run(
[sys.executable, "-c", snippet],
Expand Down
Loading