Skip to content

Commit c3543f1

Browse files
authored
Merge pull request #42 from lsvih/patch-1
Fix fastHan model loader in cpu-only env
2 parents 9444eca + 1318f16 commit c3543f1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fastHan/FastModel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def __init__(self, model_type='base', url=None):
161161
task_label_map,
162162
self.all_tasks,
163163
ensembledWeightManager=self.ensembledWeightManager)
164-
self.model.load_state_dict(torch.load(model_path))
164+
if torch.cuda.is_available():
165+
self.model.load_state_dict(torch.load(model_path))
166+
else:
167+
self.model.load_state_dict(torch.load(model_path, map_location='cpu'))
165168
self.model.to(self.device)
166169
self.model.eval()
167170
# 加载tokenizer
@@ -653,4 +656,4 @@ def __call__(self,
653656
answer = []
654657
for ans_ in ans:
655658
answer.append(Sentence(ans_, target))
656-
return answer
659+
return answer

0 commit comments

Comments
 (0)