justsomerandomdude264 commited on
Commit
047c840
·
verified ·
1 Parent(s): 82edc26

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +132 -0
README.md ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: unsloth/meta-llama-3.1-8b-instruct-bnb-4bit
3
+ language:
4
+ - en
5
+ license: mit
6
+ tags:
7
+ - text-generation-inference
8
+ - transformers
9
+ - unsloth
10
+ - llama
11
+ - trl
12
+ datasets:
13
+ - justsomerandomdude264/ScienceQA-Dataset
14
+ library_name: transformers
15
+ ---
16
+ # Model Card: Math Homework Solver
17
+
18
+ This is a Large Language Model (LLM) fine-tuned to solve math problems with detailed, step-by-step explanations and accurate answers. The base model used is Llama 3.1 with 8 billion parameters, which has been quantized to 4-bit using QLoRA (Quantized Low-Rank Adaptation) and PEFT (Parameter-Efficient Fine-Tuning) through the Unsloth framework.
19
+
20
+ ## Model Details
21
+
22
+ - **Base Model**: Llama 3.1 (8 Billion parameters)
23
+ - **Fine-tuning Method**: PEFT (Parameter-Efficient Fine-Tuning) with QLoRA
24
+ - **Quantization**: 4-bit quantization for reduced memory usage
25
+ - **Training Framework**: Unsloth, optimized for efficient fine-tuning of large language models
26
+ - **Training Environment**: Google Colab (free tier), NVIDIA T4 GPU (12GB VRAM), 12GB RAM
27
+ - **Dataset Used**: justsomerandomdude264/ScienceQA-Dataset, 560 selected rows
28
+
29
+ ## Capabilities
30
+
31
+ The Science Homework Solver model is designed to assist with a broad spectrum of scientifical problems, from basics of gravity to advanced topics like quantum entanglement. It provides clear and detailed explanations, making it an excellent resource for students, educators, and anyone looking to deepen their understanding of scientifical concepts.
32
+
33
+ By leveraging the Llama 3.1 base model and fine-tuning it using PEFT and QLoRA, this model achieves high-quality performance while maintaining a relatively small computational footprint, making it accessible even on limited hardware.
34
+
35
+ ## Getting Started
36
+
37
+ To start using the Science Homework Solver model, follow these steps:
38
+
39
+ 1. **Clone the repo**
40
+ ```bash
41
+ git clone https://huggingface.co/justsomerandomdude264/Science_Homework_Solver-Llama3.18B
42
+ ```
43
+
44
+ 2. **Run inference**
45
+
46
+ 1. This method is recommended as its reliable and accurate:
47
+ ```python
48
+ from unsloth import FastLanguageModel
49
+ import torch
50
+
51
+ # Define Your Question
52
+ question = "A tank is filled with water to a height of 12.5 cm. The apparent depth of a needle lying at the bottom of the tank is measured by a microscope to be 9.4 cm. What is the refractive index of water? If water is replaced by a liquid of refractive index 1.63 up to the same height, by what distance would the microscope have to be moved to focus on the needle again?" # Example Question, You can change it with one of your own
53
+ # Load the model
54
+ model, tokenizer = FastLanguageModel.from_pretrained(
55
+ model_name = "Science_Homework_Solver_Llama318B/model_adapters", # The dir where the repo is cloned or "\\" for root
56
+ max_seq_length = 2048,
57
+ dtype = None,
58
+ load_in_4bit = True,
59
+ )
60
+ # Set the model in inference model
61
+ FastLanguageModel.for_inference(model)
62
+ # QA template
63
+ qa_template = """Question: {}
64
+ Answer: {}"""
65
+ # Tokenize inputs
66
+ inputs = tokenizer(
67
+ [
68
+ qa_template.format(
69
+ question, # Question
70
+ "", # Answer - left blank for generation
71
+ )
72
+ ], return_tensors = "pt").to("cuda")
73
+ # Stream the answer/output of the model
74
+ from transformers import TextStreamer
75
+ text_streamer = TextStreamer(tokenizer)
76
+ _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)
77
+ ```
78
+
79
+ 2. Another way to run inference is to use the merged adapters (not recommend as it gives inaccurate/different answers):
80
+ ```python
81
+ from transformers import LlamaForCausalLM, AutoTokenizer
82
+ # Load the model
83
+ model = LlamaForCausalLM.from_pretrained(
84
+ "justsomerandomdude264/Science_Homework_Solver_Llama318B",
85
+ device_map="auto"
86
+ )
87
+
88
+ # Load the tokenizer
89
+ tokenizer = AutoTokenizer.from_pretrained("justsomerandomdude264/Science_Homework_Solver_Llama318B")
90
+ # Set the inputs up
91
+ qa_template = """Question: {}
92
+ Answer: {}"""
93
+
94
+ inputs = tokenizer(
95
+ [
96
+ qa_template.format(
97
+ "A tank is filled with water to a height of 12.5 cm. The apparent depth of a needle lying at the bottom of the tank is measured by a microscope to be 9.4 cm. What is the refractive index of water? If water is replaced by a liquid of refractive index 1.63 up to the same height, by what distance would the microscope have to be moved to focus on the needle again?", # instruction
98
+ "", # output - leave this blank for generation!
99
+ )
100
+ ], return_tensors = "pt").to("cuda")
101
+
102
+ # Do a forward pass
103
+ outputs = model.generate(**inputs, max_new_tokens = 128, use_cache = True)
104
+ raw_output = str(tokenizer.batch_decode(outputs))
105
+
106
+ # Formtting the string
107
+ # Removing the list brackets and splitting the string by newline characters
108
+ formatted_string = raw_output.strip("[]").replace("<|begin_of_text|>", "").replace("<|eot_id|>", "").strip("''").split("\\n")
109
+ # Print the lines one by one
110
+ for line in formatted_string:
111
+ print(line)
112
+ ```
113
+
114
+
115
+ ## Citation
116
+
117
+ Please use the following citation if you reference the Math Homework Solver model:
118
+
119
+ ### BibTeX Citation
120
+ ```bibtex
121
+ @misc{paliwal2024,
122
+ author = {Krishna Paliwal},
123
+ title = {Contributions to Math_Homework_Solver},
124
+ year = {2024},
125
+ email = {krishna.plwl264@gmail.com}
126
+ }
127
+ ```
128
+
129
+ ### APA Citation
130
+ ```plaintext
131
+ Paliwal, Krishna (2024). Contributions to Math_Homework_Solver. Email: krishna.plwl264@gmail.com .
132
+ ```