save quantized model throws error.
Author: nemesis00sam
Pull request: no

### System Info

===================================BUG REPORT===================================
Welcome to bitsandbytes. For bug reports, please run

python -m bitsandbytes


================================================================================
bin /opt/conda/envs/pytorch/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda118.so
CUDA SETUP: CUDA runtime path found: /opt/conda/envs/pytorch/lib/libcudart.so.11.0
CUDA SETUP: Highest compute capability among GPUs detected: 7.5
CUDA SETUP: Detected CUDA version 118
CUDA SETUP: Loading binary /opt/conda/envs/pytorch/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda118.so...
[2023-07-12 13:52:54,626] [INFO] [real_accelerator.py:110:get_accelerator] Setting ds_accelerator to cuda (auto detect)

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

- `transformers` version: 4.30.2
- Platform: Linux-5.15.0-1038-aws-x86_64-with-glibc2.31
- Python version: 3.10.12
- Huggingface_hub version: 0.16.2
- Safetensors version: 0.3.1
- PyTorch version (GPU?): 2.0.1 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

_No response_

### 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

Hi,

I'm trying to save quantized model. First attempt didn't work. (I also opened an issue, https://github.com/huggingface/accelerate/issues/1713,  to clarify it). 

I opened this issue because I'm receiving an error message when I run following code. I'm not sure I'm following the right instructions written on https://huggingface.co/docs/transformers/main_classes/quantization. Because model is pushed to hub in documentation. But I expect to save it to local filesystem. Thanks for your help in advance. 

```
### load packages ###
import transformers
import textwrap
from transformers import LlamaTokenizer, LlamaForCausalLM
import os
import sys
from typing import List
import accelerate
 
from peft import (
    LoraConfig,
    get_peft_model,
    get_peft_model_state_dict,
    prepare_model_for_int8_training,
)
 
#import fire
import torch
from datasets import load_dataset
import pandas as pd
import deepspeed

DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
DEVICE

### load model ###
BASE_MODEL = "decapoda-research/llama-7b-hf"
 
model = LlamaForCausalLM.from_pretrained(
    BASE_MODEL,
    load_in_8bit=True,
    torch_dtype=torch.float16,
    device_map="auto",
)
 
model.save_pretrained(save_directory="quantized_decapoda-research_llama-7b-hf_v2")

```

Error Message:
```
/opt/conda/envs/pytorch/lib/python3.10/site-packages/transformers/modeling_utils.py:1709: UserWarning: You are calling `save_pretrained` to a 8-bit converted model you may likely encounter unexepected behaviors. If you want to save 8-bit models, make sure to have `bitsandbytes>0.37.2` installed.
  warnings.warn(
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 model.save_pretrained(save_directory="quantized_decapoda-research_llama-7b-hf_v2")

File /opt/conda/envs/pytorch/lib/python3.10/site-packages/transformers/modeling_utils.py:1820, in PreTrainedModel.save_pretrained(self, save_directory, is_main_process, state_dict, save_function, push_to_hub, max_shard_size, safe_serialization, variant, **kwargs)
   1817 weights_name = SAFE_WEIGHTS_NAME if safe_serialization else WEIGHTS_NAME
   1818 weights_name = _add_variant(weights_name, variant)
-> 1820 shards, index = shard_checkpoint(state_dict, max_shard_size=max_shard_size, weights_name=weights_name)
   1822 # Clean the folder from a previous save
   1823 for filename in os.listdir(save_directory):

File /opt/conda/envs/pytorch/lib/python3.10/site-packages/transformers/modeling_utils.py:318, in shard_checkpoint(state_dict, max_shard_size, weights_name)
    315 storage_id_to_block = {}
    317 for key, weight in state_dict.items():
--> 318     storage_id = id_tensor_storage(weight)
    320     # If a `weight` shares the same underlying storage as another tensor, we put `weight` in the same `block`
    321     if storage_id in storage_id_to_block:

File /opt/conda/envs/pytorch/lib/python3.10/site-packages/transformers/pytorch_utils.py:290, in id_tensor_storage(tensor)
    283 def id_tensor_storage(tensor: torch.Tensor) -> Tuple[torch.device, int, int]:
    284     """
    285     Unique identifier to a tensor storage. Multiple different tensors can share the same underlying storage. For
    286     example, "meta" tensors all share the same storage, and thus their identifier will all be equal. This identifier is
    287     guaranteed to be unique and constant for this tensor's storage during its lifetime. Two tensor storages with
    288     non-overlapping lifetimes may have the same id.
    289     """
--> 290     return tensor.device, storage_ptr(tensor), storage_size(tensor)

AttributeError: 'str' object has no attribute 'device'
```

### Expected behavior

Save quantized model to local filesystem.

Comments:
`load_in_8bit=True,` --> cc @younesbelkada as he knows much better 🙏 

Hi @nemesis00sam 
Thanks for the issue, https://github.com/huggingface/transformers/pull/24416 fixed the issue you mentioned
please install transformers from source 
```
pip uninstall transformers
pip install git+https://github.com/huggingface/transformers.git
```
And it should be solved right after

Thanks for prompt answer. @younesbelkada 

I still see the same issue while saving `meta-llama/Llama-2-13b-chat-hf` as safetensors

My setup:
```
pip list | grep -E 'trans|accel|bits|safe'
accelerate                               0.21.0
bitsandbytes                             0.41.0
safetensors                              0.3.1
transformers                             4.32.0.dev0 # uninstalled and installed from git on 7/28
```

Script:
```
model_name = "meta-llama/Llama-2-13b-chat-hf"
save_dir = "/home/abc/local_models/Llama-2-13b-chat-8bit"
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer.save_pretrained(save_dir, save_config=True)
max_memory = {0: "22GIB", 1: "22GIB", 2: "22GIB", 3: "22GIB", 4: "22GIB", 5: "22GIB", 6: "22GIB", 7: "22GIB"}
model = AutoModelForCausalLM.from_pretrained(model_name, load_in_8bit=True, max_memory=max_memory)
model.save_pretrained(save_dir, save_config=True, safe_serialization=True)
```

Error:
```
Traceback (most recent call last):
  File "/home/hmohapa/search/llama/8bit_quantize.py", line 26, in <module>
    model.save_pretrained(save_dir, save_config=True, safe_serialization=True)
  File "/opt/conda/lib/python3.10/site-packages/transformers/modeling_utils.py", line 1803, in save_pretrained
    ptrs[id_tensor_storage(tensor)].append(name)
  File "/opt/conda/lib/python3.10/site-packages/transformers/pytorch_utils.py", line 287, in id_tensor_storage
    return tensor.device, storage_ptr(tensor), storage_size(tensor)
AttributeError: 'str' object has no attribute 'device'
```

i had the same issue with `transformers==4.30.2`. it's gone with `transformers==4.31.0`. 

@hrushikesh198 for safetensors there is indeed a bug, would be happy opening a new ticket for that?

I'm still getting the message in transformers 4.33.3 and bitsandbytes==0.41.0
Not using 4.34.0 yet, because it runs into a different bug that causes a crash.

I'ts not safetransfomers, I'm just using a pytorch bin file

```
home/coen/.local/lib/python3.10/site-packages/transformers/modeling_utils.py:1830: UserWarning: You are calling `save_pretrained` to a 8-bit converted model you may likely encounter unexepected behaviors. If you want to save 8-bit models, make sure to have `bitsandbytes>0.37.2` installed.
  warnings.warn(
```

@coen22 can you open a new ticket with a clean reproducer and tag me?

!pip install -q -U trl transformers accelerate git+https://github.com/huggingface/peft.git
!pip install -q datasets bitsandbytes einops
!pip install -q -U torch==2.0.1 bitsandbytes==0.40.2
works with this combination of versions


ERROTR：You are calling `save_pretrained` to a 8-bit converted model you may likely encounter unexepected behaviors. If you want to save 8-bit models, make sure to have `bitsandbytes 0.37.2     

config：
bitsandbytes-0.45.4
torch2.4.1-cuda121
transformers =4.31.0

Question：How can I solve the trouble I’m facing?

@Wyf-String It would be better to open an new issue with a code snippet.