Skip to content

fix(core): make save_adapters/load_adapters round-trip - #16302

Open
SIDDARTHAREDDY8 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
SIDDARTHAREDDY8:issue-16102-adapter-roundtrip
Open

SIDDARTHAREDDY8 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
SIDDARTHAREDDY8:issue-16102-adapter-roundtrip

Conversation

@SIDDARTHAREDDY8

Copy link
Copy Markdown

Fixes #16102

AdapterModelPTMixin.save_adapters() / load_adapters() did not round-trip. Two independent defects, both in nemo/core/classes/mixins/adapter_mixins.py:

  1. A file saved for a subset of adapters could not be loaded with the documented default name=None. load_adapters derived its restore list from the source model's entire adapter config (list(config.keys())) rather than from the file, raising KeyError for every adapter the file never contained. It now derives the list from list(state_dict.keys()), which is by construction exactly the adapters the file holds.

  2. Adapter state-dict keys were selected/stripped by substring (adapter_name in k / k.replace(...)), so saving an4 silently serialized all of an4_v2's tensors into the file and broke the subsequent strict load_state_dict. Keys are now matched/stripped on the exact '<adapter_name>.' prefix, so overlapping names no longer contaminate each other.

Test plan

  • tests/core/mixins/adapters/ (3 files): 68 passed (TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1), including the 2 new regression tests.
  • test_save_adapter_subset_then_load_with_default_name and test_save_load_adapter_with_name_that_is_prefix_of_another both fail on unpatched code (KeyError; foreign keys in saved file) and pass with the fix.

Notes for the reviewer

Signed-off-by: SIDDARTHA REDDY <75976672+SIDDARTHAREDDY8@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the core Changes to NeMo Core label Sep 27, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request core Changes to NeMo Core waiting-on-maintainers Waiting on maintainers to respond

2 participants