Why does Hugging Face's push_to_hub convert saved models to .bin instead of using safetensor mode?
Author: okoliechykwuka
Pull request: no

I am attempting to push a saved model in `model-00001-of-00006.safetensors `mode, but the model gets converted to `pytorch_model-00001-of-00006.bin` before being saved to the hub.

How can I prevent this?

Here is what I am simply doing:

```
model.push_to_hub(new_model, use_temp_dir=False)
tokenizer.push_to_hub(new_model, use_temp_dir=False)
```

![pushing to hub](https://github.com/huggingface/huggingface_hub/assets/51082506/10e078d8-98ad-4277-a478-5fb49329be6e)




Comments:
Hi @okoliechykwuka , I'll transfer the question to the `transformers` repository as it's more related to the implementation there (and not the underlying `huggingface_hub` which is only responsible of uploading a file, not generating it). Also to help `transformers`'s maintainers, which version of `transformers` / `tokenizers` are you using?

Hi, could you provide a self-contained code snippet that demonstrate this issue, please?

I believe this is because `safe_serialization` is set to `False` by default. 

Putting it to `True` by default would mean that any model saved in a current model of `transformers` would be incompatible with past versions of `transformers` that didn't have `safetensors` installed by default. We have added `safetensors` as a core dependency in v4.30.0.

We're thinking that moving towards default `safetensors` serialization could be done in ~v4.35.0, so in about two months.

cc @Narsil 

@Wauplin I am using the latest version of the transformer library.

@ydshieh I have provided the code snippet below for inspection. Thanks

transformer == 4.33.0



`!pip install -q -U transformers peft accelerate optimum
`

```
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "model_name"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
new_model = "llama-2-13b-chat"
model.save_pretrained(new_model, safe_serialization=True)
tokenizer.save_pretrained(new_model)
model.push_to_hub(new_model, use_temp_dir=False)
tokenizer.push_to_hub(new_model, use_temp_dir=False)
```



Hosting my model `runpod` using a text generation endpoint is giving me the below error. It shows that I am supposed to have my model weights in safetensor format. but I am surprised that pushing to the hub doesn't push the models in the directory in safetensor format even though that is the format the model was saved.

```safetensors_rust.safetensorerror: error while serializing: ioerror(os { code: 122, kind: filesystemquotaexceeded, message: "disk quota exceeded" })```

Hey @okoliechykwuka, the `push_to_hub` method should call its own serialization method under the hood.

Could you try this change in your code?

```diff
- model.push_to_hub(new_model, use_temp_dir=False)
+ model.push_to_hub(new_model, use_temp_dir=False, safe_serialization=True)
```

This should push the checkpoints in `safetensors` format.

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.

what if I just want to save the files into a folder without pushing to Hugging Face Hub?

@work-peng you can use `.save_pretrained()` and provide a folder path