Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5base_model_id = "unsloth/Llama-3.2-1B-Instruct-bnb-4bit"
6adapter_id = "thuanan/Llama-3.2-1B-Instruct-mathqa-lora"
7
8tokenizer = AutoTokenizer.from_pretrained(adapter_id)
9base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.bfloat16)
10model = PeftModel.from_pretrained(base_model, adapter_id)
11model.eval()
12
13messages = [
14 {
15 "role": "system",
16 "content": "You are a helpful math tutor. Solve the problem with clear reasoning and end with a concise final answer.",
17 },
18 {"role": "user", "content": "Solve: 2x + 5 = 17"},
19]
20
21prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
22inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
23
24with torch.inference_mode():
25 output = model.generate(
26 **inputs,
27 max_new_tokens=256,
28 do_sample=True,
29 temperature=0.2,
30 top_p=0.9,
31 repetition_penalty=1.1,
32 )
33
34generated = output[0][inputs["input_ids"].shape[1]:]
35print(tokenizer.decode(generated, skip_special_tokens=True))1@misc{aio_llmops_mathqa_lora_2026,
2 title={Llama-3.2-1B-Instruct-mathqa-lora},
3 author={ThuanNaN and contributors},
4 year={2026},
5 howpublished={\url{https://huggingface.co/thuanan/Llama-3.2-1B-Instruct-mathqa-lora}}
6}