Views
No views yet
unsloth/Llama-3.2-3B-Instructunsloth library for 2x faster inference. We recommend a low temperature (0.1) for mathematical stability.1from unsloth import FastLanguageModel
2import torch
3
4# 1. Load Model and Tokenizer
5model, tokenizer = FastLanguageModel.from_pretrained(
6 "Khurram123/Llama-3.2-3B-Calculus-v2",
7 max_seq_length = 2048,
8 load_in_4bit = True,
9)
10FastLanguageModel.for_inference(model)
11
12# 2. Define Calculus Problem
13problem = "Find the derivative of f(x) = x^2 * ln(x) step by step."
14
15# 3. Apply Llama 3.2 Instruct Template
16messages = [{"role": "user", "content": problem}]
17inputs = tokenizer.apply_chat_template(
18 messages,
19 add_generation_prompt = True,
20 return_tensors = "pt"
21).to("cuda")
22
23# 4. Generate Solution
24outputs = model.generate(
25 input_ids = inputs,
26 max_new_tokens = 1024,
27 temperature = 0.1
28)
29
30# 5. Decode Output
31response = tokenizer.decode(outputs[0], skip_special_tokens = True)
32print(response.split("assistant")[-1].strip())1@article{yue2023mathinstruct,
2 title={Mathinstruct: A compiled instruction dataset for mathematical reasoning},
3 author={Yue, Xiang and Qu, Xingwei and Zhang, Ge and Yao, Liang and Huo, Shijie and Sun, Wei and Caswell, Isaac and Xie, Wenhu and others},
4 journal={arXiv preprint arXiv:2309.04408},
5 year={2023}
6}