-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in embeddings pipe #256
Comments
Try this code to check if it runs success >>> from transformers import DPRContextEncoder
>>> DPRContextEncoder.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base") |
No, Still getting same error. I am thinking it is because of ops.text_embedding.dpr |
If you run failed with this code, it means you can't access the huggingface hub to download models. You need to make sure your net can access huggingface hub. |
Change code to this insert_pipe = (
|
Use towhee=1.1.3 and try this code, it works OK in my env. from towhee import pipe, ops, register, operator
from transformers import DPRContextEncoder, DPRContextEncoderTokenizer
import numpy as np
@register
class DPR(operator.NNOperator):
def __init__(self):
self.tokenizer = DPRContextEncoderTokenizer.from_pretrained('facebook/dpr-ctx_encoder-single-nq-base')
self.model = DPRContextEncoder.from_pretrained('facebook/dpr-ctx_encoder-single-nq-base')
self.model.eval()
def __call__(self, text: str):
input_ids = self.tokenizer(text, return_tensors="pt")["input_ids"]
embeddings = self.model(input_ids).pooler_output
return embeddings.squeeze(0).detach().numpy()
insert_pipe = (
pipe.input('id', 'question', 'answer')
.map('question', 'vec', ops.DPR())
.map('vec', 'vec', lambda x: x / np.linalg.norm(x, axis=0))
.output('vec')
) |
Sorry for delayed reply. Yes, this code is working. Thank you |
Hi @ALL,
I am trying to run this code
%%time
from towhee import pipe, ops
import numpy as np
from towhee.datacollection import DataCollection
insert_pipe = (
pipe.input('id', 'question', 'answer')
.map('question', 'vec', ops.text_embedding.dpr(model_name='facebook/dpr-ctx_encoder-single-nq-base'))
.map('vec', 'vec', lambda x: x / np.linalg.norm(x, axis=0))
.map(('id', 'vec'), 'insert_status', ops.ann_insert.milvus_client(host='127.0.0.1', port='19530', collection_name='question_answer'))
.output()
)
import csv
with open('question_answer.csv', encoding='utf-8') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
insert_pipe(*row)
And I am getting the following error
RuntimeError Traceback (most recent call last)
File :10
File ~\anaconda3\lib\site-packages\towhee\runtime\pipeline.py:116, in Pipeline.output(self, *output_schema, **config_kws)
113 dag_dict[self._clo_node]['next_nodes'].append(uid)
115 run_pipe = RuntimePipeline(dag_dict, config=config_kws)
--> 116 run_pipe.preload()
117 return run_pipe
File ~\anaconda3\lib\site-packages\towhee\runtime\runtime_pipeline.py:140, in RuntimePipeline.preload(self)
136 def preload(self):
137 """
138 Preload the operators.
139 """
--> 140 return _Graph(self._dag_repr.nodes, self._dag_repr.edges, self._operator_pool, self._thread_pool)
File ~\anaconda3\lib\site-packages\towhee\runtime\runtime_pipeline.py:64, in _Graph.init(self, nodes, edges, operator_pool, thread_pool, enable_trance)
62 self.features = None
63 self.time_profiler.record(Event.pipe_name, Event.pipe_in)
---> 64 self.initialize()
65 self._input_queue = self._data_queues[0]
File ~\anaconda3\lib\site-packages\towhee\runtime\runtime_pipeline.py:75, in _Graph.initialize(self)
73 node = create_node(self._nodes[name], self._operator_pool, in_queues, out_queues, self._time_profiler)
74 if not node.initialize():
---> 75 raise RuntimeError(node.err_msg)
76 self._node_runners.append(node)
RuntimeError: Node-text-embedding/dpr-0 runs failed, error msg: Create text-embedding/dpr-0 operator text-embedding/dpr:main with args None and kws {'model_name': 'facebook/dpr-ctx_encoder-single-nq-base'} failed, err: Load operator failed, Traceback (most recent call last):
File "C:\Users\Manoj\anaconda3\lib\site-packages\towhee\runtime\nodes\node.py", line 88, in initialize
self._op = self._op_pool.acquire_op(
File "C:\Users\Manoj\anaconda3\lib\site-packages\towhee\runtime\operator_manager\operator_pool.py", line 99, in acquire_op
op = self._op_loader.load_operator(hub_op_id, op_args, op_kws, tag)
File "C:\Users\Manoj\anaconda3\lib\site-packages\towhee\runtime\operator_manager\operator_loader.py", line 151, in load_operator
raise RuntimeError('Load operator failed')
RuntimeError: Load operator failed
I am using towhee 1.0.0
Please help in solving the error. I am have read other issues in this repo and tried those. But still getting the same error.
Thanks in adavance
The text was updated successfully, but these errors were encountered: