RuntimeError: Already borrowed
问题:之前写的SBERT模型接口部署上线后最近报了RuntimeError: Already borrowed的错误,在这里记录下。现象:具体的报错如下:File "/home/XXXX/XXX/src/sentence_proc.py", line 77, in compute_sentence_vectorssentences = self.tokenizer(sentences, paddi
问题:
之前写的SBERT模型接口部署上线后最近报了RuntimeError: Already borrowed的错误,在这里记录下。
现象:
具体的报错如下:
File "/home/XXXX/XXX/src/sentence_proc.py", line 77, in compute_sentence_vectors
sentences = self.tokenizer(sentences, padding='max_length', truncation=True, max_length=self.max_seq_length,return_tensors="tf")
File "/home/XXX/.local/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 2249, in __call__
return self.batch_encode_plus(
File "/home/XXXX/.local/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 2434, in batch_encode_plus
return self._batch_encode_plus(
File "/home/XXXX/.local/lib/python3.8/site-packages/transformers/tokenization_utils_fast.py", line 370, in _batch_encode_plus
self.set_truncation_and_padding(
File "/home/XXXX/.local/lib/python3.8/site-packages/transformers/tokenization_utils_fast.py", line 326, in set_truncation_and_padding
self._tokenizer.enable_truncation(max_length, stride=stride, strategy=truncation_strategy.value)
RuntimeError: Already borrowed
讨论:
网上关于这个问题的讨论:https://ask.csdn.net/questions/6983340 ;大致讨论的原因是因为多线程下使用了同一个tokenizer导致的。
因为使用的是huggingface的transformers项目,所以在项目的issues上也看到了这个问题:https://github.com/huggingface/transformers/issues/10434 ;这里面提供的解决方案是使用TFREcord进行数据的转换,再通过文件流的方式读入pipline。
但是最后通过测试,因为是在进行批量问句进行相似计算调用的时候会报错,而且是发生在大批量的时候,当批大小减少到模型训练时batch_size以下时正常调用,所以在服务内对批量数据进行了切分处理,并没有尝试上面的解决方法。
更多推荐
所有评论(0)