Views
No views yet
pip install transformers peft torch1from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
2from peft import PeftModel
3import torch
4
5model_id = "SkyAsl/Qwen3-olympiad-math-thinking-2507"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8
9base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-4B-Thinking-2507")
10model = PeftModel.from_pretrained(base_model, model_id)
11
12prompt = ""
13
14input_text = (
15 f"<|user|>\n{prompt}\n"
16 f"<|assistant|>\n<think>\n"
17)
18
19inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
20
21streamer = TextStreamer(tokenizer, skip_prompt=True)
22
23with torch.no_grad():
24 output = model.generate(
25 **inputs,
26 max_new_tokens=3000, # Recommended to keep max_new_tokens high because of the long CoT.
27 temperature=0.7,
28 top_p=0.9,
29 do_sample=True,
30 repetition_penalty=1.2,
31 streamer=streamer
32 )
33
34print(tokenizer.decode(output[0], skip_special_tokens=False))<|user|>
{prompt}
<|assistant|>
<think>
{solution}
</think>
{response}| Setting | Value |
|---|---|
| Method | LoRA (PEFT) |
| Rank (r) | 16 |
| Alpha | 32 |
| LoraDropout | 0.05 |
| Max Length | 4096 |
| Batch Size | 4 |
| Grad Accum | 8 |
| LR | 2e-4 |
| Optimizer | adamw_torch_fused |
| Scheduler | cosine |
| Epochs | 2 |
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 0.870800 | 0.886106 |
| 2 | 0.844400 | 0.871447 |