Views
No views yet
1import json
2from datasets import load_dataset
3from unsloth import FastLanguageModel
4
5# Dataset
6repo_id = "Studeni/robot-instructions"
7dataset = load_dataset(repo_id, split="test")
8test_input = dataset[0]["input"]
9test_output = dataset[0]["output"]
10print(f"User input: {test_input}\nGround truth: {test_output}")
11
12# Prompt
13robot_instruct_prompt = """
14### Instruction:
15Transform input into list of function calls for controlling industrial robots.
16
17### Input:
18{}
19
20### Response:
21{}
22"""
23
24# Model Parameters
25lora_id = "Studeni/llama-3-8b-bnb-4bit-robot-instruct"
26max_seq_length = 2048
27dtype = None # Auto-detection. Use Float16 for Tesla T4, V100, Bfloat16 for Ampere+
28load_in_4bit = True
29
30# Load the model and tokenizer
31model, tokenizer = FastLanguageModel.from_pretrained(
32 model_name=lora_id,
33 max_seq_length=max_seq_length,
34 dtype=dtype,
35 load_in_4bit=load_in_4bit,
36)
37FastLanguageModel.for_inference(model)
38
39# Tokenize input text
40inputs = tokenizer(
41 [robot_instruct_prompt.format(test_input, "")],
42 return_tensors="pt",
43).to("cuda")
44
45# Run generation
46outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)
47text_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)
48
49# Extracting function call and converting to json
50function_call = text_output[0].split("### Response:")[-1].strip()
51function_call = json.loads(function_call)
52for f in function_call:
53 print(f"Function to call: {f['function']}")
54 print(f"Input parameters: {f['kwargs']}")1import json
2from datasets import load_dataset
3from peft import AutoPeftModelForCausalLM
4from transformers import AutoTokenizer
5
6# Dataset
7repo_id = "Studeni/robot-instructions"
8dataset = load_dataset(repo_id, split="test")
9test_input = dataset[0]["input"]
10test_output = dataset[0]["output"]
11print(f"User input: {test_input}\nGround truth: {test_output}")
12
13# Prompt
14robot_instruct_prompt = """
15### Instruction:
16Transform input into list of function calls for controlling industrial robots.
17
18### Input:
19{}
20
21### Response:
22{}
23"""
24
25# Model Parameters
26lora_id = "Studeni/llama-3-8b-bnb-4bit-robot-instruct"
27load_in_4bit = True
28
29# Load model and tokenizer
30model = AutoPeftModelForCausalLM.from_pretrained(
31 pretrained_model_name_or_path=lora_id,
32 load_in_4bit=load_in_4bit,
33)
34tokenizer = AutoTokenizer.from_pretrained(lora_id)
35
36# Tokenize input text
37inputs = tokenizer(
38 [robot_instruct_prompt.format(test_input, "")],
39 return_tensors="pt",
40).to("cuda")
41
42# Run generation
43outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True)
44text_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)
45
46# Extracting function call and converting to json
47function_call = text_output[0].split("### Response:")[-1].strip()
48function_call = json.loads(function_call)
49for f in function_call:
50 print(f"Function to call: {f['function']}")
51 print(f"Input parameters: {f['kwargs']}")
52move_tcp, move_joint, and get_joint_values.
Future iterations will include a more comprehensive dataset with more complex commands and capabilities, better human-labeled data, and improved performance metrics.