Studeni commited on
Commit
cdc051a
·
verified ·
1 Parent(s): ae5e271

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +136 -4
README.md CHANGED
@@ -14,11 +14,143 @@ datasets:
14
  pipeline_tag: text-generation
15
  ---
16
 
17
- # Uploaded model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- - **Developed by:** Studeni
20
- - **License:** apache-2.0
21
- - **Finetuned from model :** unsloth/llama-3-8b-bnb-4bit
22
 
23
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
24
 
 
14
  pipeline_tag: text-generation
15
  ---
16
 
17
+ # Llama 3 8B Robot Instruction Model (4-bit)
18
+
19
+ ## Model description
20
+
21
+ This model is a fine-tuned version of Llama 3 8B, optimized with Unsloth and quantized into 4-bit.
22
+ It is designed to convert casual user input text into function calls for controlling industrial robots.
23
+ The aim is to lower the barrier for individuals who do not have programming skills to control robots using simple text instructions.
24
+
25
+ ## Model Details
26
+ - **Model ID:** Studeni/llama-3-8b-bnb-4bit-robot-instruct
27
+ - **Architecture:** Llama 3 8B
28
+ - **Quantization:** 4-bit
29
+ - **Framework:** Transformers, Peft, Unsloth
30
+
31
+ ## Usage
32
+
33
+ ### Using Unsloth Library
34
+
35
+ ```python
36
+ import json
37
+ from datasets import load_dataset
38
+ from unsloth import FastLanguageModel
39
+
40
+ # Dataset
41
+ repo_id = "Studeni/robot-instructions"
42
+ dataset = load_dataset(repo_id, split="test")
43
+ test_input = dataset[0]["input"]
44
+ test_output = dataset[0]["output"]
45
+ print(f"User input: {test_input}\nGround truth: {test_output}")
46
+
47
+ # Prompt
48
+ robot_instruct_prompt = """
49
+ ### Instruction:
50
+ Transform input into list of function calls for controlling industrial robots.
51
+
52
+ ### Input:
53
+ {}
54
+
55
+ ### Response:
56
+ {}
57
+ """
58
+
59
+ # Model Parameters
60
+ lora_id = "Studeni/llama-3-8b-bnb-4bit-robot-instruct"
61
+ max_seq_length = 2048
62
+ dtype = None # Auto-detection. Use Float16 for Tesla T4, V100, Bfloat16 for Ampere+
63
+ load_in_4bit = True
64
+
65
+ # Load the model and tokenizer
66
+ model, tokenizer = FastLanguageModel.from_pretrained(
67
+ model_name=lora_id,
68
+ max_seq_length=max_seq_length,
69
+ dtype=dtype,
70
+ load_in_4bit=load_in_4bit,
71
+ )
72
+ FastLanguageModel.for_inference(model)
73
+
74
+ # Tokenize input text
75
+ inputs = tokenizer(
76
+ [robot_instruct_prompt.format(test_input, "")],
77
+ return_tensors="pt",
78
+ ).to("cuda")
79
+
80
+ # Run generation
81
+ outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)
82
+ text_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)
83
+
84
+ # Extracting function call and converting to json
85
+ function_call = text_output[0].split("### Response:")[-1].strip()
86
+ function_call = json.loads(function_call)
87
+ for f in function_call:
88
+ print(f"Function to call: {f['function']}")
89
+ print(f"Input parameters: {f['kwargs']}")
90
+ ```
91
+
92
+ ### Using Transformers and Peft
93
+ ```python
94
+ import json
95
+ from datasets import load_dataset
96
+ from peft import AutoPeftModelForCausalLM
97
+ from transformers import AutoTokenizer
98
+
99
+ # Dataset
100
+ repo_id = "Studeni/robot-instructions"
101
+ dataset = load_dataset(repo_id, split="test")
102
+ test_input = dataset[0]["input"]
103
+ test_output = dataset[0]["output"]
104
+ print(f"User input: {test_input}\nGround truth: {test_output}")
105
+
106
+ # Prompt
107
+ robot_instruct_prompt = """
108
+ ### Instruction:
109
+ Transform input into list of function calls for controlling industrial robots.
110
+
111
+ ### Input:
112
+ {}
113
+
114
+ ### Response:
115
+ {}
116
+ """
117
+
118
+ # Model Parameters
119
+ lora_id = "Studeni/llama-3-8b-bnb-4bit-robot-instruct"
120
+ load_in_4bit = True
121
+
122
+ # Load model and tokenizer
123
+ model = AutoPeftModelForCausalLM.from_pretrained(
124
+ pretrained_model_name_or_path=lora_id,
125
+ load_in_4bit=load_in_4bit,
126
+ )
127
+ tokenizer = AutoTokenizer.from_pretrained(lora_id)
128
+
129
+ # Tokenize input text
130
+ inputs = tokenizer(
131
+ [robot_instruct_prompt.format(test_input, "")],
132
+ return_tensors="pt",
133
+ ).to("cuda")
134
+
135
+ # Run generation
136
+ outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True)
137
+ text_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)
138
+
139
+ # Extracting function call and converting to json
140
+ function_call = text_output[0].split("### Response:")[-1].strip()
141
+ function_call = json.loads(function_call)
142
+ for f in function_call:
143
+ print(f"Function to call: {f['function']}")
144
+ print(f"Input parameters: {f['kwargs']}")
145
+
146
+ ```
147
+
148
+ ## Limitations and Future Work 🚨
149
+ This model is currently a work in progress and supports only three basic functions: `move_tcp`, `move_joint`, and `get_joint_values`.
150
+ Future iterations will include a more comprehensive dataset with more complex commands and capabilities, better human-labeled data, and improved performance metrics.
151
+
152
+
153
 
 
 
 
154
 
155
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
156