Spaces:
Sleeping
Sleeping
Minh Q. Le
commited on
Commit
·
0935f1b
1
Parent(s):
8cac419
Fixed running on CPU
Browse files
Model/COSMIC/erc_training/predict_epik.py
CHANGED
@@ -42,8 +42,10 @@ def load_model(model_path, args):
|
|
42 |
|
43 |
if cuda:
|
44 |
model.cuda()
|
|
|
|
|
|
|
45 |
|
46 |
-
model.load_state_dict(torch.load(model_path))
|
47 |
model.eval()
|
48 |
|
49 |
return model
|
@@ -91,7 +93,7 @@ def parse_cosmic_args():
|
|
91 |
|
92 |
# Parse arguments input into the cosmic model
|
93 |
parser.add_argument(
|
94 |
-
"--no-cuda", action="store_true", default=
|
95 |
)
|
96 |
parser.add_argument(
|
97 |
"--lr", type=float, default=0.0001, metavar="LR", help="learning rate"
|
|
|
42 |
|
43 |
if cuda:
|
44 |
model.cuda()
|
45 |
+
model.load_state_dict(torch.load(model_path))
|
46 |
+
else:
|
47 |
+
model.load_state_dict(torch.load(model_path, map_location=torch.device("cpu")))
|
48 |
|
|
|
49 |
model.eval()
|
50 |
|
51 |
return model
|
|
|
93 |
|
94 |
# Parse arguments input into the cosmic model
|
95 |
parser.add_argument(
|
96 |
+
"--no-cuda", action="store_true", default=True, help="does not use GPU"
|
97 |
)
|
98 |
parser.add_argument(
|
99 |
"--lr", type=float, default=0.0001, metavar="LR", help="learning rate"
|
Model/COSMIC/feature_extraction/comet/csk_feature_extract.py
CHANGED
@@ -10,10 +10,8 @@ import comet.src.interactive.functions as interactive
|
|
10 |
|
11 |
|
12 |
class CSKFeatureExtractor:
|
13 |
-
def __init__(self, dir="."):
|
14 |
super(CSKFeatureExtractor, self).__init__()
|
15 |
-
|
16 |
-
device = "cpu"
|
17 |
model_file = os.path.join(
|
18 |
dir, "comet/pretrained_models/atomic_pretrained_model.pickle"
|
19 |
)
|
|
|
10 |
|
11 |
|
12 |
class CSKFeatureExtractor:
|
13 |
+
def __init__(self, dir=".", device=0):
|
14 |
super(CSKFeatureExtractor, self).__init__()
|
|
|
|
|
15 |
model_file = os.path.join(
|
16 |
dir, "comet/pretrained_models/atomic_pretrained_model.pickle"
|
17 |
)
|
app/views/__init__.py
CHANGED
@@ -9,7 +9,7 @@ EPIK_MODEL_DIR = PATH_TO_COSMIC + "/erc_training"
|
|
9 |
sys.path.append(PATH_TO_COSMIC)
|
10 |
sys.path.append(EXTRACTORS_PATH)
|
11 |
sys.path.append(EPIK_MODEL_DIR)
|
12 |
-
sys.path.append(
|
13 |
from Model.COSMIC.feature_extraction.comet.csk_feature_extract import (
|
14 |
CSKFeatureExtractor,
|
15 |
)
|
@@ -23,7 +23,7 @@ roberta = RobertaModel.from_pretrained(
|
|
23 |
)
|
24 |
roberta.eval()
|
25 |
|
26 |
-
comet = CSKFeatureExtractor(dir=EXTRACTORS_PATH)
|
27 |
|
28 |
cosmic_args = parse_cosmic_args()
|
29 |
|
|
|
9 |
sys.path.append(PATH_TO_COSMIC)
|
10 |
sys.path.append(EXTRACTORS_PATH)
|
11 |
sys.path.append(EPIK_MODEL_DIR)
|
12 |
+
sys.path.append(".")
|
13 |
from Model.COSMIC.feature_extraction.comet.csk_feature_extract import (
|
14 |
CSKFeatureExtractor,
|
15 |
)
|
|
|
23 |
)
|
24 |
roberta.eval()
|
25 |
|
26 |
+
comet = CSKFeatureExtractor(dir=EXTRACTORS_PATH, device="cpu")
|
27 |
|
28 |
cosmic_args = parse_cosmic_args()
|
29 |
|