Skip to content

[TRTLLM-16725][refactor] BREAKING: Use a string enum for checkpoint formats and simplify checkpoint I/O helpers - #20703

Merged
yijingl-nvidia merged 3 commits into
NVIDIA:mainfrom
yijingl-nvidia:user/yijingl/checkpoint-format-enum
Nov 6, 2026
Merged

yijingl-nvidia merged 3 commits into
NVIDIA:mainfrom
yijingl-nvidia:user/yijingl/checkpoint-format-enum

Conversation

@yijingl-nvidia

@yijingl-nvidia yijingl-nvidia commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR uses a string enum for the built-in checkpoint formats and simplifies the checkpoint I/O helpers. It has three commits. Review each commit separately:

  1. Use a string enum for the built-in checkpoint formats (commit diff). The new CheckpointFormat covers formats such as "HF", "MX" and "mistral". Custom formats can still use strings. The serve configuration schemas in tensorrt_llm/schemas/ change to match.
  2. Require LoadFormat in the checkpoint I/O helpers (commit diff). All callers give a LoadFormat, so the code for string values was dead code. No functional change.
  3. Simplify the checkpoint I/O policy resolution (commit diff). Consolidate I/O fallback into _checkpoint_io_incompatibility_reason(). No functional change, except that two fallback messages now include the requested policy.

These changes improve code readability and maintenance. Commits 2 and 3 were #20705 and #20706.

Side change:

  • _construct_checkpoint_loader() is now public as construct_checkpoint_loader(), because other modules use it.

Test Coverage

1 test added, 12 tests changed:

  • tests/unittest/_torch/pyexecutor/test_model_loader_checkpoint_io.py
  • tests/unittest/_torch/pyexecutor/test_model_loader_mx.py
  • tests/unittest/llmapi/test_llm_args.py
  • tests/unittest/llmapi/test_serialization.py
  • tests/unittest/usage/test_collectors.py

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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.

PRs in this series

These PRs refactor checkpoint loading and add Model Streamer loading. They merge in this order, top to bottom.

PR What it does
#20498 (merged) Change checkpoint_io_policy from plain strings to the string enum CheckpointIOPolicy.
#20703 (this PR) Add the string enum CheckpointFormat for the built-in checkpoint formats, make the checkpoint I/O helpers take only LoadFormat, and make the checkpoint I/O policy resolution easier to read.
#20704 (merged) Put the PyTorch process-group setup in one module, distributed/initialization.py.
#20711 Make ModelLoader.load() shorter: move its MX, GMS, memory and model-hook helpers to new files in models/checkpoints/.
#20713 Remove the MX-only hooks from BaseCheckpointLoader.
#20717 Move Kimi K3 weight loading from modeling_kimi_linear.py to modeling_kimi_k3_loader.py.
#20781 Add checkpoint_io_policy="model_streamer", which loads a checkpoint with Run:ai Model Streamer.
#20782 Add the Model Streamer load for Kimi K3.

🤖 Generated with Claude Code

Dev Engineer Review

The change adds public CheckpointFormat and CheckpointIOPolicy enums. Built-in checkpoint formats now use enum members. Custom formats remain strings.

Checkpoint loading, mapper registration, configuration dispatch, serialization, usage reporting, and input processing now support enum values. Defaults are CheckpointFormat.HF and CheckpointIOPolicy.AUTO.

The change renames _construct_checkpoint_loader to construct_checkpoint_loader and updates its callers. This is an API-breaking change. Callers that compare formats, inspect annotations, serialize TorchLlmArgs, or call the renamed helper require compatibility checks. Test results and review severity findings are unavailable.

QA Engineer Review

Modified tests cover format normalization, custom-format preservation, policy resolution, invalid policy errors, enum serialization, loader fallback behavior, native loading, API stability, and usage reporting.

Changed test files:

  • tests/unittest/_torch/executor/test_model_loader_checkpoint_io.py
  • tests/unittest/api_stability/references/llm.yaml
  • tests/unittest/llmapi/test_llm_args.py
  • tests/unittest/llmapi/test_serialization.py
  • tests/unittest/usage/test_collectors.py

No test declarations, integration test-list files, or manual-QA list files changed. Coverage verdict: needs follow-up, because test execution results are unavailable.

Per-File QA Perspective

  • tensorrt_llm/checkpoint_format.py: Verify built-in enum values and string compatibility.
  • tensorrt_llm/llmapi/llm_args.py: Verify format normalization, custom formats, defaults, policy validation, and serialization.
  • tensorrt_llm/llmapi/__init__.py: Verify public exports for both enums.
  • tensorrt_llm/llmapi/serialization.py: Verify secured deserialization allowlists both enums.
  • tensorrt_llm/_torch/models/checkpoints/auto_mapper.py, base_checkpoint_loader.py, modeling_utils.py: Verify enum and string lookup paths.
  • tensorrt_llm/_torch/models/checkpoints/hf/afmoe_weight_mapper.py, checkpoint_loader.py, config_loader.py, cosmos3_weight_mapper.py, exaone4_5_weight_mapper.py, exaone_moe_weight_mapper.py, gemma3_weight_mapper.py, gemma4_weight_mapper.py, glm5_next_weight_mapper.py, llama4_weight_mapper.py, llava_next_weight_mapper.py, minimaxm3_weight_mapper.py, mixtral_weight_mapper.py, nemotron_h_weight_mapper.py, nemotron_nas_weight_mapper.py, qwen2_moe_weight_mapper.py, qwen2vl_weight_mapper.py, qwen3_5_weight_mapper.py, qwen3_moe_weight_mapper.py, qwen3_next_weight_mapper.py, qwen3vl_moe_weight_mapper.py, qwen3vl_weight_mapper.py, qwen4_exp_weight_mapper.py, weight_loader.py, weight_mapper.py: Verify HF and MX registration, policy handling, fallback behavior, and reported formats.
  • tensorrt_llm/_torch/models/checkpoints/mistral/checkpoint_loader.py, config_loader.py, weight_mapper.py: Verify Mistral format registration and dispatch.
  • tensorrt_llm/_torch/models/checkpoints/mx/checkpoint_loader.py: Verify MX loading, manifest context, and reported format.
  • tensorrt_llm/_torch/models/modeling_laguna.py, modeling_speculative.py, _torch/pyexecutor/config_utils.py, inputs/registry.py, llmapi/llm.py, serve/openai_server.py: Verify enum-based model, configuration, processor, and token-encoder dispatch.
  • tensorrt_llm/_torch/pyexecutor/model_loader.py: Verify policy selection, incompatible-format fallback, MX detection, and the renamed public loader factory.
  • tensorrt_llm/tools/layer_wise_benchmarks/runner.py: Verify HF format propagation through construct_checkpoint_loader.
  • tensorrt_llm/usage/usage_lib.py: Verify enum values are serialized correctly.
  • tests/unittest/_torch/executor/test_model_loader_checkpoint_io.py: Covers policy resolution, invalid values, enum inputs, fallback behavior, and native loading. No test-list entry applies.
  • tests/unittest/api_stability/references/llm.yaml: Verify the updated public API reference. No test-list entry applies.
  • tests/unittest/llmapi/test_llm_args.py: Covers format normalization, custom formats, policy defaults, validation, and serialization. No test-list entry applies.
  • tests/unittest/llmapi/test_serialization.py: Covers round trips for checkpoint policies and CheckpointFormat.MISTRAL. No test-list entry applies.
  • tests/unittest/usage/test_collectors.py: Covers checkpoint-format value serialization. No test-list entry applies.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The pull request introduces typed checkpoint-format and checkpoint-I/O-policy enums, updates checkpoint registration and loading paths to use them, exposes construct_checkpoint_loader, and adds coverage for normalization, fallback, serialization, and API stability.

Changes

Checkpoint format and I/O policy typing

Layer / File(s) Summary
Public enum and argument contract
tensorrt_llm/checkpoint_format.py, tensorrt_llm/llmapi/llm_args.py, tensorrt_llm/llmapi/__init__.py, tensorrt_llm/llmapi/serialization.py, tensorrt_llm/usage/*, tests/unittest/llmapi/*, tests/unittest/usage/test_collectors.py, tests/unittest/api_stability/*
Adds CheckpointFormat and CheckpointIOPolicy, updates argument types and defaults, exports and approves the enums for deserialization, and adds tests for normalization and serialization.
Checkpoint registry and mapper registrations
tensorrt_llm/_torch/models/checkpoints/*, tensorrt_llm/_torch/models/modeling_utils.py, tensorrt_llm/_torch/models/modeling_laguna.py, tensorrt_llm/_torch/models/modeling_speculative.py
Checkpoint APIs accept enum or string keys. Built-in HF, MX, and Mistral registrations use enum members.
Checkpoint-format dispatch
tensorrt_llm/_torch/pyexecutor/config_utils.py, tensorrt_llm/_torch/pyexecutor/model_loader.py, tensorrt_llm/inputs/registry.py, tensorrt_llm/llmapi/llm.py, tensorrt_llm/serve/openai_server.py, tensorrt_llm/tools/layer_wise_benchmarks/runner.py
Updates checkpoint-format comparisons in configuration loading, model loading, input processing, validation, serving, and benchmark setup to use enum members.
Checkpoint I/O policy selection and fallback
tensorrt_llm/_torch/models/checkpoints/hf/weight_loader.py, tensorrt_llm/_torch/models/checkpoints/hf/checkpoint_loader.py, tensorrt_llm/_torch/pyexecutor/model_loader.py, tests/unittest/_torch/executor/test_model_loader_checkpoint_io.py
Uses CheckpointIOPolicy for policy conversion, validation, status, and fallback tracking. Tests cover policy selection, normalization, and invalid policy handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Merge Risk: Minimal · up to b68e0

No confirmed issue blocks merging; complete the normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly identifies the ticket, refactor scope, breaking nature, and primary changes to checkpoint formats and checkpoint I/O helpers.
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.
Description check Passed The description covers the changes, rationale, tests, and checklist. The two model-loader test paths should use _torch/executor, not _torch/pyexecutor. The description should also identify the API…
Full details: Description check

Explanation

The description covers the changes, rationale, tests, and checklist. The two model-loader test paths should use _torch/executor, not _torch/pyexecutor. The description should also identify the API-breaking change.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: Repository: NVIDIA/TensorRT-LLM/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 659314ab-2fb8-414c-b54b-2bb762883bde
📥 Commits

Reviewing files that changed from the base of the PR and between 464ee07 and b68e017.

📒 Files selected for processing: 7

  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/executor/base_worker.py
  • tensorrt_llm/tools/layer_wise_benchmarks/runner.py
  • tests/unittest/_torch/executor/test_model_loader_checkpoint_io.py
  • tests/unittest/_torch/executor/test_model_loader_mx.py

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

@yijingl-nvidia yijingl-nvidia changed the title [None][refactor] BREAKING: Use a string enum for built-in checkpoint formats [https://nvbugs/5812522][refactor] BREAKING: Use a string enum for built-in checkpoint formats Oct 20, 2026
@yijingl-nvidia yijingl-nvidia changed the title [https://nvbugs/5812522][refactor] BREAKING: Use a string enum for built-in checkpoint formats [TRTLLM-16725][refactor] BREAKING: Use a string enum for built-in checkpoint formats Oct 20, 2026
@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/checkpoint-format-enum branch from 3c7ad68 to 5aa311e Compare October 20, 2026 22:43
@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/checkpoint-format-enum branch from 5aa311e to 4b6e5b4 Compare October 21, 2026 18:15
Use a new str enum CheckpointFormat for built-in checkpoint formats like "HF", "MX" and "mistral".
Custom 3rd-party formats are still accepted as str.
This improves code readability and maintenance.

Signed-off-by: Yijing Li <[email protected]>
tighten function parameter load_format type range from LoadFormat | str to LoadFormat.
This is dead code as the upstream functions don't use checkpoint loading helper functions with str load formats.

Signed-off-by: Yijing Li <[email protected]>
Refactor the function that generates checkpoint io policy fallback/error reason
so it's easier for humans to read.
Also rename _construct_checkpoint_loader to construct_checkpoint_loader since it's
used outside the file defining it.

Signed-off-by: Yijing Li <[email protected]>
@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/checkpoint-format-enum branch from 9a74b75 to 15f24b8 Compare November 5, 2026 22:29
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82905 [ run ] triggered by Bot. Commit: 15f24b8 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82905 [ run ] completed with state SUCCESS. Commit: 15f24b8
/LLM/main/L0_MergeRequest_PR pipeline #68468 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

@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83119 [ run ] triggered by Bot. Commit: 15f24b8 Link to invocation

@dhansen-nvidia dhansen-nvidia 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.

LGTM

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@yijingl-nvidia
yijingl-nvidia enabled auto-merge (squash) November 6, 2026 18:04
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83119 [ run ] completed with state SUCCESS. Commit: 15f24b8
/LLM/main/L0_MergeRequest_PR pipeline #68672 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@yijingl-nvidia
yijingl-nvidia merged commit 1436567 into NVIDIA:main Nov 6, 2026
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 8, 2026
…in's Qwen3.5-VL test

Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), while NVIDIA#21434 added a Qwen3.5-VL test that still imports the old
name, so the whole test module fails to import. The pre-merge H100 stage
runs it, and an x86 single-GPU failure keeps the x86 multi-GPU stages from
running. The renamed helper takes the same keyword arguments.

Signed-off-by: ziyixiong-nv <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 8, 2026
…in's Qwen3.5-VL test

Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), while NVIDIA#21434 added a Qwen3.5-VL test that still imports the old
name, so the whole test module fails to import. The pre-merge H100 stage
runs it, and an x86 single-GPU failure keeps the x86 multi-GPU stages from
running. The renamed helper takes the same keyword arguments.

Signed-off-by: ziyixiong-nv <[email protected]>
dc3671 added a commit to dc3671/TensorRT-LLM that referenced this pull request Nov 8, 2026
…loader

NVIDIA#20703 renamed _construct_checkpoint_loader; NVIDIA#21434 still imported the old
name, so every unittest/_torch/modeling run failed collection on main.

Signed-off-by: Zhenhuan Chen <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 9, 2026
Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), so the test's import failed at collection, before its GPU skip.

Signed-off-by: ziyixiong-nv <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 9, 2026
Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), so the test's import failed at collection, before its GPU skip.

Signed-off-by: ziyixiong-nv <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 10, 2026
Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), so the test's import failed at collection, before its GPU skip.

Signed-off-by: ziyixiong-nv <[email protected]>
hanjingtian pushed a commit to ruocheng-nv/TensorRT-LLM that referenced this pull request Nov 11, 2026
…ests fixed by NVIDIA#21876

test_modeling_qwen3_5_vl.py imported _construct_checkpoint_loader, which
NVIDIA#20703 had renamed to construct_checkpoint_loader, so pytest could not
collect the module. Every test list entry that collects it failed, and
14 entries were waived under this bug. NVIDIA#21876 switched the test to the
new name; remove the waivers.

Signed-off-by: Ruocheng Jia <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 12, 2026
Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), so the test's import failed at collection, before its GPU skip.

Signed-off-by: ziyixiong-nv <[email protected]>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request Nov 14, 2026
Main renamed _construct_checkpoint_loader to construct_checkpoint_loader
(NVIDIA#20703), so the test's import failed at collection, before its GPU skip.

Signed-off-by: ziyixiong-nv <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-breaking Accepted LLM API contract change that is backwards-incompatible ci: full pre-merge approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants