File size: 1,096 Bytes
e9b662b
 
 
 
 
5553408
e9b662b
5553408
 
 
 
e9b662b
37eaa05
 
e9b662b
5553408
e9b662b
5553408
 
e9b662b
5553408
 
e9b662b
5553408
 
 
e9b662b
5553408
 
 
e9b662b
5553408
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
library_name: transformers
tags: []
---

## INFERENCE

```Python
import time
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

finetuned_model = AutoModelForCausalLM.from_pretrained("Mr-Vicky-01/GPT-QnA")
tokenizer = AutoTokenizer.from_pretrained("Mr-Vicky-01/GPT-QnA")

alpaca_prompt = """Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
what is depresssion how to overcome

### Response:
"""

s = time.time()
prompt = alpaca_prompt
encodeds = tokenizer(prompt, return_tensors="pt",truncation=True).input_ids

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
finetuned_model.to(device)
inputs = encodeds.to(device)

# Increase max_new_tokens if needed
generated_ids = finetuned_model.generate(inputs, max_new_tokens=256, temperature=0.1, top_p=0.90, do_sample=False,pad_token_id=50259,eos_token_id=50259,num_return_sequences=1)
print(tokenizer.decode(generated_ids[0]).split('### Response:')[1].split('<eos>')[0].strip())
e = time.time()
print(f'time taken:{e-s}')
```