Failed to import transformers.trainer, cannot import name 'TypedDict' from 'huggingface_hub.utils._typing'
Author: texasdave2
Pull request: no

### System Info

Hello, thanks again for looking over this, always appreciate the help.

Was running a notebook that uses peft and lora.  

@muellerzr @pacman100 

Transformers version:  
4.34.0.dev0


Python version:
3.9.17

```
!pip install bitsandbytes datasets accelerate loralib

!pip install git+https://github.com/huggingface/peft.git

!pip install git+https://github.com/huggingface/transformers
```


model:

```
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
import torch
import torch.nn as nn
import bitsandbytes as bnb
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)

model = AutoModelForCausalLM.from_pretrained(
    "facebook/opt-1.3b",
    quantization_config=bnb_config,
    device_map='auto',
    trust_remote_code=True,
)

model.config.use_cache = False

tokenizer = AutoTokenizer.from_pretrained("facebook/opt-1.3b")

```

Trainer:


```
import transformers
from datasets import load_dataset
data = load_dataset("Abirate/english_quotes")
data = data.map(lambda samples: tokenizer(samples['quote']), batched=True)

trainer = transformers.Trainer(
    model=model,
    train_dataset=data['train'],
    args=transformers.TrainingArguments(
        per_device_train_batch_size=4,
        gradient_accumulation_steps=4,
        warmup_steps=100,
        max_steps=200,
        learning_rate=2e-4,
        fp16=True,
        logging_steps=25,
        output_dir='outputs'
    ),
    data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False)
)
model.config.use_cache = False  # silence the warnings. Please re-enable for inference!
trainer.train()
```

Throws this error:



```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/transformers/utils/import_utils.py:1240, in _LazyModule._get_module(self, module_name)
   1239 try:
-> 1240     return importlib.import_module("." + module_name, self.__name__)
   1241 except Exception as e:

File ~/miniconda3/envs/pytorch/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:986, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:680, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:850, in exec_module(self, module)

File <frozen importlib._bootstrap>:228, in _call_with_frames_removed(f, *args, **kwds)

File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/transformers/trainer.py:52
     51 import torch.distributed as dist
---> 52 from huggingface_hub import Repository, create_repo, upload_folder
     53 from packaging import version

File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/huggingface_hub/__init__.py:332, in __getattr__(name)
    330         pkg.__dict__[name] = attr
--> 332     return attr
    333 else:

File ~/miniconda3/envs/pytorch/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/huggingface_hub/repository.py:25
     17 from .utils import (
     18     HfFolder,
     19     SoftTemporaryDirectory,
   (...)
     23     validate_hf_hub_args,
     24 )
---> 25 from .utils._typing import TypedDict
     28 logger = logging.get_logger(__name__)

ImportError: cannot import name 'TypedDict' from 'huggingface_hub.utils._typing' (/home/demouser/miniconda3/envs/pytorch/lib/python3.9/site-packages/huggingface_hub/utils/_typing.py)

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[7], line 6
      3 data = load_dataset("Abirate/english_quotes")
      4 data = data.map(lambda samples: tokenizer(samples['quote']), batched=True)
----> 6 trainer = transformers.Trainer(
      7     model=model,
      8     train_dataset=data['train'],
      9     args=transformers.TrainingArguments(
     10         per_device_train_batch_size=4,
     11         gradient_accumulation_steps=4,
     12         warmup_steps=100,
     13         max_steps=200,
     14         learning_rate=2e-4,
     15         fp16=True,
     16         logging_steps=25,
     17         output_dir='outputs'
     18     ),
     19     data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False)
     20 )
     21 model.config.use_cache = False  # silence the warnings. Please re-enable for inference!
     22 trainer.train()

File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/transformers/utils/import_utils.py:1230, in _LazyModule.__getattr__(self, name)
   1228     value = self._get_module(name)
   1229 elif name in self._class_to_module.keys():
-> 1230     module = self._get_module(self._class_to_module[name])
   1231     value = getattr(module, name)
   1232 else:

File ~/miniconda3/envs/pytorch/lib/python3.9/site-packages/transformers/utils/import_utils.py:1242, in _LazyModule._get_module(self, module_name)
   1240     return importlib.import_module("." + module_name, self.__name__)
   1241 except Exception as e:
-> 1242     raise RuntimeError(
   1243         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1244         f" traceback):\n{e}"
   1245     ) from e

RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
cannot import name 'TypedDict' from 'huggingface_hub.utils._typing' (/home/demouser/miniconda3/envs/pytorch/lib/python3.9/site-packages/huggingface_hub/utils/_typing.py)

```

notebook code is located here, using the same notebook:

https://github.com/ashishpatel26/LLM-Finetuning/blob/main/5.Finetune_Meta_OPT-6-1b_Model_bnb_peft.ipynb 



I have tried to downgrade the transformers version but that causes other dependency errors further up.


Thanks so much for any help!

Dave





### Who can help?

_No response_

### Information

- [ ] 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

After running the notebook and several other notebooks, this mixture of libraries and functions causes the trainer to fail.

I have run many public domain notebooks, so, it's safe to assume the versions of many libraries are mixed up and potentially not compatible.

### Expected behavior

It has worked in the past but I'm trying to get the right version or compatible mixture, does anyone know which version mix this would work best on?

Comments:
having same issue did you find the solution???

Hello both! Please try upgrading the `huggingface_hub` library and let us know if this fixes your issue?

You can do so with the following command:
```
pip install -U huggingface_hub
```

If not, please share the contents of your environment by doing `transformers-cli env` and pasting the results here. Thank you both! 

Upgrading `huggingface_hub` package works for me.

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.

Upgrading huggingface_hub package works for me TOO!!!

Upgrading huggingface_hub didn't work for me at all. Even tried deleting and installing again, still didn't work

Upgrading huggingface_hub didn't solved, but pip install --upgrade transformers did