Views
No views yet
Qwen/Qwen2.5-0.5Bmlabonne/orpo-dpo-mix-40k.HuggingFaceH4/ultrachat_200k.open-r1/Mixture-of-Thoughts dataset with step-by-step reasoning traces.mlabonne/orpo-dpo-mix-40k.messages and passed through the model's native chat_template
via tokenizer.apply_chat_template:1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3repo_id = "PursuitOfDataScience/qwen2.5-0.5b-r1-dpo"
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
43# Decode only the generated continuation (excluding the prompt tokens)
44generated_tokens = outputs[0][inputs["input_ids"].shape[1]:]
45response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
46print(response)1messages = [
2 {
3 "role": "system",
4 "content": (
5 "You are a helpful, concise assistant. "
6 "Write clear, well-structured answers that follow the user's constraints."
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": "Small models are cheaper and faster, while large models are usually more capable...",
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)<think> tags:1messages = [
2 {
3 "role": "system",
4 "content": (
5 "You are a helpful, concise assistant. "
6 "Use Chain of Thought reasoning with <think> tags for complex problems."
7 ),
8 },
9 {
10 "role": "user",
11 "content": "If a train travels 60 km in 1 hour, how long will it take to travel 180 km?",
12 },
13]
14
15prompt_text = tokenizer.apply_chat_template(
16 messages,
17 tokenize=False,
18 add_generation_prompt=True,
19)
20
21inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
22outputs = model.generate(
23 **inputs,
24 max_new_tokens=512,
25 eos_token_id=tokenizer.eos_token_id,
26 pad_token_id=tokenizer.eos_token_id,
27 temperature=0.7,
28 top_p=0.9,
29 do_sample=True,
30)
31response = tokenizer.decode(
32 outputs[0][inputs["input_ids"].shape[1]:],
33 skip_special_tokens=True,
34)
35print(response)
36# Example output: <think> The train travels 60 km in 1 hour, so speed is 60 km/h. For 180 km, time = distance / speed = 180 / 60 = 3 hours. </think> It will take 3 hours.messages.tokenizer.apply_chat_template.open-r1/Mixture-of-Thoughts dataset with step-by-step reasoning traces to enhance CoT capabilities.DPOTrainer, with prompts and
chosen/rejected continuations derived from the pre-tokenized data.dpo.py script used in this project for full configuration
(batch sizing, max length, etc.).