Views
No views yet

apply_chat_template to show you how to load the tokenizer and model and how to generate contents.1from transformers import AutoModelForCausalLM, AutoTokenizer
2device = "cuda" # the device to load the model onto
3
4model = AutoModelForCausalLM.from_pretrained(
5 "alibaba-pai/Qwen2-1.5B-Instruct-Refine",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("alibaba-pai/Qwen2-1.5B-Instruct-Refine")
10
11prompt = "Give me a short introduction to large language model."
12messages = [
13 {"role": "user", "content": prompt}
14]
15text = tokenizer.apply_chat_template(
16 messages,
17 tokenize=False,
18 add_generation_prompt=True
19)
20model_inputs = tokenizer([text], return_tensors="pt").to(device)
21
22generated_ids = model.generate(
23 model_inputs.input_ids,
24 max_new_tokens=2048,
25 eos_token_id=151645,
26)
27generated_ids = [
28 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
29]
30
31response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]| Model | Detail | Truthfulness |
|---|---|---|
| Qwen2-1.5B-Instruct | 50.00% | 50.00% |
| + Qwen2-1.5B-Instruct-Refine | 75.63% | 63.75% |
| + Qwen2-7B-Instruct-Refine | 76.56% | 62.19% |
| Qwen2-7B-Instruct | 50.00% | 50.00% |
| + Qwen2-1.5B-Instruct-Refine | 70.94% | 57.19% |
| + Qwen2-7B-Instruct-Refine | 74.69% | 58.44% |
@misc{data-augmentation-family,
title={Building a Family of Data Augmentation Models for Low-cost LLM Fine-tuning on the Cloud},
author={Yuanhao Yue and Chengyu Wang and Jun Huang and Peng Wang},
year={2024},
eprint={2412.04871},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2412.04871},
}