Views
No views yet
<think> and </think> tags.1# Key training parameters
2model_name_or_path: meta-llama/Llama-3.1-8B-Instruct
3dataset_name: open-r1/Mixture-of-Thoughts
4dataset_config: all
5learning_rate: 4.0e-05
6num_train_epochs: 5
7max_length: 32768
8per_device_train_batch_size: 2
9gradient_accumulation_steps: 8
10bf16: true
11gradient_checkpointing: true
12use_liger_kernel: true1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_name = "your-username/Llama-3.1-8B-R1-Distill"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10 attn_implementation="flash_attention_2"
11)
12
13# Example: Mathematical reasoning
14prompt = """Solve this step by step: A rectangle has a length that is 3 times its width. If the perimeter is 32 units, what are the dimensions?"""
15
16inputs = tokenizer(prompt, return_tensors="pt")
17outputs = model.generate(
18 **inputs,
19 max_new_tokens=500,
20 temperature=0.1,
21 do_sample=True,
22 pad_token_id=tokenizer.eos_token_id
23)
24response = tokenizer.decode(outputs[0], skip_special_tokens=True)
25print(response)<think> tags:1def format_reasoning_prompt(question, system_prompt=None):
2 if system_prompt is None:
3 system_prompt = "You are a helpful assistant that thinks step by step. Show your reasoning process within <think> tags before providing your final answer."
4
5 return f"""<|start_header_id|>system<|end_header_id|>
6
7{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>
8
9{question}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
10
11<think>
12"""
13
14# Example for coding problems
15coding_prompt = format_reasoning_prompt(
16 "Write a Python function to find the longest palindromic substring in a given string.",
17 "You are an expert programmer. Think through the problem step by step, consider different approaches, and then provide a clean implementation."
18)
19
20inputs = tokenizer(coding_prompt, return_tensors="pt")
21outputs = model.generate(**inputs, max_new_tokens=800, temperature=0.1)
22response = tokenizer.decode(outputs[0], skip_special_tokens=True)
23print(response)1@misc{llama31-r1-distill,
2 title={Llama-3.1-8B-R1-Distill: A Step-by-Step Reasoning Model},
3 author={[Your Name]},
4 year={2025},
5 url={https://huggingface.co/your-username/Llama-3.1-8B-R1-Distill}
6}
7
8@misc{openr1,
9 title={Open R1: A fully open reproduction of DeepSeek-R1},
10 url={https://github.com/huggingface/open-r1},
11 author={Hugging Face},
12 month={January},
13 year={2025}
14}
15
16@misc{mixture-of-thoughts,
17 title={Mixture-of-Thoughts},
18 author={Hugging Face Open R1 Team},
19 year={2025},
20 url={https://huggingface.co/datasets/open-r1/Mixture-of-Thoughts}
21}