Views
No views yet
Qwen/Qwen3-1.7B model, fine-tuned on the GSM8K dataset using Supervised Fine-Tuning (SFT) and Group Relative Policy Optimization (GRPO) reinforcement learning.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5base_model_id = "Qwen/Qwen3-1.7B"
6adapter_id = "ehzawad/qwen3-1.7b-gsm8k-grpo"
7
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.bfloat16,
12)
13
14base_model = AutoModelForCausalLM.from_pretrained(
15 base_model_id,
16 quantization_config=bnb_config,
17 device_map="auto",
18)
19
20tokenizer = AutoTokenizer.from_pretrained(adapter_id)
21hf_model = PeftModel.from_pretrained(base_model, adapter_id, is_trainable=False)
22hf_model.eval()
23
24prompt = "Janet has 3 bags with 4 apples each. She gives away 5 apples. How many remain?"
25system_prompt = (
26 "You are a careful math reasoning assistant. "
27 "Solve the problem step by step, but keep the solution concise. "
28 "End with exactly one final answer in the form \boxed{answer}."
29)
30messages = [
31 {"role": "system", "content": system_prompt},
32 {"role": "user", "content": prompt}
33]
34
35inputs = tokenizer.apply_chat_template(
36 messages,
37 tokenize=True,
38 add_generation_prompt=True,
39 return_tensors="pt",
40 return_dict=True
41).to(hf_model.device)
42
43with torch.inference_mode():
44 outputs = hf_model.generate(
45 **inputs,
46 max_new_tokens=512,
47 temperature=0.6,
48 do_sample=True,
49 )
50
51response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
52print(response)