Skip to content

Instantly share code, notes, and snippets.

@younesbelkada
Created December 25, 2023 18:10
Show Gist options
  • Save younesbelkada/89fd3984a2992fdbb408fa8e3bf44101 to your computer and use it in GitHub Desktop.
Save younesbelkada/89fd3984a2992fdbb408fa8e3bf44101 to your computer and use it in GitHub Desktop.
push bnb 4 bit models on the hub
# pip install -U bitsandbytes
# pip install -U git+https://github.com/huggingface/transformers.git
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
path_to_hub = XXX
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
model.push_to_hub(path_to_hub)
tokenizer.push_to_hub(path_to_hub)
@SharathHebbar
Copy link

What version of transformers are you using?
I tried to push lite llama 4bit but throwing the same error as 4bit models cannot be pushed to hub

@SharathHebbar
Copy link

image

@allennghayoui
Copy link

I ran into this problem then fixed it by running these (running colab nb):

!pip install git+https://github.com/huggingface/transformers.git -q -U # transformers version:  4.37.0
!pip install git+https://github.com/huggingface/accelerate.git -q -U # accelerate version:  0.27.0
!pip install bitsandbytes # bitsandbytes version:  0.42.0
!pip install git+https://github.com/huggingface/peft.git -q -U # peft version: 0.7.2

hope this helps

@SharathHebbar
Copy link

Hey Thanks a lot it worked

@SharathHebbar
Copy link

Facing this issue
RuntimeError: Error(s) in loading state_dict for LlamaForCausalLM:
size mismatch for model.layers.0.mlp.gate_proj.weight: copying a param with shape torch.Size([2097152, 1]) from checkpoint, the shape in current model is torch.Size([4096, 1024]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment