Views
No views yet
HuggingFaceH4/ultrachat_200k to improve dialogue quality and instruction following.open-r1/Mixture-of-Thoughts (a Mixture-of-Thoughts dataset) to encourage step-by-step reasoning.
"<think>\n") to teach the model to produce internal reasoning before a concise final answer.Qwen 2.5 0.5B (see base_model above)open-r1/Mixture-of-Thoughts. The model learns to place an explicit internal reasoning prefix and then continue the reply.HuggingFaceH4/ultrachat_200k.open-r1/Mixture-of-Thoughts.tokenizer.apply_chat_template to build prompts that match the training format (especially important for CoT prompts).1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3repo_id = "PursuitOfDataScience/qwen2.5-0.5b-open-r1-mot-cot-sft"
4
5tokenizer = AutoTokenizer.from_pretrained(repo_id)
6model = AutoModelForCausalLM.from_pretrained(
7 repo_id,
8 device_map="auto",
9)
10
11messages = [
12 {
13 "role": "system",
14 "content": (
15 "You are a helpful, concise assistant. "
16 "Write clear, well-structured answers that follow the user's constraints."
17 ),
18 },
19 {
20 "role": "user",
21 "content": "Explain how someone can build a consistent daily learning habit.",
22 },
23]
24
25prompt_text = tokenizer.apply_chat_template(
26 messages,
27 tokenize=False,
28 add_generation_prompt=True,
29)
30
31inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
32
33outputs = model.generate(
34 **inputs,
35 max_new_tokens=512,
36 eos_token_id=tokenizer.eos_token_id,
37 pad_token_id=tokenizer.eos_token_id,
38 temperature=0.7,
39 top_p=0.9,
40 do_sample=True,
41)
42
43generated_tokens = outputs[0][inputs["input_ids"].shape[1]:]
44response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
45print(response)1messages = [
2 {
3 "role": "system",
4 "content": (
5 "You are a thoughtful assistant. Provide step-by-step reasoning when relevant, "
6 "followed by a concise summary."
7 ),
8 },
9 {
10 "role": "user",
11 "content": "Explain how someone can build a consistent daily learning habit.",
12 },
13 # Add the CoT sentinel as an assistant prefix so the model continues with chain-of-thought.
14 {
15 "role": "assistant",
16 "content": "<think>\n",
17 },
18]
19
20prompt_text = tokenizer.apply_chat_template(
21 messages,
22 tokenize=False,
23 add_generation_prompt=True,
24)
25
26inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
27outputs = model.generate(
28 **inputs,
29 max_new_tokens=512,
30 eos_token_id=tokenizer.eos_token_id,
31 pad_token_id=tokenizer.eos_token_id,
32 temperature=0.7,
33 top_p=0.9,
34 do_sample=True,
35)
36
37generated_tokens = outputs[0][inputs["input_ids"].shape[1]:]
38response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
39print(response)1messages = [
2 {
3 "role": "system",
4 "content": (
5 "You are a thoughtful assistant with a preference for process-focused answers. "
6 "When helpful, show your chain-of-thought reasoning and finish with a short conclusion."
7 ),
8 },
9 {
10 "role": "user",
11 "content": "Describe the main trade-offs between using small and large language models.",
12 },
13 {
14 "role": "assistant",
15 "content": "<think>\n",
16 },
17 {
18 "role": "user",
19 "content": "Give me a bullet-point summary from the perspective of a startup.",
20 },
21]
22
23prompt_text = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True,
27)
28
29inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
30outputs = model.generate(
31 **inputs,
32 max_new_tokens=256,
33 eos_token_id=tokenizer.eos_token_id,
34 pad_token_id=tokenizer.eos_token_id,
35 temperature=0.7,
36 top_p=0.9,
37 do_sample=True,
38)
39response = tokenizer.decode(
40 outputs[0][inputs["input_ids"].shape[1]:],
41 skip_special_tokens=True,
42)
43print(response)tokenizer.apply_chat_template."<think>\n") so the model learns to produce internal reasoning followed by a concise answer.cot-finetuning.py for exact hyperparameters and training details.