sanjay920 commited on
Commit
b3e3351
·
verified ·
1 Parent(s): 417cf64

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +278 -12
README.md CHANGED
@@ -1,17 +1,256 @@
1
- ---
2
- license: llama3
3
- ---
4
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
6
 
7
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
8
- should probably proofread and complete it, then remove this comment. -->
9
 
10
- # run1_short_8000
 
11
 
12
- This model is a fine-tuned version of [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) on the rubra_train_v1_llama3_short dataset.
13
 
14
- ### Training hyperparameters
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  The following hyperparameters were used during training:
17
  - learning_rate: 2e-05
@@ -24,10 +263,37 @@ The following hyperparameters were used during training:
24
  - lr_scheduler_type: cosine
25
  - num_epochs: 1.0
26
 
27
-
28
- ### Framework versions
29
 
30
  - Transformers 4.41.2
31
- - Pytorch 2.3.0+cu121
32
  - Datasets 2.19.2
33
- - Tokenizers 0.19.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: llama3
3
+ model-index:
4
+ - name: Meta-Llama-3-8B-Instruct
5
+ results:
6
+ - task:
7
+ type: text-generation
8
+ dataset:
9
+ type: MMLU
10
+ name: MMLU
11
+ metrics:
12
+ - type: 5-shot
13
+ value: 58.9
14
+ verified: false
15
+ - task:
16
+ type: text-generation
17
+ dataset:
18
+ type: GPQA
19
+ name: GPQA
20
+ metrics:
21
+ - type: 0-shot
22
+ value: 29.91
23
+ verified: false
24
+ - task:
25
+ type: text-generation
26
+ dataset:
27
+ type: GSM-8K
28
+ name: GSM-8K
29
+ metrics:
30
+ - type: 8-shot, CoT
31
+ value: 34.12
32
+ verified: false
33
+ - task:
34
+ type: text-generation
35
+ dataset:
36
+ type: MATH
37
+ name: MATH
38
+ metrics:
39
+ - type: 4-shot, CoT
40
+ value: 8.36
41
+ verified: false
42
+ - task:
43
+ type: text-generation
44
+ dataset:
45
+ type: MT-bench
46
+ name: MT-bench
47
+ metrics:
48
+ - type: GPT-4 as Judge
49
+ value: 7.36
50
+ verified: false
51
+ tags:
52
+ - function-calling
53
+ - tool-calling
54
+ - agentic
55
+ - rubra
56
  ---
57
 
58
+ # Meta-Llama-3-8B-Instruct
 
59
 
60
+ ## Model description
61
+ The model is the result of further post-training [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct). It is capable of complex tool/function calling.
62
 
63
+ ## Training Data
64
 
65
+ The model was post-trained (freeze tuned & DPO) on a proprietary dataset consisting of diverse function calling, chat, and instruct data.
66
+
67
+ ## How to use
68
+
69
+ You can use the model with the Hugging Face `transformers` and the rubra library [rubra-tools](https://github.com/rubra-ai/rubra-tools) as follows:
70
+
71
+ ```
72
+ pip install rubra_tools torch==2.3.0 transformers
73
+ ```
74
+
75
+ ### 1. Load the Model
76
+ ```python
77
+ from transformers import AutoTokenizer, AutoModelForCausalLM
78
+ import torch
79
+ from rubra_tools import preprocess_input, postprocess_output
80
+
81
+ model_id = "rubra-ai/Meta-Llama-3-8B-Instruct"
82
+
83
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
84
+ model = AutoModelForCausalLM.from_pretrained(
85
+ model_id,
86
+ torch_dtype=torch.bfloat16,
87
+ device_map="auto",
88
+ )
89
+ ```
90
+
91
+ ### 2. Define Functions
92
+
93
+ Here we use 4 functions for a simple math chaining question:
94
+ ```python
95
+ functions = [
96
+ {
97
+ 'type': 'function',
98
+ 'function': {
99
+ 'name': 'addition',
100
+ 'description': "Adds two numbers together",
101
+ 'parameters': {
102
+ 'type': 'object',
103
+ 'properties': {
104
+ 'a': {
105
+ 'description': 'First number to add',
106
+ 'type': 'string'
107
+ },
108
+ 'b': {
109
+ 'description': 'Second number to add',
110
+ 'type': 'string'
111
+ }
112
+ },
113
+ 'required': []
114
+ }
115
+ }
116
+ },
117
+ {
118
+ 'type': 'function',
119
+ 'function': {
120
+ 'name': 'subtraction',
121
+ 'description': "Subtracts two numbers",
122
+ 'parameters': {
123
+ 'type': 'object',
124
+ 'properties': {
125
+ 'a': {
126
+ 'description': 'First number to be subtracted from',
127
+ 'type': 'string'
128
+ },
129
+ 'b': {
130
+ 'description': 'Number to subtract',
131
+ 'type': 'string'
132
+ }
133
+ },
134
+ 'required': []
135
+ }
136
+ }
137
+ },
138
+ {
139
+ 'type': 'function',
140
+ 'function': {
141
+ 'name': 'multiplication',
142
+ 'description': "Multiply two numbers together",
143
+ 'parameters': {
144
+ 'type': 'object',
145
+ 'properties': {
146
+ 'a': {
147
+ 'description': 'First number to multiply',
148
+ 'type': 'string'
149
+ },
150
+ 'b': {
151
+ 'description': 'Second number to multiply',
152
+ 'type': 'string'
153
+ }
154
+ },
155
+ 'required': []
156
+ }
157
+ }
158
+ },
159
+ {
160
+ 'type': 'function',
161
+ 'function': {
162
+ 'name': 'division',
163
+ 'description': "Divide two numbers",
164
+ 'parameters': {
165
+ 'type': 'object',
166
+ 'properties': {
167
+ 'a': {
168
+ 'description': 'First number to use as the dividend',
169
+ 'type': 'string'
170
+ },
171
+ 'b': {
172
+ 'description': 'Second number to use as the divisor',
173
+ 'type': 'string'
174
+ }
175
+ },
176
+ 'required': []
177
+ }
178
+ }
179
+ },
180
+ ]
181
+ ```
182
+
183
+ ### 3. Start the conversation
184
+ ```python
185
+ messages = [
186
+ {"role": "system", "content": "You are a helpful assistant."},
187
+ {"role": "user", "content": "What is the result of four plus six? Take the result and add 2? Then multiply by 5 and then divide by two"},
188
+ ]
189
+
190
+ def run_model(messages, functions):
191
+ ## Format messages in Rubra's format
192
+ formatted_msgs = preprocess_input(msgs=messages, tools=functions)
193
+
194
+ input_ids = tokenizer.apply_chat_template(
195
+ formatted_msgs,
196
+ add_generation_prompt=True,
197
+ return_tensors="pt"
198
+ ).to(model.device)
199
+
200
+ terminators = [
201
+ tokenizer.eos_token_id,
202
+ tokenizer.convert_tokens_to_ids("")
203
+ ]
204
+
205
+ outputs = model.generate(
206
+ input_ids,
207
+ max_new_tokens=1000,
208
+ eos_token_id=terminators,
209
+ do_sample=True,
210
+ temperature=0.1,
211
+ top_p=0.9,
212
+ )
213
+ response = outputs[0][input_ids.shape[-1]:]
214
+ raw_output = tokenizer.decode(response, skip_special_tokens=True)
215
+ return raw_output
216
+
217
+ raw_output = run_model(messages, functions)
218
+ # Check if there's a function call
219
+ function_call = postprocess_output(raw_output)
220
+ if function_call:
221
+ print(function_call)
222
+ else:
223
+ print(raw_output)
224
+ ```
225
+
226
+ You should see this output, which is a function call made by the AI assistant:
227
+ ```
228
+ [{'id': 'fc65a533', 'function': {'name': 'addition', 'arguments': '{"a": "4", "b": "6"}'}, 'type': 'function'}]
229
+ ```
230
+
231
+ ### 4. Add Executed Tool Result to Message History & Continue the Conversation
232
+
233
+ ```python
234
+ if function_call:
235
+ # append the assistant tool call msg
236
+ messages.append({"role": "assistant", "tool_calls": function_call})
237
+ # append the result of the tool call in openai format, in this case, the value of add 6 to 4 is 10.
238
+ messages.append({'role': 'tool', 'tool_call_id': function_call[0]["id"], 'name': function_call[0]["function"]["name"], 'content': '10'})
239
+ raw_output = run_model(messages, functions)
240
+ # Check if there's a function call
241
+ function_call = postprocess_output(raw_output)
242
+ if function_call:
243
+ print(function_call)
244
+ else:
245
+ print(raw_output)
246
+ ```
247
+
248
+ The LLM will make another call
249
+ ```
250
+ [{'id': '2ffc3de4', 'function': {'name': 'addition', 'arguments': '{"a": "10", "b": "2"}'}, 'type': 'function'}]
251
+ ```
252
+
253
+ ## Training Hyperparameters
254
 
255
  The following hyperparameters were used during training:
256
  - learning_rate: 2e-05
 
263
  - lr_scheduler_type: cosine
264
  - num_epochs: 1.0
265
 
266
+ ## Framework Versions
 
267
 
268
  - Transformers 4.41.2
269
+ - Pytorch 2.3.1+cu121
270
  - Datasets 2.19.2
271
+ - Tokenizers 0.19.1
272
+
273
+ ## Limitations and Bias
274
+
275
+ While the model performs well on a wide range of tasks, it may still produce biased or incorrect outputs. Users should exercise caution and critical judgment when using the model in sensitive or high-stakes applications. The model's outputs are influenced by the data it was trained on, which may contain inherent biases.
276
+
277
+ ## Ethical Considerations
278
+
279
+ Users should ensure that the deployment of this model adheres to ethical guidelines and consider the potential societal impact of the generated text. Misuse of the model for generating harmful or misleading content is strongly discouraged.
280
+
281
+ ## Acknowledgements
282
+
283
+ We would like to thank Meta for the model and LLaMA-Factory for training utilities.
284
+
285
+ ## Contact Information
286
+
287
+ For questions or comments about the model, please reach out to [the rubra team](mailto:[email protected]).
288
+
289
+ ## Citation
290
+
291
+ If you use this work, please cite it as:
292
+
293
+ ```
294
+ @misc {rubra_ai_2024,
295
+ author = { Sanjay Nadhavajhala and Yingbei Tong },
296
+ title = { Meta-Llama-3-8B-Instruct },
297
+ year = 2024,
298
+ url = { https://huggingface.co/rubra-ai/Meta-Llama-3-8B-Instruct },
299
+ doi = {