Repository navigation
FIX Accept layers_to_transform=0 together with layers_pattern - #3425
Merged
githubnemo merged 1 commit intoAug 13, 2026
Merged
Conversation
The config `__post_init__` guarded the `layers_pattern`/`layers_to_transform` pairing with `if self.layers_pattern and not self.layers_to_transform:`. Since 0 is falsy, passing the valid first-layer index `layers_to_transform=0` alongside a `layers_pattern` wrongly raised "When `layers_pattern` is specified, `layers_to_transform` must also be specified." even though it was specified. `layers_to_transform=1` or `[0]` were accepted, so only index 0 was rejected. The consuming matcher already treats 0 as a valid index (`check_target_module_exists` in `tuners_utils.py` uses `layer_indexes is not None`), and the docstring states the pattern is "used only if `layers_to_transform` is different from None", so the guard should compare against None. This check was duplicated verbatim across all tuner configs, so it is fixed in every one. Added a parametrized test covering every config that supports layer indexing.
|
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No linked issue — found by reading the code.
What this fixes
Every tuner config validates the
layers_pattern/layers_to_transformpairing in__post_init__with:Because
0is falsy, passing the valid first-layer indexlayers_to_transform=0together with alayers_patternwrongly raises — even thoughlayers_to_transformwas specified:Only index
0is affected —1and[0](the same logical request) are accepted.Why
is Noneis the correct check0as a valid index —check_target_module_existsinsrc/peft/tuners/tuners_utils.pygates onlayer_indexes is not None, and the sibling check a few lines above in the same__post_init__also usesself.layers_to_transform is not None.layers_to_transformis different fromNone."So the guard should compare against
None, not truthiness. The check was added in #2159 and its message improved in #2169, but the falsy-0case remained.Scope
The identical guard is duplicated across all 19 tuner configs that support layer indexing (lora, adalora, boft, deft, delora, fourierft, frod, hra, lily, loha, lokr, oft, peanut, psoft, pvera, tinylora, vblora, vera, waveft), so the one-line fix is applied to every one.
Testing
Added
test_config_layers_to_transform_index_zero, parametrized over every config inALL_CONFIG_CLASSESthat supportslayers_to_transform(25 configs), assertinglayers_to_transform=0+layers_patternis accepted. It fails before this change (19 of the configs raise) and passes after.ruff check/ruff format --checkare clean andtests/test_config.pypasses (1218 passed).