Unhashable dict error
Author: erlebach
Pull request: no

### System Info

I am running on Mac M2 with Ventura, using a Poetry environment. Here is the Pyproject.toml file: 
```
[tool.poetry]
name = "UROP Project"
version = "0.0.1"
description = "LangChain mono-repo"
authors = []
license = "MIT"
readme = "README.md"
repository = "https://github.com/fsu-sc/UROP_2023-2024.git"

#    pickle
#    transformers
#    collections
#    matplotlib

[tool.poetry.dependencies]
python = ">=3.9,<4.0"

python-dotenv = "^1.0.0"
google-search-results = "^2.4.2"
matplotlib = "^3.8.0"
torch = "^2.0.1"
langchain = "^0.0.300"
transformers = "^4.34.1"
jupyterlab = "^4.0.7"
einops = "^0.7.0"
```
Here is my code (I am using Jupyter-lab): 
```
from langchain.prompts import ChatPromptTemplate
import torch
import pickle
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
from collections import defaultdict

model_name = "microsoft/phi-1_5"
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
device = "mps" if torch.backends.mps.is_available() else "cpu"
# device = "mps"
device = "cpu"
print(device)
model.to(device)
```
which is fine. The error occurs in the next cell: 
```
generation_config, unused_kwargs = GenerationConfig.from_pretrained(
    model_name,
    top_k=100,
    top_p=1.0,
    temperature=1.0,
    max_new_tokens=2,
    num_return_sequences=1,
    do_sample=True,
    return_unused_kwargs=True,
)
```
Here is the stack trace: 
```
Traceback (most recent call last):
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/var/folders/g_/_bggj09s1z183t3_j5jy1r9c0000gn/T/ipykernel_76724/2282397824.py", line 1, in <module>
    generation_config, unused_kwargs = GenerationConfig.from_pretrained(
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/transformers/generation/configuration_utils.py", line 735, in from_pretrained
TypeError: unhashable type: 'dict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2120, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1326, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1173, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1088, in format_exception_as_a_whole
    frames.append(self.format_record(record))
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 970, in format_record
    frame_info.lines, Colors, self.has_colors, lvals
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/IPython/core/ultratb.py", line 792, in lines
    return self._sd.lines
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/core.py", line 734, in lines
    pieces = self.included_pieces
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/core.py", line 681, in included_pieces
    pos = scope_pieces.index(self.executing_piece)
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/stack_data/core.py", line 660, in executing_piece
    return only(
  File "/Users/erlebach/src/2023/UROP_2023-2024/.venv/lib/python3.10/site-packages/executing/executing.py", line 116, in only
    raise NotOneValueFound('Expected one value, found 0')
executing.executing.NotOneValueFound: Expected one value, found: " 0
```

Looking at the file where the error occurs: `transformers/generation/configuration_utils.py`, I find the lines:
```
727         if is_local:
728             logger.info(f"loading configuration file {resolved_config_file}")
729         else:
730             logger.info(f"loading configuration file {configuration_file} from cache at {resolved_config_file}")
731
732         config = cls.from_dict(config_dict, **kwargs)
733         config._original_object_hash = hash(config)  # Hash to detect whether the instance was modified
734         return config
```
The error occurs on line 733. I printed the type of config, it was  a non-hashable type. More specifically, type: 
```
type(config_dict):  <class 'dict'>
type(config):  <class 'tuple'>
type(config):  <class 'tuple'>
config:  (GenerationConfig {
  "do_sample": true,
  "max_new_tokens": 2,
  "top_k": 100
}
, {})
```
Clearly, `config` isunhashable due to `GenerationConfig`

Any insight would be greatly appreciated. Thanks.




### Who can help?

_No response_

### 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

See above.

### Expected behavior

See above.

Comments:
cc @gante I can reproduce this with:
```python 
>>> from tranformers import GenerationConfig
>>> generation_config, unused_kwargs = GenerationConfig.from_pretrained(
    "microsoft/phi-1_5",
    top_k=100,
    top_p=1.0,
    temperature=1.0,
    max_new_tokens=2,
    num_return_sequences=1,
    do_sample=True,
    return_unused_kwargs=True,
)
```
Note that this model is not (yet) part of transformers so that could explain why the config is a dict. Trust remote code probably not supported for generation mixin. 

Thanks you, @ArthurZucker .  The toml file works on a friend's M1 mac (mine is M2). That is what is so confusing to me!
Is there an easy way to find the models actually supported by `transformers`? It is obviously a subset of the models listed on HuggingFace. 

Not it's not obviously a sub-set, this is probably a versioning issue. Usually it's more like some models on the hub don't support transformers anymore because they are not maintained. For now I would recommend you to just pass the generation arguments to the generate call or init the generation config instead of using the generationConfig from pretrained, specifically because this model's generation config is pretty much empty

My current codebase relies on loading the `generation_config` from `GenerationConfig.from_pretrained`, and currently I resorted to downgrading the library to a previous version (v4.33.2) where hashing was not present.
Any idea on how to resolve this issue?

Phi was recently merged, and this seems to have been fixed on main. I'll close this as completed. @zaemyung you are not providing a reproducer, can't really help you but feel free to open a new issue with a reproducer. 🤗 

Hello,
I am also having this issue with:
```
from transformers import GenerationConfig
generation_kwargs = {
    "top_k": 0.0,
    "top_p": 1.0,
    "do_sample": True,
    "pad_token_id": "test",
    "eos_token_id": "test",
    "return_unused_kwargs": True
}
GenerationConfig.from_pretrained("meta-llama/Llama-2-7b-chat-hf", **generation_kwargs)

```
I get this stack trace:

```
TypeError                                 Traceback (most recent call last)
Cell In[19], line 10
      1 from transformers import GenerationConfig
      2 generation_kwargs = {
      3     "top_k": 0.0,
      4     "top_p": 1.0,
   (...)
      8     "return_unused_kwargs": True
      9 }
---> 10 GenerationConfig.from_pretrained("meta-llama/Llama-2-7b-chat-hf", **generation_kwargs)

File ~/.virtualenvs/llm/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:754, in GenerationConfig.from_pretrained(cls, pretrained_model_name, config_file_name, cache_dir, force_download, local_files_only, token, revision, **kwargs)
    751     logger.info(f"loading configuration file {configuration_file} from cache at {resolved_config_file}")
    753 config = cls.from_dict(config_dict, **kwargs)
--> 754 config._original_object_hash = hash(config)  # Hash to detect whether the instance was modified
    755 return config

TypeError: unhashable type: 'dict'
```

I am using the most recent transformers version 4.35.2.
Cheers!

Was fixed on main 😉