Perf(LTX2): Comprehensive XLA, Memory, and Transformer Code Quality Optimizations#422
Open
Perseus14 wants to merge 1 commit into
Open
Perf(LTX2): Comprehensive XLA, Memory, and Transformer Code Quality Optimizations#422Perseus14 wants to merge 1 commit into
Perseus14 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is a comprehensive refactor and optimization sweep. It brings massive improvements to XLA compilation times, memory usage (HBM), and architectural hygiene by stripping out redundant compute, unifying duplicated logic, and optimizing JAX tracing.
🧹 Architectural Hygiene & Code Quality
LTX2VideoTransformer3DModel.__call__. The 4 separate block execution paths (scan vs. loop, perturbation vs. no-perturbation) have been consolidated using a newTransformerContextcontainer and a singleapply_blockhelper function.prepare_video_coords: Deleted the wasteful 5Dlatent_coordsblock inattention_ltx2.pythat was computing an unused, wrongly-shaped tensor only to immediately overwrite it.apply_split_rotary_emb: Cleaned up the convoluted reshape/broadcast logic for split RoPE. Removed the redundantexpand_dimsandsqueezeoperations, executing the rotation directly (first_x * cos - second_x * sin) to avoid allocating unnecessary intermediate 5D tensors.hasattr(self, "rope_type")check inLTX2Attention.max_logging.logwarning when defaulting to a zero-seedjax.random.key(0)for noise generation.⚡ XLA & JAX Compilation Optimizations
guidance_scale,stg_scale,audio_guidance_scale, etc.) fromstatic_argnamesinrun_diffusion_loop(). Tweaking these generation scales will no longer trigger expensive 10-30 minute JAX recompilations!if guidance_rescale > 0:check inside the compiled diffusion loop withjax.lax.cond. This enables the CFG rescaling logic to be fully dynamic, complementing the removal of the static scales and fixing formulation inconsistencies.nnx.scanwith standardjax.lax.scanfor the primary denoising timestep loop to ensure predictable compilation.RuntimeProgramInputMismatchforscan_layers=False: Resolved an issue where XLA would fail during warmup compilation due to unrolled layer layout mismatches. Added explicit@jax.jitwrappers withjax.lax.with_sharding_constraintto enforce layout transpositions before crossing intorun_diffusion_loop.🧠 Memory (HBM) Optimizations
target_dtypeupfront and mapping it directly, avoiding a redundant double-casting pipeline that was passing throughbfloat16.