Views
No views yet
bitsandbytes and transformers as presented in the code snipet below.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4model_name = "deepseek-ai/DeepSeek-V2-Lite-Chat"
5bnb_config = BitsAndBytesConfig(
6 load_in_4bit=True,
7 bnb_4bit_quant_type="nf4", # NF4 for weight
8 bnb_4bit_use_double_quant=True,
9 bnb_4bit_compute_dtype=torch.bfloat16 # bnb supports bfloat16
10)
11
12bnb_model = AutoModelForCausalLM.from_pretrained(
13 model_name,
14 trust_remote_code=True,
15 torch_dtype=torch.bfloat16,
16 quantization_config=bnb_config
17)
18
19tokenizer = AutoTokenizer.from_pretrained( model_name, trust_remote_code=True)
20
21bnb_model.push_to_hub("slowfastai/DeepSeek-V2-Lite-Chat-bnb-4bit")
22tokenizer.push_to_hub("slowfastai/DeepSeek-V2-Lite-Chat-bnb-4bit")
23
24