Create gen.py
Browse files
gen.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
generation_config = GenerationConfig(
|
2 |
+
temperature=0.1,
|
3 |
+
top_p=0.75,
|
4 |
+
num_beams=4,
|
5 |
+
)
|
6 |
+
|
7 |
+
def evaluate(instruction, input=None):
|
8 |
+
prompt = generate_prompt(instruction, input)
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
input_ids = inputs["input_ids"].cuda()
|
11 |
+
generation_output = model.generate(
|
12 |
+
input_ids=input_ids,
|
13 |
+
generation_config=generation_config,
|
14 |
+
return_dict_in_generate=True,
|
15 |
+
output_scores=True,
|
16 |
+
max_new_tokens=256
|
17 |
+
)
|
18 |
+
for s in generation_output.sequences:
|
19 |
+
output = tokenizer.decode(s)
|
20 |
+
print("Response:", output.split("### Response:")[1].strip())
|