huggingface / huggingface/peft

PeftModel.set_adapter raises opaque TypeError: unhashable type: 'list' instead of a clear error

Open Beginner friendly
#3,723 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
21.7k
Forks
2.5k
Avg merge
4d 12h
Merged PRs (30d)
59

Description

### System Info

- peft: 0.20.1.dev0 (current `main`, commit `0e8d0ae8`)
- transformers: 5.17.0
- torch: 2.14.0 (CPU)
- Python: 3.13.12
- OS: macOS

### Who can help?

_No response — filing as a fresh issue per CONTRIBUTING.md_

### Reproduction

```python
from peft import get_peft_model, LoraConfig
import torch.nn as nn

model = get_peft_model(nn.Sequential(nn.Linear(10, 20)), LoraConfig(target_modules=["0"], r=4))
model.add_adapter("other", LoraConfig(target_modules=["0"], r=4))
model.set_adapter(["default", "other"])
```

```
Traceback (most recent call last):
File ".../peft/peft_model.py", line 1622, in set_adapter
if adapter_name not in self.peft_config:
TypeError: unhashable type: 'list'
```

### Expected behavior

`PeftModel.set_adapter` is typed and documented to take a single `str` ("Only one adapter can be
active at a time"), so passing a list is user error — but the failure mode is a bare
`TypeError: unhashable type: 'list'` raised from the internal `self.peft_config` dict lookup,
three frames removed from any peft code, with no indication of what went wrong or what to do
instead.

This is an easy mistake to make because sibling/related methods on the same class or an adjacent
class *do* accept a list: `PeftMixedModel.set_adapter`, `BaseTuner.set_adapter` (reachable as
`model.base_model.set_adapter`), and `PeftModel.set_requires_grad` all take `Union[str, list[str]]`
or `Sequence[str]`. #1374 shows a user independently reaching for
`model.base_model.set_adapter(list(...))` to activate multiple adapters — i.e. guessing that
`set_adapter` takes a list is a real, observed pattern, not a hypothetical.

I'd like to fix this by raising a clear `TypeError` when `adapter_name` isn't a `str`, explaining
that `PeftModel.set_adapter` only supports a single adapter and pointing at
`model.base_model.set_adapter(adapter_names)` for the multi-adapter case — mirroring the guidance
already given in #1374. I have a small fix + regression test ready (verified red/green against
current `main`, existing test suite green) and will open a PR referencing this issue once it's
approved, per CONTRIBUTING.md.

Contributor guide

Open the contributing guide

Research direction

Start at peft/peft_model.py around line 1622 and inspect PeftModel.set_adapter alongside the related set_adapter entry points described in the issue. Add regression coverage for the list argument and run the existing test suite; done means the invalid input produces a clear TypeError directing users to the multi-adapter alternative.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
api, machine-learning, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.