Skip to content

Commit 51fe554

Browse files
committed
refactor: improve cast exclusion and guidance conditional logic
1 parent ca268a6 commit 51fe554

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/maxdiffusion/pipelines/ltx2/ltx2_pipeline.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def _apply_ltx2_guidance(
179179
audio_guidance_rescale,
180180
do_cfg,
181181
do_stg,
182-
use_lax_cond=False,
183182
):
184183
"""Applies the shared LTX2 CFG/STG delta formulation to video and audio."""
185184
if not do_cfg:
@@ -199,7 +198,7 @@ def convert_to_vel(latents_to_convert, x0):
199198
return (latents_to_convert - x0) / sigma_t
200199

201200
def maybe_rescale(noise, text_noise, scale):
202-
if use_lax_cond:
201+
if isinstance(scale, jax.core.Tracer):
203202
return jax.lax.cond(
204203
scale > 0,
205204
lambda: rescale_noise_cfg(noise, text_noise, guidance_rescale=scale),
@@ -254,15 +253,13 @@ def maybe_rescale(noise, text_noise, scale):
254253

255254
logger = logging.get_logger(__name__)
256255

257-
_CAST_EXCLUSION_KEYWORDS = (
258-
"norm", # All LayerNorm/GroupNorm parameters.
259-
"condition_embedder", # The entire time/text conditioning module.
260-
"scale_shift_table", # The final and AdaLN scale/shift tables.
261-
)
256+
import re
257+
258+
_CAST_EXCLUSION_PATTERN = re.compile(r"(^|\.)(norm[0-9]*|.*_norm[0-9]*|norm_out|condition_embedder|scale_shift_table)(\.|$)")
262259

263260

264261
def _is_cast_excluded(path_str: str) -> bool:
265-
return any(keyword in path_str.lower() for keyword in _CAST_EXCLUSION_KEYWORDS)
262+
return bool(_CAST_EXCLUSION_PATTERN.search(path_str.lower()))
266263

267264

268265
def _final_param_dtype(flax_key: tuple, dtype_to_cast) -> np.dtype:
@@ -2164,7 +2161,6 @@ def __call__(
21642161
audio_guidance_rescale,
21652162
do_cfg,
21662163
do_stg,
2167-
use_lax_cond=False,
21682164
)
21692165

21702166
latents_step, _ = self.scheduler.step(scheduler_state, noise_pred, t, latents_step, return_dict=False)
@@ -2659,7 +2655,6 @@ def scan_body(carry, inputs):
26592655
audio_guidance_rescale,
26602656
do_cfg,
26612657
do_stg,
2662-
use_lax_cond=True,
26632658
)
26642659

26652660
# Step scheduler

0 commit comments

Comments
 (0)