File size: 694 Bytes
480f3c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda:0"
tokenizer = AutoTokenizer.from_pretrained("glm-4-voice-9b", trust_remote_code=True)
tokenizer.chat_template = "{{role}}: {{content}}"
query = "你好"
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
return_dict=True
)
inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
"glm-4-voice-9b",
low_cpu_mem_usage=True,
trust_remote_code=True,
load_in_8bit=True
).eval()
model.save_pretrained("glm-4-voice-9b-int8")
tokenizer.save_pretrained("glm-4-voice-9b-int8") |