Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from transformers import BitsAndBytesConfig
3import torch
4
5# Define the 4-bit configuration
6nf4_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_quant_type="nf4",
9 bnb_4bit_use_double_quant=True,
10 bnb_4bit_compute_dtype=torch.bfloat16
11)
12
13# Load the pre-trained model with the 4-bit quantization configuration
14model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-8b-code-instruct-4k", quantization_config=nf4_config)
15
16# Load the tokenizer associated with the model
17tokenizer = AutoTokenizer.from_pretrained("ibm-granite/granite-8b-code-instruct-4k")
18
19# Push the model and tokenizer to the Hugging Face hub
20model.push_to_hub("onekq-ai/granite-8b-code-instruct-4k-bnb-4bit", use_auth_token=True)
21tokenizer.push_to_hub("onekq-ai/granite-8b-code-instruct-4k-bnb-4bit", use_auth_token=True)