Model.save_pretrained is not saving .bin files! model.push_to_hub is not pushing my model in my HuggingFace directory! What am I missing? Help

Hello everyone,

I am trying to save my model after fine tuning and I would like to get a .bin file. Unfortunately, even using this command:

trainer.model.save_pretrained(save_directory = “path/to/directory/trained”)

base_model = AutoModelForCausalLM.from_pretrained(
model_name,
low_cpu_mem_usage=True,
return_dict=True,
torch_dtype=torch.float16,
device_map=device_map,
)
model = PeftModel.from_pretrained(base_model, new_model)
model = model.merge_and_unload()
model.save_pretrained(save_directory = “path/to/directory/merged”)

it gives me back .json and .safetensors files:

image

Finally, when I try to push the model in my HF directory, using the following command:

model.push_to_hub(“TeoR95/my_project_dir”, use_temp_dir=False)
tokenizer.push_to_hub(“TeoR95/my_project_dir/”, use_temp_dir=False)

it returns this error:

return {f: os.path.getmtime(os.path.join(working_dir, f)) for f in os.listdir(working_dir)}
FileNotFoundError: [Errno 2] No such file or directory: ‘my_project_dir’

Obviously, I did the login in HF at the beginning of the script with:

from huggingface_hub import login
login(“my_token”)

What am I missing? Can you help me please? Any suggestion would be super appreciated!

Thank you so much in advance! :slight_smile:

Anyone? :frowning:

Have you tried trainer.push_to_hub() ?

set safe_serialization=False when you save your model

model.save_pretrained(save_directory = “path/to/directory/merged”, safe_serialization=False)

1 Like

Thank you for your reply!
As soon as I test it, I will let you know if it works :slight_smile:

Thank you for your reply!
Yes, but it again does not give me back a .bin file :frowning:

that’s weird, is it possible to send your code in Google Colab?

I encountered a similar issue and resolved it by downgrading the Transformer library to version 4.16.2.

1 Like

Hello everyone,

Thank you so much for your kind replies. I am sorry if I could not reply faster, but I tried to login in “discuss.huggingface” many times, but it did not allow me for several days (I still do not know the reason).
Anyway, I found out that FastChat (the reason why I tried to have the .bin) can accept also the file types you can see in the image of my first post.
In any case, @Mit1208 and @mufseera answers could be the solution to the issue and I will give it a try for sure.

For now, I thank you all from the bottom of my heart for your support! :smiley:

@TeoR95 no problem. As I mentioned just one argument is required, I showed in colab for your reference.

You can see output in below image:

colab: Google Colab

hey wokring this note boook

also getting same issues its has been week im stuck .
here is another repo that are push but image are not good to genrate .

1 Like