model.add_adapter() does not work correctly, raising the following error while check_peft_version : [PEFT is not installed. Please install it with `pip install peft`]
Author: aghris
Pull request: no

### System Info

- `transformers` version: 4.35.0
- Platform: Linux-5.15.120+-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: 0.24.1
- Accelerate config: 	not found
- PyTorch version (GPU?): 2.1.0+cu121 (True)
- Tensorflow version (GPU?): 2.14.0 (True)
- Flax version (CPU?/GPU?/TPU?): 0.7.4 (gpu)
- Jax version: 0.4.16
- JaxLib version: 0.4.16
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

I am attempting to fine-tune a fully quantized LLM model. So, I need to attach trainable adapters to enhance its performance. However, during this process, I encountered this error "PEFT is not installed. Please install it with pip install peft," that was triggered by the check_peft_version() function.

In an effort to diagnose the issue, I employed two diagnostic functions from the transformers.utils.import_utils module: is_peft_available and _is_package_available. Interestingly, **_is_package_available("peft")** returns **True** while, **is_peft_available()** returns **False**.

Code details: 
Model: "mistralai/Mistral-7B-v0.1"
Quantization:  BitsAndBytes
Peft_ adapter: Lora

Additionally, I have followed the example provided on the HuggingFace platform, available at their documentation site (https://huggingface.co/docs/transformers/main/peft) but, I encountered the same issue.

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```python
from transformers import AutoTokenizer, MistralForSequenceClassification
from peft import PeftModel, get_peft_model, LoraConfig, TaskType, prepare_model_for_kbit_training
from transformers import BitsAndBytesConfig
import torch

peft_config = LoraConfig(
    r=64,
    lora_alpha=16,
    lora_dropout=0.1,
    bias="none",
    task_type=TaskType.SEQ_CLS,
    inference_mode=False,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]
)
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype=torch.bfloat16
)

model_name = "mistralai/Mistral-7B-v0.1"
model = MistralForSequenceClassification.from_pretrained(
    model_name,
    num_labels=3,
    quantization_config=bnb_config,
    device_map="auto"
)

model.gradient_checkpointing_enable()
model= prepare_model_for_kbit_training(model)
peft_config.init_lora_weights = False
model.add_adapter(peft_config, adapter_name='adapter')
```

### Expected behavior

**_is_package_available("peft")** and **is_peft_available()** imported from the transformers.utils.import_utils module both have to return the same value either True or False. 

Comments:
cc @pacman100 @younesbelkada 

you may have a broken installation of peft, can you try to re-run your script by uninstall peft and re-installing it again?
```bash
pip uninstall peft && pip install -U peft
```

Thank you for your response. However, I have implemented that solution previously but encountered the same issue. Additionally, I have conducted tests on both the Kaggle platform and Google Colab to verify the results.

Hi @aghris 
Hmmm I tried again with an environment having PEFT freshly installed and did not managed to repro - I ran the same script as yours and just replaced the checkpoint to a smaller checkpoint:
```python
from transformers import AutoTokenizer, MistralForSequenceClassification
from peft import PeftModel, get_peft_model, LoraConfig, TaskType, prepare_model_for_kbit_training
from transformers import BitsAndBytesConfig
import torch

peft_config = LoraConfig(
    r=64,
    lora_alpha=16,
    lora_dropout=0.1,
    bias="none",
    task_type=TaskType.SEQ_CLS,
    inference_mode=False,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]
)
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype=torch.bfloat16
)

model_name = "hf-internal-testing/tiny-random-MistralForCausalLM"
model = MistralForSequenceClassification.from_pretrained(
    model_name,
    num_labels=3,
    quantization_config=bnb_config,
    device_map="auto"
)

model.gradient_checkpointing_enable()
model= prepare_model_for_kbit_training(model)
peft_config.init_lora_weights = False
model.add_adapter(peft_config, adapter_name='adapter')
```
A conflict could also happen if you have a `peft/` directory somewhere in your working directory 

Could you please try it in a sample google colab notebook?

Thank you in advance

Hi @aghris
I just made this notebook: https://colab.research.google.com/drive/16S4U9v9oBJYVtCm_-wuWi6vBGDfyOsy5?usp=sharing and it seems to work fine on my end 

Thank you @younesbelkada for your cooperative spirit and the time spent helping me. It seems the issue was with the compatibility of certain accelerators in Kaggle and Google Colab environments—specifically, the script functions well with V100/T4 GPUs and TPUs, but encounters problems with P100 and A100 GPUs


Thanks a lot @aghris for double checking ! And no worries
Out of curiosity I ran my snippet on an A100 and it worked fine - really not sure about the issue here :/ 

iIt is quite intriguing. I found out that several users within the community utilizing get_peft_model along with a customized peft_config, bypassing  add_adapter method. I try it and it works correctly.

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.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.