YongdongWang commited on
Commit
98c5195
·
verified ·
1 Parent(s): 0af933c

Update Llama 3.1 8B robot planning space with improvements

Browse files
Files changed (2) hide show
  1. README.md +85 -11
  2. app.py +82 -25
README.md CHANGED
@@ -13,18 +13,92 @@ hardware: t4-medium
13
 
14
  # 🤖 Robot Task Planning - Llama 3.1 8B
15
 
16
- Fine-tuned Llama 3.1 8B model for robot task planning using QLoRA technique.
17
 
18
- ## Model
19
- [YongdongWang/llama-3.1-8b-dart-qlora](https://huggingface.co/YongdongWang/llama-3.1-8b-dart-qlora)
20
 
21
- ## Features
22
- - Natural language to robot task conversion
23
- - Multi-robot coordination
24
- - Real-time task generation
25
- - Optimized with 4-bit quantization
26
 
27
- ## Usage
28
- Input robot commands and get structured task sequences for excavators, dump trucks, and other construction robots.
29
 
30
- Loading time: ~3-5 minutes on first startup.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # 🤖 Robot Task Planning - Llama 3.1 8B
15
 
16
+ This Space demonstrates a fine-tuned version of Meta's **Llama 3.1 8B** model specialized for **robot task planning** using QLoRA (4-bit quantization + LoRA) technique.
17
 
18
+ ## 🎯 Purpose
 
19
 
20
+ Convert natural language commands into structured task sequences for construction robots including:
21
+ - **Excavators** - Digging, loading, positioning
22
+ - **Dump Trucks** - Material transport, loading, unloading
23
+ - **Multi-robot Coordination** - Complex task dependencies
 
24
 
25
+ ## 🔗 Model
 
26
 
27
+ **Fine-tuned Model**: [YongdongWang/llama-3.1-8b-dart-qlora](https://huggingface.co/YongdongWang/llama-3.1-8b-dart-qlora)
28
+
29
+ **Base Model**: [meta-llama/Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B)
30
+
31
+ ## ✨ Features
32
+
33
+ - 🎮 **Interactive Chat Interface** - Real-time robot command processing
34
+ - ⚙️ **Configurable Generation** - Adjust temperature, top-p, max tokens
35
+ - 📝 **Example Commands** - Pre-built scenarios to get started
36
+ - 🚀 **Optimized Performance** - 4-bit quantization for efficient inference
37
+ - 📊 **Structured Output** - JSON-formatted task sequences
38
+
39
+ ## 🚀 Usage
40
+
41
+ 1. **Input**: Natural language robot commands
42
+ ```
43
+ "Deploy Excavator 1 to Soil Area 1 for excavation"
44
+ ```
45
+
46
+ 2. **Output**: Structured task sequences
47
+ ```json
48
+ {
49
+ "tasks": [
50
+ {
51
+ "robot": "Excavator_1",
52
+ "action": "move_to",
53
+ "target": "Soil_Area_1",
54
+ "duration": 30
55
+ },
56
+ {
57
+ "robot": "Excavator_1",
58
+ "action": "excavate",
59
+ "target": "Soil_Area_1",
60
+ "duration": 120
61
+ }
62
+ ]
63
+ }
64
+ ```
65
+
66
+ ## 🛠️ Technical Details
67
+
68
+ - **Architecture**: Llama 3.1 8B + QLoRA adapters
69
+ - **Quantization**: 4-bit (NF4) with double quantization
70
+ - **Framework**: Transformers + PEFT + BitsAndBytesConfig
71
+ - **Interface**: Gradio 4.44.0
72
+ - **Hardware**: T4 Medium (16GB VRAM)
73
+
74
+ ## ⚡ Performance Notes
75
+
76
+ - **First Load**: 3-5 minutes (model downloading + loading)
77
+ - **Subsequent Generations**: ~2-10 seconds per response
78
+ - **Memory Usage**: ~8GB VRAM with 4-bit quantization
79
+ - **Context Length**: Up to 2048 tokens
80
+
81
+ ## 📚 Example Commands
82
+
83
+ Try these robot commands:
84
+
85
+ - `"Deploy Excavator 1 to Soil Area 1 for excavation"`
86
+ - `"Send Dump Truck 1 to collect material, then unload at storage"`
87
+ - `"Coordinate multiple excavators across different areas"`
88
+ - `"Create evacuation sequence for all robots from dangerous zone"`
89
+
90
+ ## 🔬 Research Applications
91
+
92
+ This model demonstrates:
93
+ - **Natural Language → Robot Planning** translation
94
+ - **Multi-agent Task Coordination**
95
+ - **Efficient LLM Fine-tuning** with QLoRA
96
+ - **Real-time Robot Command Processing**
97
+
98
+ ## 📄 License
99
+
100
+ This project uses Meta's Llama 3.1 license. Please review the license terms before use.
101
+
102
+ ## 🤝 Contributing
103
+
104
+ For issues, improvements, or questions about the model, please visit the [model repository](https://huggingface.co/YongdongWang/llama-3.1-8b-dart-qlora).
app.py CHANGED
@@ -57,13 +57,13 @@ def load_model():
57
  print(f"❌ Model loading failed: {load_error}")
58
  return None, None
59
 
60
- # 全局变量
61
  model = None
62
  tokenizer = None
63
  model_loading = False
64
 
65
  def initialize_model():
66
- """初始化模型"""
67
  global model, tokenizer, model_loading
68
 
69
  if model is not None and tokenizer is not None:
@@ -85,7 +85,7 @@ def generate_response(prompt, max_tokens=200, temperature=0.7, top_p=0.9):
85
  if model_loading:
86
  return "🔄 Model is loading, please wait a few minutes and try again..."
87
  else:
88
- return "❌ Model failed to load. Please check the Space logs."
89
 
90
  try:
91
  # 格式化输入
@@ -123,7 +123,7 @@ def generate_response(prompt, max_tokens=200, temperature=0.7, top_p=0.9):
123
  elif len(response) > len(formatted_prompt):
124
  response = response[len(formatted_prompt):].strip()
125
 
126
- return response if response else "❌ No response generated. Please try again."
127
 
128
  except Exception as generation_error:
129
  return f"❌ Generation Error: {str(generation_error)}"
@@ -156,55 +156,112 @@ with gr.Blocks(
156
  gr.Markdown("""
157
  # 🤖 Llama 3.1 8B - Robot Task Planning
158
 
159
- Fine-tuned version of Meta's Llama 3.1 8B for **robot task planning** using QLoRA.
 
 
160
 
161
  **Model**: [YongdongWang/llama-3.1-8b-dart-qlora](https://huggingface.co/YongdongWang/llama-3.1-8b-dart-qlora)
162
 
163
- ⚠️ **First load takes 3-5 minutes**
164
  """)
165
 
166
  with gr.Row():
167
  with gr.Column(scale=3):
168
  chatbot = gr.Chatbot(
169
- label="🤖 Task Planning Results",
170
  height=500,
 
 
 
171
  show_copy_button=True
172
  )
173
 
174
  msg = gr.Textbox(
175
  label="Robot Command",
176
- placeholder="e.g., 'Deploy Excavator 1 to Soil Area 1'...",
177
- lines=2
 
 
 
178
  )
179
 
180
  with gr.Row():
181
- send_btn = gr.Button("🚀 Generate", variant="primary")
182
- clear_btn = gr.Button("🗑️ Clear", variant="secondary")
183
 
184
  with gr.Column(scale=1):
185
- gr.Markdown("### ⚙️ Settings")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
- max_tokens = gr.Slider(50, 500, 200, label="Max Tokens")
188
- temperature = gr.Slider(0.1, 2.0, 0.7, step=0.1, label="Temperature")
189
- top_p = gr.Slider(0.1, 1.0, 0.9, step=0.05, label="Top-p")
 
 
190
 
191
- # 示例
192
  gr.Examples(
193
  examples=[
194
  ["Deploy Excavator 1 to Soil Area 1 for excavation."],
195
- ["Send Dump Truck 1 to collect material and unload at storage."],
196
- ["Move all robots to avoid dangerous Puddle 1."],
197
- ["Coordinate multiple excavators across different areas."],
198
- ["Create evacuation sequence for all robots."],
 
 
 
199
  ],
200
  inputs=msg,
201
- label="💡 Try these examples"
202
  )
203
 
204
  # 事件处理
205
- msg.submit(chat_interface, [msg, chatbot, max_tokens, temperature, top_p], [chatbot, msg])
206
- send_btn.click(chat_interface, [msg, chatbot, max_tokens, temperature, top_p], [chatbot, msg])
207
- clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg])
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  if __name__ == "__main__":
210
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
57
  print(f"❌ Model loading failed: {load_error}")
58
  return None, None
59
 
60
+ # 全局变量存储模型
61
  model = None
62
  tokenizer = None
63
  model_loading = False
64
 
65
  def initialize_model():
66
+ """初始化模型 - 延迟加载"""
67
  global model, tokenizer, model_loading
68
 
69
  if model is not None and tokenizer is not None:
 
85
  if model_loading:
86
  return "🔄 Model is loading, please wait a few minutes and try again..."
87
  else:
88
+ return "❌ Model failed to load. Please check the Space logs or try restarting."
89
 
90
  try:
91
  # 格式化输入
 
123
  elif len(response) > len(formatted_prompt):
124
  response = response[len(formatted_prompt):].strip()
125
 
126
+ return response if response else "❌ No response generated. Please try again with a different prompt."
127
 
128
  except Exception as generation_error:
129
  return f"❌ Generation Error: {str(generation_error)}"
 
156
  gr.Markdown("""
157
  # 🤖 Llama 3.1 8B - Robot Task Planning
158
 
159
+ This is a fine-tuned version of Meta's Llama 3.1 8B model specialized for **robot task planning** using QLoRA technique.
160
+
161
+ **Capabilities**: Convert natural language robot commands into structured task sequences for excavators, dump trucks, and other construction robots.
162
 
163
  **Model**: [YongdongWang/llama-3.1-8b-dart-qlora](https://huggingface.co/YongdongWang/llama-3.1-8b-dart-qlora)
164
 
165
+ ⚠️ **Note**: Model loading may take 3-5 minutes on first startup. Please be patient.
166
  """)
167
 
168
  with gr.Row():
169
  with gr.Column(scale=3):
170
  chatbot = gr.Chatbot(
171
+ label="Task Planning Results",
172
  height=500,
173
+ show_label=True,
174
+ container=True,
175
+ bubble_full_width=False,
176
  show_copy_button=True
177
  )
178
 
179
  msg = gr.Textbox(
180
  label="Robot Command",
181
+ placeholder="Enter robot task command (e.g., 'Deploy Excavator 1 to Soil Area 1')...",
182
+ lines=2,
183
+ max_lines=5,
184
+ show_label=True,
185
+ container=True
186
  )
187
 
188
  with gr.Row():
189
+ send_btn = gr.Button("🚀 Generate Tasks", variant="primary", size="sm")
190
+ clear_btn = gr.Button("🗑️ Clear", variant="secondary", size="sm")
191
 
192
  with gr.Column(scale=1):
193
+ gr.Markdown("### ⚙️ Generation Settings")
194
+
195
+ max_tokens = gr.Slider(
196
+ minimum=50,
197
+ maximum=500,
198
+ value=200,
199
+ step=10,
200
+ label="Max Tokens",
201
+ info="Maximum number of tokens to generate"
202
+ )
203
+
204
+ temperature = gr.Slider(
205
+ minimum=0.1,
206
+ maximum=2.0,
207
+ value=0.7,
208
+ step=0.1,
209
+ label="Temperature",
210
+ info="Controls randomness (lower = more focused)"
211
+ )
212
+
213
+ top_p = gr.Slider(
214
+ minimum=0.1,
215
+ maximum=1.0,
216
+ value=0.9,
217
+ step=0.05,
218
+ label="Top-p",
219
+ info="Nucleus sampling threshold"
220
+ )
221
 
222
+ gr.Markdown("""
223
+ ### 📊 Model Status
224
+ The model will load automatically on first use.
225
+ Loading time: ~3-5 minutes
226
+ """)
227
 
228
+ # 示例对话
229
  gr.Examples(
230
  examples=[
231
  ["Deploy Excavator 1 to Soil Area 1 for excavation."],
232
+ ["Send Dump Truck 1 to collect material from Excavator 1, then unload at storage area."],
233
+ ["Move all robots to avoid Puddle 1 after inspection."],
234
+ ["Deploy multiple excavators to different soil areas simultaneously."],
235
+ ["Coordinate dump trucks to transport materials from excavation site to storage."],
236
+ ["Send robot to inspect rock area, then avoid with all other robots if dangerous."],
237
+ ["Return all robots to start position after completing tasks."],
238
+ ["Create a sequence: excavate, load, transport, unload, repeat."]
239
  ],
240
  inputs=msg,
241
+ label="💡 Example Robot Commands"
242
  )
243
 
244
  # 事件处理
245
+ msg.submit(
246
+ chat_interface,
247
+ inputs=[msg, chatbot, max_tokens, temperature, top_p],
248
+ outputs=[chatbot, msg]
249
+ )
250
+
251
+ send_btn.click(
252
+ chat_interface,
253
+ inputs=[msg, chatbot, max_tokens, temperature, top_p],
254
+ outputs=[chatbot, msg]
255
+ )
256
+
257
+ clear_btn.click(
258
+ lambda: ([], ""),
259
+ outputs=[chatbot, msg]
260
+ )
261
 
262
  if __name__ == "__main__":
263
+ demo.launch(
264
+ server_name="0.0.0.0",
265
+ server_port=7860,
266
+ show_error=True
267
+ )