Views
No views yet
uv pip install transformers>=5.6.0 auto-round1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "Intel/Hy-MT2-1.8B-int4-AutoRound"
5
6# Load tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
8
9# Load model
10model = AutoModelForCausalLM.from_pretrained(
11 model_path,
12 dtype=torch.bfloat16,
13 device_map="auto",
14 trust_remote_code=True,
15)
16
17model.eval()
18
19# Example inference
20prompt = "将以下文本翻译成英语,注意只需要输出翻译后的结果,不要额外解释:\n\n今天天气真好。"
21messages = [{"role": "user", "content": prompt}]
22inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
23
24with torch.no_grad():
25 outputs = model.generate(
26 **inputs,
27 max_new_tokens=4096,
28 )
29response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
30print(response)1vllm serve Intel/Hy-MT2-1.8B-int4-AutoRound \
2 --host localhost \
3 --trust-remote-code \
4 --dtype bfloat16auto-round --model_name tencent/Hy-MT2-1.8B --bits 4 --iters 200 --output_dir Hy-MT2-1.8B-int4-AutoRound@article{cheng2023optimize,
title={Optimize weight rounding via signed gradient descent for the quantization of llms},
author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi},
journal={arXiv preprint arXiv:2309.05516},
year={2023}
}