Skip to content

FIX Raise an error when a PEFT method targets an unsupported layer type - #4015

Merged
BenjaminBossan merged 1 commit into
huggingface:mainfrom
devYRPauli:fix/unsupported-target-layer-errors
Oct 20, 2026
Merged

BenjaminBossan merged 1 commit into
huggingface:mainfrom
devYRPauli:fix/unsupported-target-layer-errors

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

PR description

Resolves #3986. Approval: #3986 (comment)

OSF skipped a target module that is not nn.Linear and gave no error. With the gpt2 example from the OSF docs, the model had 0 trainable parameters, and loss.backward() failed.

Changes:

  • OSF raises an error when a target module is not nn.Linear. The error is a TypeError because the repo's ruff rule TRY004 rejects a ValueError after an isinstance check. BOFT, WaveFT, and TinyLoRA raise a TypeError for the same case.
  • The OSF docs example uses facebook/opt-125m with q_proj and v_proj. I ran the example: 27,887,328 trainable parameters, and the backward pass runs.
  • The new test_targeting_unknown_layer_type_raises in test_custom_models.py runs for every MLP entry that sets target_modules. A new Vanilla MLP 3 OSF entry sets target_modules, so OSF is not skipped. The 2 existing OSF entries still test the default all-linear path.
  • Lily and PEANuT raised NotImplementedError. They now raise a ValueError with the shared Target module ... is not supported wording.
  • GLoRA now uses the shared wording.
  • TinyLoRA raised KeyError: 'lin0', because its layer index only holds the supported layer types. It now raises its existing TypeError for an unsupported layer.
  • WaveFT with proportional_parameters=True said "No target modules found" when no target was a supported type. It now uses the same wording as VeRA, PVeRA, RandLora and FRoD: No layer types compatible with WaveFT were found.

I did not change any TypeError. LoHa and LoKr keep their TypeError and wording. VeRA, PVeRA, RandLora, and FRoD check all targets before the first layer is created, so the test also accepts their No layer(s) types compatible error.

Behavior change: OSFConfig() without target_modules on gpt2 now raises an error. Before, it gave 0 trainable parameters. The gpt2 entry in TRANSFORMERS_MODELS_TO_OSF_TARGET_MODULES_MAPPING points to Conv1D layers. I did not remove it because the error names the Conv1D layer.

Tests:

  • pytest tests/test_custom_models.py -k test_targeting_unknown_layer_type_raises: 226 passed, 109 skipped. On main, 25 fail: GLoRA 6, TinyLoRA 6, Lily 5, PEANuT 5, WaveFT 2, OSF 1.
  • pytest tests/test_osf.py: 8 passed. The 3 new cases fail on main.
  • pytest tests/ --ignore=tests/test_seq_classifier.py -k "osf or lily or peanut or glora or waveft or tinylora or targeting_unknown": 4156 passed, 40 failed, 1305 skipped. The same 40 tests fail on main on my machine (macOS, CPU), all in test_training_*_gradient_checkpointing and test_disable_adapter of the decoder and encoder-decoder tests. This PR adds no failures.
  • make quality: passes.

I used Claude Code CLI with Opus 5.5.

OSF skipped a target module that is not nn.Linear without an error, so
the model had 0 trainable parameters. OSF now raises a TypeError, and
the OSF docs example uses OPT with q_proj and v_proj.

Lily and PEANuT raised NotImplementedError, GLoRA used its own wording,
TinyLoRA raised a KeyError, and WaveFT with proportional_parameters said
that no target module was found. They now use the shared wording.

The new test_targeting_unknown_layer_type_raises runs for every MLP test
case that sets target_modules.

Resolves huggingface#3986

Co-Authored-By: Claude Opus 5.5 <[email protected]>
devYRPauli added a commit to devYRPauli/devYRPauli that referenced this pull request Oct 19, 2026
Merged external pull requests: 137 across 36 projects, unchanged. Open:
60 -> 61 (huggingface/peft#4015). Upstream issues: 23 -> 22
(anomalyco/opencode#46868 closed as fixed on v2).

No table row moved. The table still covers 84 merges across 13 projects,
so the remainder is 53 across 23.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, it looks clean. Failing CI is unrelated.

@BenjaminBossan
BenjaminBossan merged commit d04e37f into huggingface:main Oct 20, 2026
17 of 19 checks passed
devYRPauli added a commit to devYRPauli/devYRPauli that referenced this pull request Oct 22, 2026
Merged external pull requests: 137 -> 143 across 36 -> 37 projects
(huggingface/peft#4015, infiniflow/ragflow#20925, #20926, #20927, #20928,
sqlfluff/sqlfluff#8620). Open: 62 -> 55. Upstream issues: 23 -> 20.

Table rows that moved: RAGFlow 26 -> 30. PEFT is new at 22k stars, above
the table's 10k floor, with 1 merge.

The table now covers 89 merges across 14 projects, so the remainder is 54
across 23.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSF wraps nothing on non-Linear targets and raises no error, so the gpt2 docs example trains 0 parameters

3 participants