From 1a9878be8cbf3b78347a795a2b0bdde01832e3cd Mon Sep 17 00:00:00 2001 From: yael shraga Date: Mon, 13 Apr 2026 16:42:34 +0300 Subject: [PATCH 1/2] Refactor: use get_submodule with manual traversal fallback in get_module --- auto_round/utils/model.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/auto_round/utils/model.py b/auto_round/utils/model.py index e60e595ec..351ead656 100644 --- a/auto_round/utils/model.py +++ b/auto_round/utils/model.py @@ -1193,14 +1193,22 @@ def set_attr(model, key, new_attr): def get_module(module, key): - """Get module from model by key name using PyTorch native API. - - Missing paths return `None` to preserve legacy non-fail-fast behavior. + """ + Get module from model by key name using PyTorch native API with a + fallback to manual traversal for backward compatibility. """ try: return module.get_submodule(key) except (AttributeError, KeyError): - return None + pass + + attrs = key.split(".") + for attr in attrs: + try: + module = getattr(module, attr) + except AttributeError: + return None + return module def set_module(model, key, new_module): From 3cf652cc567d77de95a16bba0b5c3035c94613fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 14:05:43 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- auto_round/utils/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_round/utils/model.py b/auto_round/utils/model.py index 351ead656..5dbb22811 100644 --- a/auto_round/utils/model.py +++ b/auto_round/utils/model.py @@ -1194,7 +1194,7 @@ def set_attr(model, key, new_attr): def get_module(module, key): """ - Get module from model by key name using PyTorch native API with a + Get module from model by key name using PyTorch native API with a fallback to manual traversal for backward compatibility. """ try: