Skip to content

[TRTLLM-12527][feat] Parallelize multi-shard visual-gen checkpoint loading and pre-fetch checking - #14021

Merged
chang-l merged 3 commits into
NVIDIA:mainfrom
yibinl-nvidia:dev-yibinl-TRT-12527-part-2
Jun 5, 2026
Merged

[TRTLLM-12527][feat] Parallelize multi-shard visual-gen checkpoint loading and pre-fetch checking#14021
chang-l merged 3 commits into
NVIDIA:mainfrom
yibinl-nvidia:dev-yibinl-TRT-12527-part-2

Conversation

@yibinl-nvidia

@yibinl-nvidia yibinl-nvidia commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Similar to LLM sharded loading and pre-fetch.

  • Refactor
    • Optimized weight loading for visual generation models to process sharded files concurrently, improving performance when multiple weight files are present.
    • Enhanced error reporting to clearly identify which weight file shard failed during loading.

Review Change Stack

Description

With this PR, the improvements are great.

model mode weight GB model/pipeline load vs baseline
Wan2.1-T2V-14B-Diffusers prefetch + parallel shard 80.39 88.23s 52.3% faster, 2.09x
Wan2.1-T2V-14B-Diffusers parallel shard only 80.39 193.55s 4.7% slower, 0.95x
Wan2.1-T2V-14B-Diffusers no features 80.39 184.82s baseline
Wan2.2-T2V-A14B-Diffusers prefetch + parallel shard 126.18 146.85s 67.5% faster, 3.08x
Wan2.2-T2V-A14B-Diffusers parallel shard only 126.18 344.26s 23.9% faster, 1.31x
Wan2.2-T2V-A14B-Diffusers no features 126.18 452.53s baseline
FLUX.1-dev prefetch + parallel shard 34.08 82.34s 2.1% faster, 1.02x
FLUX.1-dev parallel shard only 34.08 88.48s 5.2% slower, 0.95x
FLUX.1-dev no features 34.08 84.09s baseline
FLUX.2-dev prefetch + parallel shard 113.14 193.71s 32.8% faster, 1.49x
FLUX.2-dev parallel shard only 113.14 292.94s 1.6% slower, 0.98x
FLUX.2-dev no features 113.14 288.39s baseline

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@yibinl-nvidia
yibinl-nvidia requested a review from a team as a code owner May 12, 2026 02:42
@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

WeightLoader's load_weights method now delegates per-component weight file loading to a new _load_weight_files helper. The helper uses ThreadPoolExecutor to load multiple weight shards concurrently when present, falling back to sequential loading for single-file checkpoints. Shard-load failures are caught and re-raised as RuntimeError with the failing file name.

Changes

Concurrent Weight File Loading

Layer / File(s) Summary
Concurrent weight file loading with thread pool
tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py
Added ThreadPoolExecutor and as_completed imports; refactored load_weights to delegate per-component loading to new _load_weight_files helper that selects between sequential loading (0–1 files) and concurrent loading via ThreadPoolExecutor (2+ files), aggregates tensor dicts, and wraps per-shard exceptions into RuntimeError with file identifiers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning PR description is largely incomplete with only a performance metrics table provided; missing detailed explanation of what was changed, why, and test coverage details. Add a clear explanation of the changes made to the WeightLoader (thread pool parallelization for loading sharded weights), provide details on test coverage for the new _load_weight_files method, and complete the PR checklist items appropriately.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately summarizes the main change: parallelizing multi-shard visual-gen checkpoint loading, which directly aligns with the updated WeightLoader implementation that introduces concurrent file loading via thread pool.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py (2)

125-128: 💤 Low value

Consider catching more specific exceptions.

Per coding guidelines, avoid broad exception handling. While catching Exception here is a common pattern for future.result() (to add context via from exc), you could narrow the scope to the likely exceptions from file I/O and tensor loading.

♻️ Suggested narrower exception handling
                 try:
                     loaded = future.result()
-                except Exception as exc:
+                except (OSError, RuntimeError, ValueError) as exc:
                     raise RuntimeError(f"Failed to load weight file {wf}") from exc

Note: If there are other exception types from safetensors.load_file or torch.load that should be caught, add them to the tuple.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py` around lines 125
- 128, The try/except around future.result() in weight_loader.py is too broad;
replace the blanket "except Exception" with a narrowed tuple of likely errors
(e.g., OSError, IOError, RuntimeError, ValueError and any specific exceptions
thrown by safetensors.load_file or torch.load) so only expected file/I/O or
tensor-loading failures are caught, still re-raising with RuntimeError(f"Failed
to load weight file {wf}") from exc to preserve context; add any additional
safetensors/torch-specific exception types to the tuple if discovered.

21-22: ⚡ Quick win

Outdated docstring contradicts new functionality.

The docstring says "no parallel loading optimization for now" but this PR adds parallel loading via ThreadPoolExecutor. Update the description to reflect the new concurrent loading capability.

📝 Suggested docstring update
     """
     Weight loader for diffusion models.

     Loads weights from safetensors/bin files, similar to HfWeightLoader
-    but simpler (no parallel loading optimization for now).
+    with parallel loading for multi-shard checkpoints.

     Supports loading multiple components (e.g., transformer and transformer_2):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py` around lines 21
- 22, The module docstring in
tensorrt_llm._torch.visual_gen.checkpoints.weight_loader still claims "no
parallel loading optimization for now" but the code now uses ThreadPoolExecutor
for concurrent loads; update the top-level docstring (and any class docstring
for HfWeightLoader or WeightLoader) to reflect that the loader supports
parallel/concurrent loading using ThreadPoolExecutor (mention ability to
configure worker count if applicable) and remove the outdated "no parallel
loading" statement so the description matches the implemented behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py`:
- Around line 91-93: Reformat the long lines flagged by ruff by wrapping
arguments and breaking the calls into multiple indented lines: split the call to
self._load_weight_files(weight_files, component, is_pipeline) across lines, wrap
the logger.info(...) parameters onto separate lines, and reflow the
tqdm.tqdm(as_completed(...)) invocation so its inner as_completed(...) call and
outer tqdm parameters are on separate lines; run ruff format on
tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py to apply consistent
formatting for the functions/methods _load_weight_files, logger.info, and
tqdm.tqdm(as_completed(...)).
- Line 1: Add the required NVIDIA copyright header at the top of the module
before the module-level docstring in the weight_loader.py file (i.e., the
module-level docstring in
tensorrt_llm._torch.visual_gen.checkpoints.weight_loader); insert the
current-year NVIDIA boilerplate header exactly as used in other project files,
then keep the existing docstring and code unchanged below it.

---

Nitpick comments:
In `@tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py`:
- Around line 125-128: The try/except around future.result() in weight_loader.py
is too broad; replace the blanket "except Exception" with a narrowed tuple of
likely errors (e.g., OSError, IOError, RuntimeError, ValueError and any specific
exceptions thrown by safetensors.load_file or torch.load) so only expected
file/I/O or tensor-loading failures are caught, still re-raising with
RuntimeError(f"Failed to load weight file {wf}") from exc to preserve context;
add any additional safetensors/torch-specific exception types to the tuple if
discovered.
- Around line 21-22: The module docstring in
tensorrt_llm._torch.visual_gen.checkpoints.weight_loader still claims "no
parallel loading optimization for now" but the code now uses ThreadPoolExecutor
for concurrent loads; update the top-level docstring (and any class docstring
for HfWeightLoader or WeightLoader) to reflect that the loader supports
parallel/concurrent loading using ThreadPoolExecutor (mention ability to
configure worker count if applicable) and remove the outdated "no parallel
loading" statement so the description matches the implemented behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d1f9a9ae-cf2c-4d5d-a448-d13f1747813f

📥 Commits

Reviewing files that changed from the base of the PR and between 64260ba and a050e7d.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py

Comment thread tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py
Comment thread tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py Outdated
@yibinl-nvidia
yibinl-nvidia force-pushed the dev-yibinl-TRT-12527-part-2 branch from a050e7d to efb290f Compare May 12, 2026 05:53
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47891 [ run ] triggered by Bot. Commit: efb290f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47891 [ run ] completed with state SUCCESS. Commit: efb290f
/LLM/main/L0_MergeRequest_PR pipeline #37742 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47989 [ run ] triggered by Bot. Commit: efb290f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47989 [ run ] completed with state SUCCESS. Commit: efb290f
/LLM/main/L0_MergeRequest_PR pipeline #37828 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yibinl-nvidia
yibinl-nvidia requested a review from chang-l May 12, 2026 19:26
@yibinl-nvidia yibinl-nvidia changed the title [TRTLLM-12527][feat] Parallelize multi-shard visual-gen checkpoint loading [TRTLLM-12527][feat] Parallelize multi-shard visual-gen checkpoint loading and pre-fetch checking May 15, 2026
@yibinl-nvidia
yibinl-nvidia force-pushed the dev-yibinl-TRT-12527-part-2 branch from 61b17fe to e233135 Compare May 15, 2026 19:14
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48656 [ run ] triggered by Bot. Commit: e233135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48656 [ run ] completed with state SUCCESS. Commit: e233135
/LLM/main/L0_MergeRequest_PR pipeline #38436 completed with status: 'SUCCESS'

CI Report

Link to invocation

@chang-l chang-l 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.

Is it possible to reduce the code dup in the PR?

Comment thread tensorrt_llm/_torch/visual_gen/models/ltx2/pipeline_ltx2.py Outdated
Comment thread tensorrt_llm/_torch/visual_gen/models/ltx2/pipeline_ltx2.py Outdated
Comment thread tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py Outdated
Comment thread tensorrt_llm/_torch/visual_gen/models/ltx2/pipeline_ltx2.py Outdated
Comment thread tensorrt_llm/_torch/visual_gen/checkpoints/weight_loader.py Outdated
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
@yibinl-nvidia
yibinl-nvidia force-pushed the dev-yibinl-TRT-12527-part-2 branch from 3d721e3 to 7a274d7 Compare May 29, 2026 00:58
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51139 [ run ] triggered by Bot. Commit: 7a274d7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51139 [ run ] completed with state SUCCESS. Commit: 7a274d7
/LLM/main/L0_MergeRequest_PR pipeline #40575 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yibinl-nvidia
yibinl-nvidia force-pushed the dev-yibinl-TRT-12527-part-2 branch 2 times, most recently from e417e26 to 7a274d7 Compare June 1, 2026 17:18
@yibinl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51645 [ run ] triggered by Bot. Commit: 7a274d7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51645 [ run ] completed with state SUCCESS. Commit: 7a274d7
/LLM/main/L0_MergeRequest_PR pipeline #41028 completed with status: 'SUCCESS'

CI Report

Link to invocation

@chang-l
chang-l merged commit 52ba2bb into NVIDIA:main Jun 5, 2026
12 checks passed
2ez4bz pushed a commit to 2ez4bz/TensorRT-LLM that referenced this pull request Jun 8, 2026
…ading and pre-fetch checking (NVIDIA#14021)

Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
@yibinl-nvidia
yibinl-nvidia deleted the dev-yibinl-TRT-12527-part-2 branch June 9, 2026 01:35
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.

3 participants