noom83 commited on
Commit
567c93e
·
verified ·
1 Parent(s): eea6d8c

Upload inference.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. inference.py +22 -0
inference.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Example inference code
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ # Load the model
6
+ tokenizer = AutoTokenizer.from_pretrained("exaler/aaa-2-sql-2")
7
+ model = AutoModelForCausalLM.from_pretrained("exaler/aaa-2-sql-2")
8
+
9
+ def generate_sql(instruction, input_text):
10
+ # Format prompt
11
+ prompt = f"<s>[INST] {instruction}\n\n{input_text} [/INST]"
12
+
13
+ # Generate
14
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
15
+ outputs = model.generate(
16
+ inputs=inputs.input_ids,
17
+ max_new_tokens=512,
18
+ temperature=0.0,
19
+ do_sample=False
20
+ )
21
+ response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
22
+ return response