-
Notifications
You must be signed in to change notification settings - Fork 73
fix(client): use canonical TRT-LLM transfer catalogs #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zhengluo-nv
merged 2 commits into
ai-dynamo:main
from
chienchunhung:fix/trtllm-canonical-wire-catalog
Jul 20, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
modelexpress_client/python/tests/test_trtllm_live_transfer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tests for TensorRT-LLM live-transfer catalog validation.""" | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
| import torch | ||
| from torch import nn | ||
|
|
||
| from modelexpress.trtllm_live_transfer import ( | ||
| MxLiveWeightLoader, | ||
| _canonical_named_parameters, | ||
| _require_exact_catalog_match, | ||
| ) | ||
|
|
||
|
|
||
| class _AliasLayer(nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.next_attn = None | ||
| self.self_attn = None | ||
|
|
||
|
|
||
| class _AliasedModel(nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.layers = nn.ModuleList([_AliasLayer(), _AliasLayer()]) | ||
| self.layers[1].self_attn = nn.Linear(2, 2, bias=False) | ||
| self.layers[0].next_attn = self.layers[1].self_attn | ||
|
|
||
|
|
||
| def test_runtime_aliases_are_excluded_from_canonical_catalog(): | ||
| model = _AliasedModel() | ||
|
|
||
| default_names = dict(model.named_parameters()) | ||
| canonical_names = dict(_canonical_named_parameters(model)) | ||
|
|
||
| assert "layers.0.next_attn.weight" in default_names | ||
| assert "layers.1.self_attn.weight" not in default_names | ||
| assert "layers.0.next_attn.weight" not in canonical_names | ||
| assert canonical_names["layers.1.self_attn.weight"] is model.layers[1].self_attn.weight | ||
|
|
||
|
|
||
| def test_exact_catalog_match_is_accepted(): | ||
| tensor = torch.zeros(1) | ||
| _require_exact_catalog_match({"model.weight": object()}, {"model.weight": tensor}) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("source", "target", "message"), | ||
| [ | ||
| ({"source.only": object()}, {}, "1 source tensors are absent"), | ||
| ({}, {"target.only": torch.zeros(1)}, "1 target tensors are absent"), | ||
| ], | ||
| ) | ||
| def test_incomplete_catalogs_fail_closed(source, target, message): | ||
| with pytest.raises(RuntimeError, match=message): | ||
| _require_exact_catalog_match(source, target) | ||
|
|
||
|
|
||
| def test_rank_log_handler_is_closed_on_failure(monkeypatch, tmp_path): | ||
| monkeypatch.setenv("MX_TRANSFER_LOG_DIR", str(tmp_path)) | ||
| monkeypatch.setattr(torch.cuda, "current_device", lambda: 0) | ||
| loader = MxLiveWeightLoader() | ||
| monkeypatch.setattr( | ||
| loader, | ||
| "_load_weights", | ||
| lambda **kwargs: (_ for _ in ()).throw(RuntimeError("catalog mismatch")), | ||
| ) | ||
|
|
||
| with pytest.raises(RuntimeError, match="catalog mismatch"): | ||
| loader.load_weights("checkpoint", model=object()) | ||
|
|
||
| rank_log = tmp_path / "rank0.log" | ||
| assert all( | ||
| getattr(handler, "baseFilename", None) != str(rank_log) | ||
| for handler in logging.getLogger("modelexpress").handlers | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.