Views
No views yet
meta-llama/Meta-Llama-3-8B-Instruct, specialized for solving university-level differential equations problems.(prompt, chosen, rejected) triplets.trl's DPOTrainer and QLoRA.transformers library pipeline. It is crucial to use the Llama 3 chat template for best results.1import torch
2from transformers import pipeline
3
4# Load the model and tokenizer
5pipe = pipeline(
6 "text-generation",
7 model="Sandesh-Zenteiq/LMT-tuning",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11
12# Your differential equations problem
13problem = "Solve the initial value problem: y' - 2y = 0, with y(0) = 3."
14
15# This is the full instruction set the model was trained on
16instruction_text = (
17 "Your task is to answer the last question below. "
18 "Give step by step reasoning before you answer. "
19 "When you're ready to answer, please wrap your answer and conclude using the format\n"
20 "'''\n[[Final Answer]]:\n$ANSWER$\n'''\n\n\n\n"
21)
22exam_template = (
23 "[[Question]]:\n{question}\n\n"
24 "[[Solution]]:\nLet's think step by step.\n\n"
25)
26
27# Format the prompt using the Llama 3 chat template
28prompt = (
29 f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n"
30 f"{instruction_text}{exam_template.format(question=problem)}"
31 f"<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
32)
33
34# Generate the response
35# The pipeline will handle the prompt and only show you the generated part
36response = pipe(
37 prompt,
38 max_new_tokens=1024,
39 do_sample=False, # Use do_sample=True for more creative answers
40 temperature=0.7,
41 top_p=0.9
42)
43
44# Extract and print the generated text
45# The pipeline returns a list of outputs
46generated_text = response['generated_text']
47# The generated text includes the prompt, so we can slice it to see only the model's answer
48assistant_response = generated_text[len(prompt):]
49print(assistant_response)
50
51Training Details
52
53Base Model: meta-llama/Meta-Llama-3-8B-Instruct
54
55Framework: trl.DPOTrainer with QLoRA
56
57Hardware: NVIDIA A6000 / H200 class GPUs
58
59Key Hyperparameters:
60
61learning_rate: 2e-5
62
63num_epochs: 1
64
65lora_r: 128
66
67lora_alpha: 256
68
69gradient_accumulation_steps: 16
70
71Evaluation
72
73The model was evaluated on a held-out test set of 305 differential equations problems that were not seen during training. The metric is Pass@1 accuracy.
74
75Model Accuracy
76meta-llama/Llama-3-8B-Instruct (Base) 10.16%
77LMT-tuning (This Model) 16.07%
78
79This represents a +5.90 point absolute improvement and a ~58% relative improvement in performance on this specialized task.
80
81Model fine-tuned by Sandesh-Zenteiq. The methodology is based on the paper "Can LLMs Learn by Teaching for Better Reasoning?"```