Skip to content

[NVBug 6982527] Fix duplicate final checkpoint save in LTX distillation - #3027

Merged
Zhehao-Hu merged 1 commit into
mainfrom
zhehaoh/fix-6982527-ltx-final-checkpoint
Oct 27, 2026
Merged

Zhehao-Hu merged 1 commit into
mainfrom
zhehaoh/fix-6982527-ltx-final-checkpoint

Conversation

@Zhehao-Hu

@Zhehao-Hu Zhehao-Hu commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

When the final LTX distillation step coincides with a checkpoint interval, the trainer saves the same step twice. The second save fails while renaming its temporary directory onto the existing nonempty checkpoint directory, preventing final inference export. Time-limit exits can encounter the same collision.

Reuse the existing saved_this_step flag to skip the final training-state save when the last step was already checkpointed. Initialize the flag before the loop and set it after a time-limit save. Final inference export still runs, and steps not already checkpointed still receive a final save.

Usage

No configuration changes required. For example, optimization.steps=1 with checkpoints.interval=1 now saves the training state once and proceeds to inference export.

Testing

pytest tests/examples/diffusers/test_distillation_trainer.py -q
  • The checked-in parametrized regression test covers interval-aligned completion, a nonaligned final step, and time-limit exits with and without an interval save, each with gradient accumulation of one and two.
  • All 8 cases passed locally on CPU (pytest-reported duration: 1.87 seconds). The test imports the complete example and exercises its real training loop, Accelerate training-state save, checkpoint retention, and safetensors inference export using a tiny model. It verifies exactly one training-state save per expected step, one inference export, and exported weights matching the trained model.
  • With the production fix reverted, 6 cases fail with the original directory collision; the two nonaligned controls still pass.
  • All applicable pre-commit checks passed.

The test substitutes the optional LTX dependency/setup and UI; it requires no LTX model downloads. Full LTX model execution and GPU/FSDP validation were not run.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅ — eight parametrized checkpoint-finalization cases in tests/examples/diffusers/test_distillation_trainer.py.
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: N/A - Not yet run

Additional Information

Fixes NVBug 6982527.

Summary by CodeRabbit

  • Bug Fixes
    • Training now avoids saving duplicate checkpoints when an interval or time-limit save already covers the final step.
    • A final training-state checkpoint is still saved when no earlier save covers the last step, helping ensure the latest training progress is retained.

@copy-pr-bot

copy-pr-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 607263d and f355998.

Files selected for processing: 2
  • examples/diffusers/distillation/distillation_trainer.py
  • tests/examples/diffusers/test_distillation_trainer.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The training loop now skips its final state save when an interval or time-limit checkpoint already saved the final step. New parameterized tests cover checkpoint timing and verify saved output and metadata.

Changes: Distillation checkpoint saving

Layer / File(s) Summary
Track and test final-step checkpoint saves
examples/diffusers/distillation/distillation_trainer.py, tests/examples/diffusers/test_distillation_trainer.py
The trainer tracks whether the current step was saved and skips a duplicate final state save. CPU tests cover interval and deadline scenarios, and check the checkpoint call, exported weights, retained directory, and metadata.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: mxino

Merge Risk: Minimal · up to f3559

No actionable merge-blocking issue is established for the final checkpoint-save change.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing duplicate final checkpoint saves in LTX distillation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed No listed security anti-pattern was introduced. The PR changes only examples/diffusers/distillation/distillation_trainer.py and a test module. Added lines contain no `torch.load(..., weights_only=Fa…
Full details: Security Anti-Patterns

Explanation

No listed security anti-pattern was introduced. The PR changes only examples/diffusers/distillation/distillation_trainer.py and a test module. Added lines contain no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, external-input eval()/exec(), or # nosec. No pyproject.toml or requirements file changed.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

Nudge: the checkpoint guard looks correct, but the reported temporary harness leaves no checked-in regression coverage.

Needs action:

  • Add a lean parametrized regression test for DistillationTrainer.train under tests/examples/diffusers, covering interval-aligned completion, time-limit exits, and a nonaligned final step; verify one final-step training-state save and successful inference-export execution.

@Zhehao-Hu Zhehao-Hu changed the title [NVBug 698227] Fix duplicate final checkpoint save in LTX distillation [NVBug 6982527] Fix duplicate final checkpoint save in LTX distillation Oct 26, 2026
Skip the final training-state save when an interval or time-limit
save already checkpointed the last step. This avoids a directory
rename collision and allows final inference export to proceed.

Fixes NVBug 6982527.

Signed-off-by: Zhehao Hu <[email protected]>
@Zhehao-Hu
Zhehao-Hu force-pushed the zhehaoh/fix-6982527-ltx-final-checkpoint branch from d8141f5 to f355998 Compare October 26, 2026 18:02
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.49%. Comparing base (1d9ec87) to head (f355998).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3027   +/-   ##
=======================================
  Coverage   77.49%   77.49%           
=======================================
  Files         661      661           
  Lines       74949    74949           
=======================================
  Hits        58085    58085           
  Misses      16864    16864           
Flag Coverage Δ
examples-diffusers 19.90% <ø> (-0.01%) ⬇️
unit 61.15% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

Approve: the previous regression-coverage concern is resolved, and the checkpoint guard correctly preserves final inference export without duplicate training-state saves.

No action needed:

  • ✔️ Resolved since the last review: tests/examples/diffusers/test_distillation_trainer.py now covers aligned and nonaligned completion plus both time-limit paths, with gradient accumulation of one and two, using real checkpoint saving and safetensors export.

@Zhehao-Hu
Zhehao-Hu marked this pull request as ready for review October 26, 2026 18:06
@Zhehao-Hu
Zhehao-Hu requested review from a team as code owners October 26, 2026 18:06
@Zhehao-Hu
Zhehao-Hu requested a review from ajrasane October 26, 2026 18:06

@Edwardf0t1 Edwardf0t1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Zhehao-Hu
Zhehao-Hu merged commit 5e95d70 into main Oct 27, 2026
36 checks passed
@Zhehao-Hu
Zhehao-Hu deleted the zhehaoh/fix-6982527-ltx-final-checkpoint branch October 27, 2026 00:18
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-27 00:18 UTC

kevalmorabia97 added a commit that referenced this pull request Oct 28, 2026
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072)

## Cherry-picked PRs

- #2817
- #2671
- #2892
- #2876
- #2910
- #2911
- #2919
- #2904
- #2937
- #2928
- #2885
- #2908
- #2929
- #2950
- #2972
- #2877
- #2951
- #2816
- #3005
- #3012
- #2971
- #3015
- #3006
- #3026
- #2988
- #3028
- #1860
- #3030
- #2612
- #3033
- #2653
- #2599
- #2655
- #2618
- #2868
- #3032
- #3027
- #2869
- #2984
- #2975
- #2345
- #3020
- #2997

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Diffusion exports now offer more control over attention-quantizer
metadata and preserve sparse-attention settings in a format compatible
with downstream tooling.
* Model loading better handles select bundled model implementations, and
Docker guidance now covers writable CUDA-extension cache locations.
* **Bug Fixes**
* Improved reliability for model export and checkpoint saving,
quantization across devices, ONNX processing, and calibration.
* Temporary TensorRT and autotuning artifacts now use private
directories by default.
* **Documentation**
* Updated installation guidance, compatibility notes, and links;
corrected typos across guides and examples.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Chad Voegele <[email protected]>
Signed-off-by: Rohan Joshi <[email protected]>
Signed-off-by: LinCanNerd <[email protected]>
Signed-off-by: Keval Morabia <[email protected]>
Signed-off-by: weimingc <[email protected]>
Signed-off-by: Noey Yang <[email protected]>
Signed-off-by: Kai Xu <[email protected]>
Signed-off-by: Zhehao Hu <[email protected]>
Signed-off-by: noeyy-mino <[email protected]>
Signed-off-by: joe-nv <[email protected]>
Signed-off-by: yingguo-trt <[email protected]>
Signed-off-by: Shengliang Xu <[email protected]>
Signed-off-by: Chenjie Luo <[email protected]>
Signed-off-by: anmaurya001 <[email protected]>
Signed-off-by: Connor Baker <[email protected]>
Signed-off-by: wiederse <[email protected]>
Signed-off-by: Vu Dinh <[email protected]>
Signed-off-by: Pratik Gandhi <[email protected]>
Signed-off-by: Michael Rusu <[email protected]>
Signed-off-by: Michael-Rusu <[email protected]>
Signed-off-by: namgyu-youn <[email protected]>
Signed-off-by: Sylvester Kaczmarek <[email protected]>
Signed-off-by: Javier de Jesus <[email protected]>
Signed-off-by: javierdejesusda <[email protected]>
Signed-off-by: Zhiyu Cheng <[email protected]>
Signed-off-by: Juhi Mittal <[email protected]>
Signed-off-by: Dmitry Rantovov <[email protected]>
Signed-off-by: h-guo18 <[email protected]>
Co-authored-by: Chad Voegele <[email protected]>
Co-authored-by: LinCanNerd <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: Keval Morabia <[email protected]>
Co-authored-by: Wei-Ming Chen <[email protected]>
Co-authored-by: noeyy-mino <[email protected]>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: kaix-nv <[email protected]>
Co-authored-by: Zhehao Hu <[email protected]>
Co-authored-by: joe <[email protected]>
Co-authored-by: yingguo-trt <[email protected]>
Co-authored-by: Shengliang Xu <[email protected]>
Co-authored-by: Chenjie Luo <[email protected]>
Co-authored-by: anmaurya001 <[email protected]>
Co-authored-by: Connor Baker <[email protected]>
Co-authored-by: Jiao Mingyang <[email protected]>
Co-authored-by: Vu Dinh <[email protected]>
Co-authored-by: Pratik Gandhi <[email protected]>
Co-authored-by: Michael R <[email protected]>
Co-authored-by: Michael-Rusu <[email protected]>
Co-authored-by: namgyu-youn <[email protected]>
Co-authored-by: Sylvester Kaczmarek <[email protected]>
Co-authored-by: Javier De Jesus <[email protected]>
Co-authored-by: Zhiyu <[email protected]>
Co-authored-by: Juhi Mittal <[email protected]>
Co-authored-by: Dmitry Rantovov <[email protected]>
Co-authored-by: h-guo18 <[email protected]>
@rohansjoshi rohansjoshi added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants