Views
No views yet

qwen2.5-3b-claude-distilled-reasoning-dpo is a post-trained, reasoning-specialized 3.0B parameter causal language model.Qwen/Qwen2.5-3B-Instruct:DPOTrainer on preference pairs (argilla/ultrafeedback-binarized-preferences-cleaned). This step eliminates scientific hallucinations (e.g., density vs. thermal conductivity), suppresses infinite token repetition loops, and anchors physical explanations to first-principles facts.| Feature | Base Model (Qwen2.5-3B-Instruct) | SFT Stage (...-reasoning) | DPO Stage (...-reasoning-dpo) |
|---|---|---|---|
| Reasoning Engine | Static response generation | Claude CoT monologue traces | Refined CoT monologue traces |
| Physics/Math Accuracy | Standard textbook baseline | Prone to reasoning hallucinations | First-principles verified |
| Degeneracy / Loops | Standard EOS handling | Prone to trailing follow-up loops | Suppressed via preference rewards |
TextIteratorStreamer.1import os
2import sys
3from threading import Thread
4import torch
5import time
6from transformers import (
7 AutoTokenizer,
8 AutoModelForCausalLM,
9 TextIteratorStreamer,
10 StoppingCriteria,
11 StoppingCriteriaList
12)
13
14# =========================================================================
15# 1. CONFIGURATION & MODEL LOADING
16# =========================================================================
17REPO_ID = "Phase-Technologies/qwen2.5-3b-claude-distilled-reasoning-dpo"
18
19print(f"[*] Hardware Status: CUDA Available: {torch.cuda.is_available()}")
20
21tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
22model = AutoModelForCausalLM.from_pretrained(
23 REPO_ID,
24 torch_dtype=torch.float16,
25 device_map="auto",
26 attn_implementation="sdpa"
27)
28
29# =========================================================================
30# 2. ENHANCED INFERENCE ENGINE
31# =========================================================================
32def analyze_inference(prompt):
33 messages = [
34 {"role": "system", "content": "You are a reasoning assistant. Solve the problem step-by-step and provide a final answer in a box."},
35 {"role": "user", "content": prompt}
36 ]
37 formatted_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
38 inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
39
40 streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
41
42 # Increased repetition penalty to 1.3 to stop 'Implication:' loops
43 # Added stop_strings for common hallucination patterns
44 gen_kwargs = dict(
45 **inputs,
46 streamer=streamer,
47 max_new_tokens=400,
48 do_sample=True,
49 temperature=0.4,
50 top_p=0.9,
51 repetition_penalty=1.3,
52 stop_strings=["Implication:", "<|im_end|>", "###"],
53 tokenizer=tokenizer,
54 pad_token_id=tokenizer.eos_token_id
55 )
56
57 print(f"\n--- TESTING IMPROVED PARAMETERS ---")
58 start_time = time.time()
59 thread = Thread(target=model.generate, kwargs=gen_kwargs)
60 thread.start()
61
62 generated_text = ""
63 for new_text in streamer:
64 print(new_text, end="", flush=True)
65 generated_text += new_text
66
67 duration = time.time() - start_time
68 print(f"\n\n[Metric] Speed: {len(tokenizer.encode(generated_text))/duration:.2f} tokens/sec")
69
70analyze_inference("Sally has 3 brothers. Each of her brothers has 2 sisters. How many sisters does Sally have?")Qwen2.5 architecture)bfloat16 / float16Qwen/Qwen2.5-3B-Instruct)argilla/ultrafeedback-binarized-preferences-cleaned)TRL (DPOTrainer), PEFT, and Transformers.