justsomerandomdude264 commited on
Commit
12a43d2
1 Parent(s): 2656fe1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +57 -17
README.md CHANGED
@@ -1,18 +1,18 @@
1
- ---
2
- base_model: unsloth/meta-llama-3.1-8b-instruct-bnb-4bit
3
- language:
4
- - en
5
- license: apache-2.0
6
- tags:
7
- - text-generation-inference
8
- - transformers
9
- - unsloth
10
- - llama
11
- - trl
12
- datasets:
13
- - TIGER-Lab/MathInstruct
14
- library_name: transformers
15
- ---
16
 
17
  # Model Card: Math Homework Solver
18
 
@@ -44,7 +44,8 @@ To start using the Math Homework Solver model, follow these steps:
44
  ```
45
 
46
  2. **Run inference**
47
- Make a new file named main.py and run this code in it:
 
48
  ```python
49
  from unsloth import FastLanguageModel
50
  import torch
@@ -54,7 +55,7 @@ To start using the Math Homework Solver model, follow these steps:
54
 
55
  # Load the model
56
  model, tokenizer = FastLanguageModel.from_pretrained(
57
- model_name = "Math_Homework_Solver_Llama318B", # The dir where the repo is cloned or "\\" for root
58
  max_seq_length = 2048,
59
  dtype = None,
60
  load_in_4bit = True,
@@ -81,6 +82,45 @@ To start using the Math Homework Solver model, follow these steps:
81
  text_streamer = TextStreamer(tokenizer)
82
  _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)
83
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  ## Citation
86
 
 
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
+ - TIGER-Lab/MathInstruct
14
+ library_name: transformers
15
+ ---
16
 
17
  # Model Card: Math Homework Solver
18
 
 
44
  ```
45
 
46
  2. **Run inference**
47
+
48
+ 1. This method is recommended as its reliabel and accurate:
49
  ```python
50
  from unsloth import FastLanguageModel
51
  import torch
 
55
 
56
  # Load the model
57
  model, tokenizer = FastLanguageModel.from_pretrained(
58
+ model_name = "Math_Homework_Solver_Llama318B/model_adapters", # The dir where the repo is cloned or "\\" for root
59
  max_seq_length = 2048,
60
  dtype = None,
61
  load_in_4bit = True,
 
82
  text_streamer = TextStreamer(tokenizer)
83
  _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)
84
  ```
85
+
86
+ 2. Another way to run inference is to use the merged adapters (not recommend as it gives inaccurate/different answers):
87
+ ```python
88
+ from transformers import LlamaForCausalLM, AutoTokenizer
89
+
90
+ # Load the model
91
+ model = LlamaForCausalLM.from_pretrained(
92
+ "justsomerandomdude264/Science_Homework_Solver_Llama318B",
93
+ device_map="auto"
94
+ )
95
+
96
+ # Load the tokenizer
97
+ tokenizer = AutoTokenizer.from_pretrained("justsomerandomdude264/Science_Homework_Solver_Llama318B")
98
+
99
+ # Set the inputs up
100
+ qa_template = """Question: {}
101
+ Answer: {}"""
102
+
103
+ inputs = tokenizer(
104
+ [
105
+ qa_template.format(
106
+ "find the force of an object with 5kg of mass and 3.9ms2 acceleration", # instruction
107
+ "", # output - leave this blank for generation!
108
+ )
109
+ ], return_tensors = "pt").to("cuda")
110
+
111
+ # Do a forward pass
112
+ outputs = model.generate(**inputs, max_new_tokens = 128, use_cache = True)
113
+ raw_output = str(tokenizer.batch_decode(outputs))
114
+
115
+ # Formtting the string
116
+ # Removing the list brackets and splitting the string by newline characters
117
+ formatted_string = raw_output.strip("[]").replace("<|begin_of_text|>", "").replace("<|eot_id|>", "").strip("''").split("\\n")
118
+
119
+ # Print the lines one by one
120
+ for line in formatted_string:
121
+ print(line)
122
+ ```
123
+
124
 
125
  ## Citation
126