Update README.md
Browse files
README.md
CHANGED
@@ -18,4 +18,39 @@ tags:
|
|
18 |
# Qwen2.5-1.5B-Instruct-CoT-Reflection
|
19 |
|
20 |
This model has been finetuned from the Qwen2.5-1.5B-Instruct Model. This model has been finetuned on data to produce step by step chain of thought responses with reflections.
|
21 |
-
This model was trained with unsloth with LoRA and 4 bit quantization.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Qwen2.5-1.5B-Instruct-CoT-Reflection
|
19 |
|
20 |
This model has been finetuned from the Qwen2.5-1.5B-Instruct Model. This model has been finetuned on data to produce step by step chain of thought responses with reflections.
|
21 |
+
This model was trained with unsloth with LoRA and 4 bit quantization.
|
22 |
+
|
23 |
+
# How to use?
|
24 |
+
|
25 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
26 |
+
|
27 |
+
model_name = "Qwen/Qwen2.5-1.5B-Instruct"
|
28 |
+
|
29 |
+
model = AutoModelForCausalLM.from_pretrained(
|
30 |
+
model_name,
|
31 |
+
torch_dtype="auto",
|
32 |
+
device_map="auto"
|
33 |
+
)
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
35 |
+
|
36 |
+
prompt = "Give me a short introduction to large language model."
|
37 |
+
messages = [
|
38 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
|
39 |
+
{"role": "user", "content": prompt}
|
40 |
+
]
|
41 |
+
text = tokenizer.apply_chat_template(
|
42 |
+
messages,
|
43 |
+
tokenize=False,
|
44 |
+
add_generation_prompt=True
|
45 |
+
)
|
46 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
47 |
+
|
48 |
+
generated_ids = model.generate(
|
49 |
+
**model_inputs,
|
50 |
+
max_new_tokens=512
|
51 |
+
)
|
52 |
+
generated_ids = [
|
53 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
54 |
+
]
|
55 |
+
|
56 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|