Skip to content

Update the LTX2 API calls during the calibration#926

Merged
jingyu-ml merged 2 commits intomainfrom
jingyux/ltx-2-update
Feb 24, 2026
Merged

Update the LTX2 API calls during the calibration#926
jingyu-ml merged 2 commits intomainfrom
jingyux/ltx-2-update

Conversation

@jingyu-ml
Copy link
Contributor

@jingyu-ml jingyu-ml commented Feb 24, 2026

What does this PR do?

Type of change: Bug fix

Overview:

Update LTX-2 integration to match latest upstream API

  1. The LTX-2 codebase removed/replaced several APIs. This MR updates all affected files:
  2. Replace cfg_guidance_scale with MultiModalGuiderParams: The pipeline call no longer accepts a single cfg_guidance_scale float. It now requires two MultiModalGuiderParams objects (video_guider_params and audio_guider_params) that control CFG, STG, rescale, cross-modality guidance, and skip-step settings. Updated in ltx-2.py, ltx-2-fp8.py, ltx-2-onestage.py, calibration.py, and models_utils.py.
  3. Replace fp8transformer with QuantizationPolicy: The TI2VidTwoStagesPipeline constructor no longer accepts the fp8transformer boolean flag. FP8 quantization is now configured via quantization=QuantizationPolicy.fp8_cast(). Updated in ltx-2-fp8.py and pipeline_manager.py (with backwards-compatible support for the old --extra-param fp8transformer=true CLI flag).
  4. Remove DEFAULT_CFG_GUIDANCE_SCALE constant: Replaced by DEFAULT_VIDEO_GUIDER_PARAMS and DEFAULT_AUDIO_GUIDER_PARAMS in all import sites.

Usage

python quantize.py --model ltx-2 --format fp4 --batch-size 1 --calib-size 1 --n-steps 40 --extra-param checkpoint_path=./ltx-2-19b-dev-fp8.safetensors --extra-param distilled_lora_path=./ltx-2-19b-distilled-lora-384.safetensors --extra-param spatial_upsampler_path=./ltx-2-spatial-upscaler-x2-1.0.safetensors --extra-param gemma_root=./gemma-3-12b-it-qat-q4_0-unquantized --extra-param fp8transformer=true --hf-ckpt-dir ./ltx2-nvfp4

Testing

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes/No
  • Did you write any new necessary tests?: Yes/No
  • Did you add or update any necessary documentation?: Yes/No
  • Did you update Changelog?: Yes/No

Additional Information

Summary by CodeRabbit

Release Notes

  • Updates
    • Default resolution for LTX2 models adjusted to 768x1280
    • Guidance parameter configuration updated for video and audio pipelines
    • FP8 quantization parameter handling refined

Signed-off-by: Jingyu Xin <jingyux@nvidia.com>
@jingyu-ml jingyu-ml requested a review from a team as a code owner February 24, 2026 06:05
@jingyu-ml jingyu-ml requested a review from Edwardf0t1 February 24, 2026 06:05
@jingyu-ml jingyu-ml self-assigned this Feb 24, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes update the LTX2 pipeline configuration by replacing the cfg_guidance_scale parameter with separate video_guider_params and audio_guider_params, removing cfg_guidance_scale from model defaults while adjusting resolution values, and replacing the fp8transformer boolean flag with a new fp8_quantization-driven quantization policy approach.

Changes

Cohort / File(s) Summary
Guidance Parameters Refactoring
examples/diffusers/quantization/calibration.py
Replaces cfg_guidance_scale parameter with DEFAULT_VIDEO_GUIDER_PARAMS and DEFAULT_AUDIO_GUIDER_PARAMS imports and passes two separate guider parameter bundles to calibration pipeline invocation.
Model Defaults Update
examples/diffusers/quantization/models_utils.py
Adjusts LTX2 model resolution from 1024x1536 to 768x1280 and removes cfg_guidance_scale entry from inference defaults configuration.
Quantization Policy Refactoring
examples/diffusers/quantization/pipeline_manager.py
Replaces fp8transformer boolean flag with fp8_quantization parameter and maps it to a new quantization pipeline argument using QuantizationPolicy.fp8_cast() conditional logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Update the LTX2 API calls during the calibration' is vague and generic. It uses non-descriptive terms that don't clearly convey what specific API changes were made. Revise title to be more specific about the changes, e.g., 'Replace cfg_guidance_scale with MultiModalGuiderParams and fp8transformer with QuantizationPolicy' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jingyux/ltx-2-update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
examples/diffusers/quantization/calibration.py (1)

123-142: Avoid sharing mutable guider defaults across batches.

If DEFAULT_*_GUIDER_PARAMS are mutable (e.g., dict/dataclass), passing the same instance each call risks cross-batch mutation. Consider cloning per call.

🔧 Suggested change
+        from copy import deepcopy
         kwargs = {
@@
-            "video_guider_params": DEFAULT_VIDEO_GUIDER_PARAMS,
-            "audio_guider_params": DEFAULT_AUDIO_GUIDER_PARAMS,
+            "video_guider_params": deepcopy(DEFAULT_VIDEO_GUIDER_PARAMS),
+            "audio_guider_params": deepcopy(DEFAULT_AUDIO_GUIDER_PARAMS),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/diffusers/quantization/calibration.py` around lines 123 - 142, The
code passes the shared mutable defaults DEFAULT_VIDEO_GUIDER_PARAMS and
DEFAULT_AUDIO_GUIDER_PARAMS directly into kwargs (used in prompt batching),
risking cross-batch mutation; change the call site where kwargs is built (the
block creating "kwargs") to create per-call copies of those defaults (e.g.,
shallow or deep copy as appropriate) before assigning to "video_guider_params"
and "audio_guider_params" so each batch gets its own independent instance and
mutations do not leak between batches.
examples/diffusers/quantization/models_utils.py (1)

166-167: Keep LTX2 resolution defaults single-sourced.

Now that LTX2 defaults are 768×1280, consider centralizing any fallback usage (e.g., in calibration) to avoid drift if values change again.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/diffusers/quantization/models_utils.py` around lines 166 - 167,
Extract the hard-coded LTX2 resolution (height: 768, width: 1280) into a single
shared constant (e.g., LTX2_DEFAULT_RESOLUTION or LTX2_DEFAULT_HEIGHT and
LTX2_DEFAULT_WIDTH) in models_utils.py and replace all ad-hoc fallbacks in the
codebase (particularly any calibration routines that currently reference literal
768/1280) to reference that constant; ensure the constant is exported/imported
where needed so calibration and model init code use the single source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@examples/diffusers/quantization/pipeline_manager.py`:
- Around line 216-218: The current assignment to fp8_quantization uses "or"
which causes an explicit False for the new flag to be overridden by the legacy
fp8transformer key; change the logic so the explicit new flag wins: check
whether "fp8_quantization" exists in params and use
params.pop("fp8_quantization") if present, otherwise fall back to
params.pop("fp8transformer", False). Update the code that sets the
fp8_quantization variable (and remove the single-line or expression) so the
precedence is: explicit fp8_quantization > legacy fp8transformer.

---

Nitpick comments:
In `@examples/diffusers/quantization/calibration.py`:
- Around line 123-142: The code passes the shared mutable defaults
DEFAULT_VIDEO_GUIDER_PARAMS and DEFAULT_AUDIO_GUIDER_PARAMS directly into kwargs
(used in prompt batching), risking cross-batch mutation; change the call site
where kwargs is built (the block creating "kwargs") to create per-call copies of
those defaults (e.g., shallow or deep copy as appropriate) before assigning to
"video_guider_params" and "audio_guider_params" so each batch gets its own
independent instance and mutations do not leak between batches.

In `@examples/diffusers/quantization/models_utils.py`:
- Around line 166-167: Extract the hard-coded LTX2 resolution (height: 768,
width: 1280) into a single shared constant (e.g., LTX2_DEFAULT_RESOLUTION or
LTX2_DEFAULT_HEIGHT and LTX2_DEFAULT_WIDTH) in models_utils.py and replace all
ad-hoc fallbacks in the codebase (particularly any calibration routines that
currently reference literal 768/1280) to reference that constant; ensure the
constant is exported/imported where needed so calibration and model init code
use the single source of truth.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52e662d and 0d749bc.

📒 Files selected for processing (3)
  • examples/diffusers/quantization/calibration.py
  • examples/diffusers/quantization/models_utils.py
  • examples/diffusers/quantization/pipeline_manager.py

Comment on lines +216 to +218
fp8_quantization = params.pop("fp8_quantization", None) or params.pop(
"fp8transformer", False
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Explicit fp8_quantization=false can be overridden by legacy flag.

Using or means an explicit False is ignored if fp8transformer is truthy. Prefer “explicit new flag wins” semantics.

✅ Safer precedence
-        fp8_quantization = params.pop("fp8_quantization", None) or params.pop(
-            "fp8transformer", False
-        )
+        if "fp8_quantization" in params:
+            fp8_quantization = params.pop("fp8_quantization")
+        else:
+            fp8_quantization = params.pop("fp8transformer", False)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/diffusers/quantization/pipeline_manager.py` around lines 216 - 218,
The current assignment to fp8_quantization uses "or" which causes an explicit
False for the new flag to be overridden by the legacy fp8transformer key; change
the logic so the explicit new flag wins: check whether "fp8_quantization" exists
in params and use params.pop("fp8_quantization") if present, otherwise fall back
to params.pop("fp8transformer", False). Update the code that sets the
fp8_quantization variable (and remove the single-line or expression) so the
precedence is: explicit fp8_quantization > legacy fp8transformer.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.09%. Comparing base (03a1899) to head (d4c4043).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #926   +/-   ##
=======================================
  Coverage   73.09%   73.09%           
=======================================
  Files         205      205           
  Lines       22301    22301           
=======================================
  Hits        16300    16300           
  Misses       6001     6001           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@Edwardf0t1 Edwardf0t1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"width": 1280,
"num_frames": 121,
"frame_rate": 24.0,
"cfg_guidance_scale": 4.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean users cannot specify cfg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they can, but in our calibration script we leave it to the default inference parameters in LTX-2:
DEFAULT_AUDIO_GUIDER_PARAMS,
DEFAULT_VIDEO_GUIDER_PARAMS,
these 2 params contain the default cfg_guidance_scale value. We haven't got any related request for calibrating different guidance scale yet.

@jingyu-ml jingyu-ml merged commit d78797b into main Feb 24, 2026
36 of 37 checks passed
@jingyu-ml jingyu-ml deleted the jingyux/ltx-2-update branch February 24, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants