ImportError: cannot import name 'check_peft_version' from 'transformers.utils'
Author: nrchan
Pull request: no

### System Info

The error happens when I try to import Trainer
```python
from transformers import Trainer
```

Here's the traceback:
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File /miniconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py:1130, in _LazyModule._get_module(self, module_name)
   1129 try:
-> 1130     return importlib.import_module("." + module_name, self.__name__)
   1131 except Exception as e:

File /miniconda3/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1006, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:688, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:883, in exec_module(self, module)

File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f, *args, **kwds)

File /miniconda3/lib/python3.10/site-packages/transformers/trainer.py:40
     38 # Integrations must be imported before ML frameworks:
     39 # isort: off
---> 40 from .integrations import (
     41     get_reporting_integration_callbacks,
     42     hp_params,
     43     is_fairscale_available,
     44 )
     46 # isort: on

File /miniconda3/lib/python3.10/site-packages/transformers/integrations/__init__.py:71
     33 from .integration_utils import (
     34     INTEGRATION_TO_CALLBACK,
     35     AzureMLCallback,
   (...)
     69     run_hp_search_wandb,
     70 )
---> 71 from .peft import PeftAdapterMixin

File /miniconda3/lib/python3.10/site-packages/transformers/integrations/peft.py:17
     15 from typing import Optional
---> 17 from ..utils import (
     18     check_peft_version,
     19     find_adapter_config_file,
     20     is_accelerate_available,
     21     is_peft_available,
     22     logging,
     23 )
     26 if is_accelerate_available():

ImportError: cannot import name 'check_peft_version' from 'transformers.utils' (/miniconda3/lib/python3.10/site-packages/transformers/utils/__init__.py)

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[1], line 2
      1 import torch
----> 2 from transformers import T5Tokenizer, T5Config, T5ForConditionalGeneration, Trainer, TrainingArguments
      3 from torch.utils.data import Dataset
      4 import pandas as pd

File <frozen importlib._bootstrap>:1075, in _handle_fromlist(module, fromlist, import_, recursive)

File /miniconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py:1120, in _LazyModule.__getattr__(self, name)
   1118     value = self._get_module(name)
   1119 elif name in self._class_to_module.keys():
-> 1120     module = self._get_module(self._class_to_module[name])
   1121     value = getattr(module, name)
   1122 else:

File /miniconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py:1132, in _LazyModule._get_module(self, module_name)
   1130     return importlib.import_module("." + module_name, self.__name__)
   1131 except Exception as e:
-> 1132     raise RuntimeError(
   1133         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1134         f" traceback):\n{e}"
   1135     ) from e

RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
cannot import name 'check_peft_version' from 'transformers.utils' (/miniconda3/lib/python3.10/site-packages/transformers/utils/__init__.py)
```

I'm sorry ```transformers-cli env``` doesn't work somehow, I'm using transformers 4.33.0 and pytorch 2.0.1.

Thanks for any help!

### Who can help?

@muellerzr @pac

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

Steps to reproduce the behavior:

1.  Run ```from transformers import Trainer```
2.  Exception happen

### Expected behavior

This code used to run last week, I guess there might be some packages conflicting (?)

Comments:
CC @pacman100 

Same problem here

Cc @pacman100 

cc @younesbelkada as he has worked on the PEFT integration in Transformers and can quickly look into it

Hi @nrchan 
Thanks for the issue, I tried to reproduce the issue and did not managed to. I used `transformers==4.33.0` and I tried your command with and without peft library being installed. Note that `check_peft_version` method is correctly part of `transformers.utils`: https://github.com/huggingface/transformers/blob/main/src/transformers/utils/__init__.py#L189 then: https://github.com/huggingface/transformers/blob/main/src/transformers/utils/peft_utils.py#L106

I am also very surprised about this issue because it seems quite critical and it is strange that we did not flagged it either in our CI or nightly build tests.

Can you try again with transformers == 4.33.1 ? 

```bash
pip install -U transformers
```

@younesbelkada Hi, I tried to install all my packages again and the issue was gone. Not really sure what is happening... 
Thanks for helping :)

Thanks! Closing the issue! Glad it worked :) 

I am getting the same error with `transformers==4.33.0`:

```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py](https://localhost:8080/#) in _get_module(self, module_name)
   1116         try:
-> 1117             return importlib.import_module("." + module_name, self.__name__)
   1118         except Exception as e:

13 frames
ImportError: cannot import name 'check_peft_version' from 'transformers.utils' (/usr/local/lib/python3.10/dist-packages/transformers/utils/__init__.py)

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py](https://localhost:8080/#) in _get_module(self, module_name)
   1117             return importlib.import_module("." + module_name, self.__name__)
   1118         except Exception as e:
-> 1119             raise RuntimeError(
   1120                 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1121                 f" traceback):\n{e}"

RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
cannot import name 'check_peft_version' from 'transformers.utils' (/usr/local/lib/python3.10/dist-packages/transformers/utils/__init__.py)
```

ImportError                               Traceback (most recent call last)
Cell In[29], line 1
----> 1 from transformers import BertForCausalLM

ImportError: cannot import name 'BertForCausalLM' from 'transformers' (/opt/miniconda/lib/python3.11/site-packages/transformers/__init__.py)
Selection deleted