Skip to content

Conversation

@2ez4bz
Copy link
Collaborator

@2ez4bz 2ez4bz commented Aug 25, 2025

Description

  • Why?

Some models (e.g. anything produced by Mistral) can have both sharded safetensors and a consolidated safetensor in the same checkpoint directory. In such cases, prefetching both to memory is a waste of time, and memory.

  • What?

This commit skips over consolidated safetensors when they are not the only safetensor file present in the checkpoint directory.

Test Coverage

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Summary by CodeRabbit

  • Bug Fixes

    • Improved HF weight loading to prefer sharded safetensor checkpoints over a single consolidated file, reducing memory usage and avoiding oversized loads when shards are available.
  • Tests

    • Added unit tests covering weight file selection across mixed, shard-only, and consolidated-only scenarios, including edge cases in directory naming.
    • Registered the new test in integration test lists.
  • Chores

    • Updated configuration to adjust tooling behavior (formatting, linting, import sorting, and spell-check) for the new test path.

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
@2ez4bz 2ez4bz requested a review from a team as a code owner August 25, 2025 17:47
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 25, 2025

📝 Walkthrough

Walkthrough

Configuration updates in pyproject.toml adjust tool include/exclude lists for a specific test file. The weight loader adds filtering to prefer sharded safetensors over consolidated ones. A new unit test validates this selection logic, and an integration test list entry is added to run the CPU-only test.

Changes

Cohort / File(s) Summary
Tooling configuration updates
pyproject.toml
Added tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py to isort extend_skip_glob, yapfignore ignore_patterns, codespell exclude, autoflake exclude, and ruff include.
HF weight loading logic
tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py
Filters safetensors to exclude basenames containing "consolidated"; uses sharded files when present, otherwise retains original list. Loading flow unchanged beyond selection.
Integration test list
tests/integration/test_lists/test-db/l0_a10.yml
Adds CPU-only PyTorch test entry for unittest/_torch/models/checkpoints/hf/test_weight_loader.py with explanatory comments.
Unit tests for weight selection
tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py
New tests for HfWeightLoader.load_weights asserting shard-preference over consolidated, with mocked prefetch_files and _load_weights_in_parallel. Covers mixed, consolidated-only, and directory-name edge cases.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Loader as HfWeightLoader
  participant FS as Filesystem
  participant Prefetch as prefetch_files
  participant Parallel as _load_weights_in_parallel

  Caller->>Loader: load_weights(model_dir)
  Loader->>FS: list *.safetensors
  FS-->>Loader: weight_files

  alt Any non-"consolidated" shards exist
    note right of Loader: Filter out files with "consolidated" in basename
    Loader->>Loader: use shard_files
  else No shards (only consolidated)
    Loader->>Loader: use original weight_files
  end

  Loader->>Prefetch: prefetch(selected_files)
  Prefetch-->>Loader: ok
  Loader->>Parallel: load(selected_files)
  Parallel-->>Loader: done
  Loader-->>Caller: return
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • yilin-void
  • syuoni
  • shaharmor98
  • litaotju

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@2ez4bz
Copy link
Collaborator Author

2ez4bz commented Aug 25, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16467 [ run ] triggered by Bot

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py (1)

1-1: Missing NVIDIA Apache-2.0 header and Python 3.8 typing compatibility.

  • Per repo guidelines, prepend the NVIDIA Apache-2.0 header.
  • The function annotation -> dict[str, Any] (and similar built-in generics elsewhere) requires Python 3.9+. To keep Python 3.8 compatibility, either add from __future__ import annotations at the top of the file or switch to typing.Dict[str, Any].

Example header and future import to add at the very top:

+# Copyright (c) 2025, NVIDIA CORPORATION.  All rights reserved.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from __future__ import annotations

If you prefer not to use postponed evaluation, change the annotations to Dict[..., ...] and import Dict from typing.

🧹 Nitpick comments (3)
tests/integration/test_lists/test-db/l0_a10.yml (1)

19-21: CPU-only unit test added to GPU A10 list: acceptable, but consider explicit CPU gating.

Adding unittest/_torch/models/checkpoints/hf/test_weight_loader.py here is fine and low-cost, but since it’s CPU-only, a marker (e.g., @pytest.mark.cpu_only) plus job-side selection (or skip on GPU-required nodes) would make intent explicit and avoid accidental coupling to GPU infra later.

If you want, I can add a cpu_only marker and wire it in the test list selection.

tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py (2)

12-49: Expand scenarios to cover common consolidated filename and case robustness.

Current tests only gate on names containing “consolidated”. Add a case with pytorch_model.safetensors alongside shards to ensure we never co-load it when shards are present.

Append to the parametrization:

@@
     [
         (
             "foo",
             [
                 "model-00001-of-00002.safetensors",
                 "model-000002-of-00002.safetensors",
                 "consolidated.safetensors",
             ],
             ["model-00001-of-00002.safetensors", "model-000002-of-00002.safetensors"],
         ),
+        (
+            "foo",
+            [
+                "pytorch_model.safetensors",
+                "model-00001-of-00002.safetensors",
+                "model-00002-of-00002.safetensors",
+            ],
+            ["model-00001-of-00002.safetensors", "model-00002-of-00002.safetensors"],
+        ),

If you want, I can also add a case-insensitivity check and adapt the loader accordingly.


65-71: Patch the local MPI barrier to avoid external environment coupling in unit tests.

load_weights calls local_mpi_barrier() after prefetch. In non-MPI CI, this is typically a no-op, but mocking it makes the test hermetic.

@@
     with (
         mock.patch.object(
             loader, "_load_weights_in_parallel", side_effect=MyError
         ) as load_weights_in_parallel,
         mock.patch.object(loader, "prefetch_files") as prefetch_files,
+        mock.patch("tensorrt_llm._utils.local_mpi_barrier", return_value=None),
         pytest.raises(MyError),
     ):
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d010b20 and 7f3439d.

📒 Files selected for processing (4)
  • pyproject.toml (4 hunks)
  • tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py (1 hunks)
  • tests/integration/test_lists/test-db/l0_a10.yml (1 hunks)
  • tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Code must target Python 3.8+
Indent with 4 spaces; do not use tabs
Preserve module namespace when importing: from package.subpackage import foo; then use foo.SomeClass()
Python filenames use snake_case (e.g., some_file.py)
Class names use PascalCase
Function and method names use snake_case
Local variables use snake_case; prefix k for names starting with a number (e.g., k_99th_percentile)
Global variables are UPPER_SNAKE_CASE prefixed with G (e.g., G_MY_GLOBAL)
Constants are UPPER_SNAKE_CASE
Avoid shadowing variables from an outer scope
Initialize all externally visible members of a class in init
For interfaces used outside a file, prefer docstrings over comments; comments for internal code or local interfaces
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Attributes and variables can be documented inline with trailing docstrings under the class or module
Avoid using reflection when easily avoidable; prefer explicit parameters/constructs over dict(**locals())
In try/except, catch the narrowest exception types possible
For duck-typing try/except, keep try body minimal and place logic in else after attribute existence checks

Files:

  • tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py
  • tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py
**/*.{h,hpp,hxx,hh,c,cc,cpp,cxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend NVIDIA Apache-2.0 copyright header with current year to all source files

Files:

  • tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py
  • tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py
🧠 Learnings (1)
📚 Learning: 2025-07-28T17:06:08.621Z
Learnt from: moraxu
PR: NVIDIA/TensorRT-LLM#6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.

Applied to files:

  • tests/integration/test_lists/test-db/l0_a10.yml
🧬 Code graph analysis (1)
tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py (1)
tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py (3)
  • HfWeightLoader (22-135)
  • prefetch_files (121-135)
  • load_weights (27-67)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (2)
pyproject.toml (1)

36-36: Tooling entries kept in sync across sections. LGTM.

The new test file is consistently listed in isort’s skip, yapf ignore, autoflake exclude, and ruff include. This matches the comments about keeping lists aligned.

Also applies to: 67-67, 102-102, 146-146

tests/unittest/_torch/models/checkpoints/hf/test_weight_loader.py (1)

50-81: Test structure and assertions are solid.

The use of a sentinel exception to capture the selected file list and the check that prefetch_files and _load_weights_in_parallel receive identical sets is clean and effective.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16467 [ run ] completed with state SUCCESS
/LLM/release-1.0/L0_MergeRequest_PR pipeline #301 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@2ez4bz 2ez4bz enabled auto-merge (squash) August 26, 2025 16:03
@2ez4bz 2ez4bz merged commit 34c1e9c into NVIDIA:release/1.0 Aug 26, 2025
5 checks passed
yuanjingx87 pushed a commit that referenced this pull request Aug 28, 2025
…te (#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 4, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 7, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 8, 2025
…te (NVIDIA#7225)

* Why?

Some models (e.g. anything produced by Mistral) can have both sharded
safetensors and a consolidated safetensor in the same checkpoint
directory. In such cases, prefetching both to memory is a waste of time,
and memory.

* What?

This commit skips over consolidated safetensors when they are not the
only safetensor file present in the checkpoint directory.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: Wangshanshan <[email protected]>
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.

4 participants