Repository navigation
[TRTLLM-14839][chore] Add shim files for root PEFT module relocation #17857
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
Merged
Changes from all commits
Commits
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
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
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,43 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
| """Compatibility shim for ``tensorrt_llm.lora_helper``. | ||
|
|
||
| Will be removed once all usages are migrated to | ||
| ``tensorrt_llm._torch.peft.lora.config``. | ||
|
|
||
| DO NOT ADD ANYTHING TO THIS FILE. | ||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| from tensorrt_llm._torch.peft.lora.config import ( # noqa: F401 | ||
| LoraConfig, | ||
| get_default_trtllm_modules_to_hf_modules, | ||
| get_missing_qkv_modules_from_lora_modules, | ||
| ) | ||
|
|
||
| warnings.warn( | ||
| "tensorrt_llm.lora_helper has moved to " | ||
| "tensorrt_llm._torch.peft.lora.config and will be removed in a future " | ||
| "release.", | ||
| FutureWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "LoraConfig", | ||
| "get_default_trtllm_modules_to_hf_modules", | ||
| "get_missing_qkv_modules_from_lora_modules", | ||
| ] |
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,54 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
| """Compatibility shim for ``tensorrt_llm.lora_manager``. | ||
|
|
||
| Will be removed once all usages are migrated to | ||
| ``tensorrt_llm._torch.peft.lora.config`` and | ||
| ``tensorrt_llm._torch.peft.lora.loaders`` and | ||
| ``tensorrt_llm._torch.peft.lora.manager``. | ||
|
|
||
| DO NOT ADD ANYTHING TO THIS FILE. | ||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| from tensorrt_llm._torch.peft.lora.config import LoraConfig # noqa: F401 | ||
| from tensorrt_llm._torch.peft.lora.loaders import HfLoraLoader, NemoLoraLoader # noqa: F401 | ||
| from tensorrt_llm._torch.peft.lora.manager import ( # noqa: F401 | ||
| LoraManager, | ||
| LoraModelConfig, | ||
| load_torch_lora, | ||
| load_torch_nemo_lora, | ||
| ) | ||
|
|
||
| warnings.warn( | ||
| "tensorrt_llm.lora_manager has moved to " | ||
| "tensorrt_llm._torch.peft.lora.config and " | ||
| "tensorrt_llm._torch.peft.lora.loaders and " | ||
| "tensorrt_llm._torch.peft.lora.manager and will be removed in a " | ||
| "future release.", | ||
| FutureWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "HfLoraLoader", | ||
| "LoraConfig", | ||
| "LoraManager", | ||
| "LoraModelConfig", | ||
| "NemoLoraLoader", | ||
| "load_torch_lora", | ||
| "load_torch_nemo_lora", | ||
| ] |
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,37 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
| """Compatibility shim for ``tensorrt_llm.prompt_adapter_manager``. | ||
|
|
||
| Will be removed once all usages are migrated to | ||
| ``tensorrt_llm._torch.peft.prompt_adapter``. | ||
|
|
||
| DO NOT ADD ANYTHING TO THIS FILE. | ||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| from tensorrt_llm._torch.peft.prompt_adapter import PromptAdapterManager # noqa: F401 | ||
|
|
||
| warnings.warn( | ||
| "tensorrt_llm.prompt_adapter_manager has moved to " | ||
| "tensorrt_llm._torch.peft.prompt_adapter and will be removed in a " | ||
| "future release.", | ||
| FutureWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "PromptAdapterManager", | ||
| ] |
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,99 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
| """The compatibility modules kept at the pre-move PEFT import paths. | ||
|
|
||
| Each one must forward every name in its own ``__all__`` to the module that | ||
| defines it, as the same object. The names are read from the module rather than | ||
| restated here, so changing the export set changes what is verified. | ||
|
|
||
| ``lora_manager`` is the interesting case: it is the only one whose names do not | ||
| all live in a single module. It was one file before the move and is three now, | ||
| so the test resolves each name to wherever it is actually defined instead of | ||
| assuming a single destination -- which is also what stops the shim from | ||
| quietly pointing a name at a module that merely re-exports it. | ||
| """ | ||
|
|
||
| import importlib | ||
| import sys | ||
| import warnings | ||
|
|
||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.cpu_only | ||
|
|
||
| FORWARDING_PATHS = ( | ||
| "tensorrt_llm.lora_helper", | ||
| "tensorrt_llm.lora_manager", | ||
| "tensorrt_llm.prompt_adapter_manager", | ||
| ) | ||
|
|
||
| CANONICAL_PREFIX = "tensorrt_llm._torch.peft." | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("forwarding_path", FORWARDING_PATHS) | ||
| def test_published_names_come_from_where_they_are_defined(forwarding_path: str) -> None: | ||
| """Identity against the defining module, not against the shim's target. | ||
|
|
||
| A re-implementation would compare equal and still break ``isinstance`` and | ||
| unpickling for callers that kept the old import path. Resolving through | ||
| ``__module__`` additionally catches a shim that forwards a name to a module | ||
| that only re-exports it: that spelling resolves, so nothing fails until the | ||
| incidental re-export goes away. | ||
| """ | ||
| forwarding = importlib.import_module(forwarding_path) | ||
|
|
||
| published = getattr(forwarding, "__all__", None) | ||
| assert published, f"{forwarding_path} publishes nothing, so it forwards nothing" | ||
|
|
||
| for name in published: | ||
| obj = getattr(forwarding, name) | ||
| home = getattr(obj, "__module__", None) | ||
| assert home is not None, f"{name} carries no __module__ to check" | ||
| assert home.startswith(CANONICAL_PREFIX), f"{name}.__module__ is {home!r}" | ||
| assert getattr(importlib.import_module(home), name) is obj, name | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("forwarding_path", FORWARDING_PATHS) | ||
| def test_import_warns_once_and_names_the_new_path(forwarding_path: str) -> None: | ||
| """Importing the old path has to say so, and say where to go instead.""" | ||
| # A module body runs once per interpreter, so drop it before re-importing. | ||
| sys.modules.pop(forwarding_path, None) | ||
| with warnings.catch_warnings(record=True) as caught: | ||
| warnings.simplefilter("always") | ||
| forwarding = importlib.import_module(forwarding_path) | ||
|
|
||
| about_this_module = [w for w in caught if forwarding_path in str(w.message)] | ||
| assert len(about_this_module) == 1, [str(w.message) for w in caught] | ||
|
|
||
| message = str(about_this_module[0].message) | ||
| for name in forwarding.__all__: | ||
| home = getattr(getattr(forwarding, name), "__module__", "") | ||
| assert home in message, f"the warning does not mention {home}" | ||
|
|
||
|
|
||
| def test_the_restricted_unpickle_allowlist_still_accepts_the_old_module_strings() -> None: | ||
| """``find_class`` matches the key exactly, before any import happens. | ||
|
|
||
| So the forwarding modules alone do not cover deserialization: a pickle | ||
| written before the move names the old module, and a canonical-only table | ||
| rejects it without ever reaching the shim. | ||
| """ | ||
| from tensorrt_llm.llmapi.serialization import BASE_EXAMPLE_CLASSES | ||
|
|
||
| canonical = "tensorrt_llm._torch.peft.lora.config" | ||
| assert "LoraConfig" in BASE_EXAMPLE_CLASSES[canonical] | ||
| # lora_helper is the module a real pre-move LoraConfig pickle names. | ||
| assert "LoraConfig" in BASE_EXAMPLE_CLASSES["tensorrt_llm.lora_helper"] | ||
| assert "LoraConfig" in BASE_EXAMPLE_CLASSES["tensorrt_llm.lora_manager"] | ||
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.