Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95df6f9
LTX2 and LTX2.3 improvements and Tile-size auto-tuning
Perseus14 Jul 24, 2026
ea8b413
fix: use full step count for warmup when scan_diffusion_loop=True
Perseus14 Jul 25, 2026
2e01b44
fix: reject incompatible LTX2 KV cache
Perseus14 Jul 25, 2026
d3f3e5e
fix: complete LTX2 KV cache and named scopes
Perseus14 Jul 25, 2026
a97317f
fix: strengthen LTX2 AOT cache key
Perseus14 Jul 25, 2026
6e13344
refactor: deduplicate LTX2 guidance paths
Perseus14 Jul 25, 2026
1c738c7
Fix LTX2 TPU correctness and cache safety
Perseus14 Jul 27, 2026
434e84f
Implement persistent converted-weight caching for LTX2
Perseus14 Jul 27, 2026
037b055
perf: optimize video postprocessing natively on TPU via JAX
Perseus14 Jul 27, 2026
08ba652
Revert "perf: optimize video postprocessing natively on TPU via JAX"
Perseus14 Jul 27, 2026
3a88a1a
perf: vectorize postprocessing to bypass PyTorch CPU processor overhead
Perseus14 Jul 27, 2026
8c9c78c
perf: fix video postprocessing thrash natively on TPU
Perseus14 Jul 28, 2026
02ad821
style: fix ruff dict literal warning
Perseus14 Jul 28, 2026
0404031
style: fix ruff linting errors across src
Perseus14 Jul 28, 2026
0819ce2
perf: simplify LTX2 caching with atomic WAN-style persistent memoization
Perseus14 Jul 28, 2026
cce204e
fix: unflatten dictionary for try_load_converted_weights cache logic
Perseus14 Jul 28, 2026
1283a54
style: remove unused expected_shapes from cache cleanup
Perseus14 Jul 28, 2026
2eb0e8a
fix: restore expected_dtypes used for casting
Perseus14 Jul 28, 2026
6b3cae3
Optimize LTX2: AOT Timestep Embedding Precomputation (Vectorized)
Perseus14 Jul 29, 2026
83982f0
Fix model loading for scan_layers=False: remove manual string casting…
Perseus14 Jul 29, 2026
bb3ee40
Apply formatting to LTX2 transformer and pipeline files
Perseus14 Jul 29, 2026
fedbc0d
Fix generate_ltx2 lint errors, remove LTX2_AOT_CACHE_ABI, and remove …
Perseus14 Jul 29, 2026
c1972f0
perf: jit compile tpu video formatting to avoid memory thrash
Perseus14 Jul 29, 2026
9fe8632
perf: completely bypass PIL image creation by introducing np_uint8 ou…
Perseus14 Jul 29, 2026
89ba388
perf: remove jax.jit from postprocessing to avoid compilation overhead
Perseus14 Jul 29, 2026
411714b
chore: delete converted_weights_cache_v2_test
Perseus14 Jul 29, 2026
188ac7d
fix: hardcoded upsampler_output_type pil in configs overriding np_uint8
Perseus14 Jul 29, 2026
f1f9f80
test: remove obsolete ltx2_abi_changes_cache_fingerprint test
Perseus14 Jul 29, 2026
30c6b82
style: apply ruff and pyink formatting fixes
Perseus14 Jul 29, 2026
b0f9b9b
fix: move tpu format methods to module scope to prevent RecursionErro…
Perseus14 Jul 29, 2026
ef39a0d
fix: resolve python anti-patterns in gcs and caching logic
Perseus14 Jul 29, 2026
db29fb9
test: fix mock_config.seed throwing ValueError in test_load_and_init
Perseus14 Jul 29, 2026
26ae907
test: fix mock_load_transformer assertions in test_load_and_init
Perseus14 Jul 29, 2026
65be114
refactor: apply code quality fixes to generate_ltx2 and aot_cache
Perseus14 Jul 29, 2026
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
32 changes: 24 additions & 8 deletions src/maxdiffusion/aot_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def transformer_forward_pass(...):
import hashlib
import inspect
import os
import json
import pickle
import re
import threading
Expand All @@ -72,6 +73,12 @@ def transformer_forward_pass(...):
_FORMAT_VERSION = 1


def _metadata_fingerprint(meta: dict[str, Any]) -> str:
"""Returns the stable filename fingerprint for install-time metadata."""
serialized = json.dumps(meta, sort_keys=True)
return hashlib.sha256(serialized.encode("utf-8")).hexdigest()[:12]


def _dynamic_signature(args: tuple, kwargs: dict) -> str:
"""Deterministic digest of everything that selects an executable.

Expand Down Expand Up @@ -372,21 +379,30 @@ def install(cache_dir: str, meta: dict[str, Any], mesh: Any) -> None:
mesh: The pipeline mesh; pins device order for deserialization and
provides the context for re-lowering at save time.
"""
if not cache_dir:
return
os.makedirs(cache_dir, exist_ok=True)
_STATE.cache_dir = cache_dir
_STATE.fingerprint = hashlib.sha256(repr(sorted(meta.items())).encode()).hexdigest()[:12]
_STATE.mesh = mesh
_STATE.enabled = True
# A process may construct multiple pipelines with different cache settings.
# Finish any previous loads, then reset all install-scoped state even when
# the new cache directory is empty.
wait_for_loads()
_STATE.cache_dir = ""
_STATE.fingerprint = ""
_STATE.mesh = None
_STATE.enabled = False
for entry in _REGISTRY:
with entry._lock:
# Cached state belongs to the previous install's dir/fingerprint.
entry._compiled.clear()
entry._out_specs.clear()
entry._pending.clear()
entry._adapters.clear()
entry._on_disk.clear()

if not cache_dir:
return
os.makedirs(cache_dir, exist_ok=True)
_STATE.cache_dir = cache_dir
_STATE.fingerprint = _metadata_fingerprint(meta)
_STATE.mesh = mesh
_STATE.enabled = True
for entry in _REGISTRY:
thread = threading.Thread(target=entry.load_from_disk, name=f"aot-load-{entry.name}", daemon=True)
thread.start()
_LOAD_THREADS.append(thread)
Expand Down
34 changes: 32 additions & 2 deletions src/maxdiffusion/configs/ltx2_3_video.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#hardware
hardware: 'tpu'
skip_jax_distributed_system: False
# Supported attention kernels:
# dot_product, flash, tokamax_flash, tokamax_ring, tokamax_ring_custom,
# ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_ring,
# ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_bidir,
# and cudnn_flash_te (GPU only).
attention: 'flash'
use_base2_exp: False
use_experimental_scheduler: False
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
ulysses_attention_chunks: 1
a2v_attention_kernel: 'flash'
v2a_attention_kernel: 'dot_product'
attention_sharding_uniform: True
Expand All @@ -12,6 +23,8 @@ names_which_can_be_offloaded: []
remat_policy: "NONE"

jax_cache_dir: ''
# Local/shared filesystem directory for content-addressed PyTorch->Flax transformer weights ('' = disabled).
converted_weights_dir: ''
weights_dtype: 'bfloat16'
activations_dtype: 'bfloat16'
text_encoder_dtype: 'bfloat16'
Expand Down Expand Up @@ -94,7 +107,7 @@ flash_min_seq_length: 4096
dcn_context_parallelism: 1
dcn_tensor_parallelism: 1
ici_data_parallelism: 1
ici_fsdp_parallelism: 1
ici_fsdp_parallelism: 1
ici_context_parallelism: -1 # recommended ICI axis to be auto-sharded
ici_tensor_parallelism: 1
enable_profiler: False
Expand All @@ -106,6 +119,10 @@ enable_ondemand_xprof: True
skip_first_n_steps_for_profiler: 0
profiler_steps: 5

# Enable JAX named scopes for detailed profiling and debugging
# When enabled, adds named scopes around key operations in transformer and attention layers
enable_jax_named_scopes: False

replicate_vae: False

run_text_encoder_on_tpu: False
Expand Down Expand Up @@ -173,4 +190,17 @@ upsampler_temporal_patch_size: 1
upsampler_adain_factor: 0.0
upsampler_tone_map_compression_ratio: 0.0
upsampler_rational_spatial_scale: 2.0
upsampler_output_type: "pil"
upsampler_output_type: "np_uint8"

aot_cache_dir: ''
# Immutable package/build revision used when Git metadata is unavailable.
aot_build_revision: ''
# Tile-size auto-tuning. When enable_tile_search: True, generate_ltx2 runs a fast one-DiT-block
# grid search (maxdiffusion/utils/tile_size_grid_search.py) before inference and updates every
# effective flash_block_sizes field with the winner. Default off (no-op).
enable_tile_search: False
tile_search_mode: 'smart' # 'smart' (VMEM-capped candidate ladders) | 'full' (2D sweep)
tile_search_iters: 10
tile_search_out: '' # dir for the results CSV; '' -> print only
tile_search_vmem_limit_bytes: 67108864 # 64 MiB; shared by benchmark and production custom kernels
use_kv_cache: False
34 changes: 32 additions & 2 deletions src/maxdiffusion/configs/ltx2_video.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#hardware
hardware: 'tpu'
skip_jax_distributed_system: False
# Supported attention kernels:
# dot_product, flash, tokamax_flash, tokamax_ring, tokamax_ring_custom,
# ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_ring,
# ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_bidir,
# and cudnn_flash_te (GPU only).
attention: 'flash'
use_base2_exp: False
use_experimental_scheduler: False
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
ulysses_attention_chunks: 1
a2v_attention_kernel: 'dot_product'
v2a_attention_kernel: 'dot_product'
attention_sharding_uniform: True
Expand All @@ -18,6 +29,8 @@ names_which_can_be_offloaded: []
remat_policy: "NONE"

jax_cache_dir: ''
# Local/shared filesystem directory for content-addressed PyTorch->Flax transformer weights ('' = disabled).
converted_weights_dir: ''
weights_dtype: 'bfloat16'
activations_dtype: 'bfloat16'
text_encoder_dtype: 'bfloat16'
Expand Down Expand Up @@ -99,7 +112,7 @@ flash_min_seq_length: 4096
dcn_context_parallelism: 1
dcn_tensor_parallelism: 1
ici_data_parallelism: 1
ici_fsdp_parallelism: 1
ici_fsdp_parallelism: 1
ici_context_parallelism: -1 # recommended ICI axis to be auto-sharded
ici_tensor_parallelism: 1
enable_profiler: False
Expand All @@ -111,6 +124,10 @@ enable_ondemand_xprof: True
skip_first_n_steps_for_profiler: 0
profiler_steps: 5

# Enable JAX named scopes for detailed profiling and debugging
# When enabled, adds named scopes around key operations in transformer and attention layers
enable_jax_named_scopes: False

replicate_vae: False
use_bwe: False

Expand Down Expand Up @@ -170,4 +187,17 @@ upsampler_temporal_patch_size: 1
upsampler_adain_factor: 0.0
upsampler_tone_map_compression_ratio: 0.0
upsampler_rational_spatial_scale: 2.0
upsampler_output_type: "pil"
upsampler_output_type: "np_uint8"

aot_cache_dir: ''
# Immutable package/build revision used when Git metadata is unavailable.
aot_build_revision: ''
# Tile-size auto-tuning. When enable_tile_search: True, generate_ltx2 runs a fast one-DiT-block
# grid search (maxdiffusion/utils/tile_size_grid_search.py) before inference and updates every
# effective flash_block_sizes field with the winner. Default off (no-op).
enable_tile_search: False
tile_search_mode: 'smart' # 'smart' (VMEM-capped candidate ladders) | 'full' (2D sweep)
tile_search_iters: 10
tile_search_out: '' # dir for the results CSV; '' -> print only
tile_search_vmem_limit_bytes: 67108864 # 64 MiB; shared by benchmark and production custom kernels
use_kv_cache: False
Loading
Loading