move input ids and attmask to device
Browse files
app.py
CHANGED
@@ -12,8 +12,13 @@ model = transformers.AutoModelForCausalLM.from_pretrained(model_name, device_map
|
|
12 |
# Function to generate responses from the model
|
13 |
def generate_response(input_text):
|
14 |
inputs = tokenizer(input_text, return_tensors="pt")
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
17 |
return response
|
18 |
|
19 |
# Define the Gradio interface
|
|
|
12 |
# Function to generate responses from the model
|
13 |
def generate_response(input_text):
|
14 |
inputs = tokenizer(input_text, return_tensors="pt")
|
15 |
+
input_ids = inputs["input_ids"].to(model.device)
|
16 |
+
attention_mask = inputs["attention_mask"].to(model.device)
|
17 |
+
|
18 |
+
# Generate the output
|
19 |
+
outputs = model.generate(input_ids=input_ids, attention_mask=attention_mask, max_new_tokens=512)
|
20 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
+
|
22 |
return response
|
23 |
|
24 |
# Define the Gradio interface
|