Spaces:
Sleeping
Sleeping
Upload model_utils.py
Browse files- src/model_utils.py +2 -4
src/model_utils.py
CHANGED
@@ -12,11 +12,9 @@ def load_hf_model(model_name, device="cpu"):
|
|
12 |
except NotImplementedError:
|
13 |
# If meta tensor error occurs, use to_empty()
|
14 |
model = model.to_empty(device=device)
|
15 |
-
device_id = 0
|
16 |
-
else:
|
17 |
-
device_id = -1
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
def generate_answer(text_gen, question, context):
|
22 |
prompt = f"Context: {context}\n\nQuestion: {question}\n\nAnswer:"
|
|
|
12 |
except NotImplementedError:
|
13 |
# If meta tensor error occurs, use to_empty()
|
14 |
model = model.to_empty(device=device)
|
|
|
|
|
|
|
15 |
|
16 |
+
# Don't specify device in pipeline when using accelerate
|
17 |
+
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
18 |
|
19 |
def generate_answer(text_gen, question, context):
|
20 |
prompt = f"Context: {context}\n\nQuestion: {question}\n\nAnswer:"
|