PEFT: Access active_adapters as a property in Trainer
Author: pashminacameron
Pull request: yes

PEFTModel has a property called `active_adapters`. It was being accessed as a function which led to the below error.
Seeing issues such as 
```
    trainer.train()
  File "C:\dev\anaconda3\envs\env-gpu\Lib\site-packages\transformers\trainer.py", line 1885, in train
    return inner_training_loop(
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\anaconda3\envs\env-gpu\Lib\site-packages\transformers\trainer.py", line 2339, in _inner_training_loop
    self._load_best_model()
  File "C:\dev\anaconda3\envs\env-gpu\Lib\site-packages\transformers\trainer.py", line 2629, in _load_best_model
    active_adapter = model.active_adapters()[0]
                     ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'list' object is not callable
``` 
Issue seems similar to #30754 and was likely introduced in #30738

Fixes: https://github.com/huggingface/transformers/issues/30754

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@younesbelkada 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_30790). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Thanks :) now I can stop hitting my head on the table.

I thought this was the solution to my similar error,
but it turned out, my transformer actually contains this commit but failed in a different way:

  File "/home/jimmy/pyvenv/310/lib/python3.10/site-packages/transformers/trainer.py", line 2694, in _load_best_model
    active_adapter = model.active_adapters[0]
TypeError: 'method' object is not subscriptable

I am trying to run this example: 
https://github.com/huggingface/peft/blob/fb607d00adc7b8aa1694f58a786ce2cd5681710d/docs/source/task_guides/ptuning-seq-classification.md

Thanks huggingface for these libraries!

cc @BenjaminBossan


Hey @speculaas Which `peft` and `transformers` versions (or commits) do you have? Thanks. 

thanks for your help!

My peft and transformers versions are:
```
.venv/lib/python3.12/site-packages/peft$ pgrep "_version" 
./__init__.py:20:__version__ = "0.11.1"

.venv/lib/python3.12/site-packages/transformers$ pgrep "_version" | grep _init 
./__init__.py:21:__version__ = "4.42.3"
```


Thanks for reporting the problem. The problematic line is the following:

https://github.com/huggingface/peft/blob/1b16753a6aca2fc9581823c8e2efd628b7d2b676/src/peft/peft_model.py#L181

The issue stems from the fact that if the `base_model` is some kind of PEFT model, e.g. `LoraModel`, `self.base_model.active_adapters` will return a list. However, if the underlying base model is a transformers model, as is the case here, `active_adapters` is a method that needs to be called. It is unfortunate that there are two methods with the same name but one is a property and the other is not.

Anyway, this is an issue that should be fixed on the PEFT side. I'll work on a PR.

PR: https://github.com/huggingface/peft/pull/1975

The PR is merged.

Thanks for the fix and explanation!

> The PR is merged.

Do you recommend install it from source?

> Do you recommend install it from source?

Installing from source is always a little bit more risky when it comes to breaking things, so if you can wait, I would wait for the next release. That said, if you fix the commit hash, you'll be most likely fine when installing from source.