Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,13 +6,14 @@ import torch.nn.functional as F
|
|
6 |
import torch.nn as nn
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
9 |
-
|
10 |
|
11 |
global model, tokenizer
|
12 |
model = AutoModelForSequenceClassification.from_pretrained(
|
13 |
model_path,
|
14 |
num_labels=1,
|
15 |
load_in_8bit=True,
|
|
|
16 |
)
|
17 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
18 |
model.eval()
|
@@ -21,9 +22,8 @@ model.eval()
|
|
21 |
|
22 |
@spaces.GPU(duration=60, enable_queue=True)
|
23 |
def predict(title, abstract):
|
24 |
-
model_device = next(model.parameters()).device
|
25 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
26 |
-
inputs = tokenizer(text, return_tensors="pt")
|
27 |
with torch.no_grad():
|
28 |
outputs = model(**inputs)
|
29 |
probability = torch.sigmoid(outputs.logits).item()
|
|
|
6 |
import torch.nn as nn
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
9 |
+
device = 'cuda:0'
|
10 |
|
11 |
global model, tokenizer
|
12 |
model = AutoModelForSequenceClassification.from_pretrained(
|
13 |
model_path,
|
14 |
num_labels=1,
|
15 |
load_in_8bit=True,
|
16 |
+
device_map={"": torch.device(device)}
|
17 |
)
|
18 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
19 |
model.eval()
|
|
|
22 |
|
23 |
@spaces.GPU(duration=60, enable_queue=True)
|
24 |
def predict(title, abstract):
|
|
|
25 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
26 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
27 |
with torch.no_grad():
|
28 |
outputs = model(**inputs)
|
29 |
probability = torch.sigmoid(outputs.logits).item()
|