Repository navigation
[TRTLLM-16725][refactor] BREAKING: Use a string enum for checkpoint formats and simplify checkpoint I/O helpers - #20703
Conversation
3c7ad68 to
5aa311e
Compare
5aa311e to
4b6e5b4
Compare
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]>
9a74b75 to
15f24b8
Compare
|
/bot run |
|
PR_Github #82905 [ run ] triggered by Bot. Commit: |
|
PR_Github #82905 [ run ] completed with state
|
|
/bot run |
|
PR_Github #83119 [ run ] triggered by Bot. Commit: |
|
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. |
|
PR_Github #83119 [ run ] completed with state |
…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]>
…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]>
…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]>
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]>
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]>
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]>
…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]>
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]>
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]>
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:
CheckpointFormatcovers formats such as"HF","MX"and"mistral". Custom formats can still use strings. The serve configuration schemas intensorrt_llm/schemas/change to match.LoadFormatin the checkpoint I/O helpers (commit diff). All callers give aLoadFormat, so the code for string values was dead code. No functional change._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 asconstruct_checkpoint_loader(), because other modules use it.Test Coverage
1 test added, 12 tests changed:
tests/unittest/_torch/pyexecutor/test_model_loader_checkpoint_io.pytests/unittest/_torch/pyexecutor/test_model_loader_mx.pytests/unittest/llmapi/test_llm_args.pytests/unittest/llmapi/test_serialization.pytests/unittest/usage/test_collectors.pyPR 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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.
checkpoint_io_policyfrom plain strings to the string enumCheckpointIOPolicy.CheckpointFormatfor the built-in checkpoint formats, make the checkpoint I/O helpers take onlyLoadFormat, and make the checkpoint I/O policy resolution easier to read.distributed/initialization.py.ModelLoader.load()shorter: move its MX, GMS, memory and model-hook helpers to new files inmodels/checkpoints/.BaseCheckpointLoader.modeling_kimi_linear.pytomodeling_kimi_k3_loader.py.checkpoint_io_policy="model_streamer", which loads a checkpoint with Run:ai Model Streamer.🤖 Generated with Claude Code
Dev Engineer Review
The change adds public
CheckpointFormatandCheckpointIOPolicyenums. 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.HFandCheckpointIOPolicy.AUTO.The change renames
_construct_checkpoint_loadertoconstruct_checkpoint_loaderand updates its callers. This is an API-breaking change. Callers that compare formats, inspect annotations, serializeTorchLlmArgs, 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.pytests/unittest/api_stability/references/llm.yamltests/unittest/llmapi/test_llm_args.pytests/unittest/llmapi/test_serialization.pytests/unittest/usage/test_collectors.pyNo 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 throughconstruct_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 andCheckpointFormat.MISTRAL. No test-list entry applies.tests/unittest/usage/test_collectors.py: Covers checkpoint-format value serialization. No test-list entry applies.