问题:

之前写的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以下时正常调用,所以在服务内对批量数据进行了切分处理,并没有尝试上面的解决方法。

RuntimeError: Already borrowed相关推荐

  1. RuntimeError: Expected object of backend CUDA but got backend CPU for argument

    RuntimeError: Expected object of backend CUDA but got backend CPU for argument #4 'mat1' 原因:变量没有加cud ...

  2. RuntimeError: Expected object of device type cuda but got device type cpu for argument pytorch数据位置

    RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'target' i ...

  3. RuntimeError: Assertion cur_target 0 cur_target n_classes failed

    问题描述 使用pytorch的函数 torch.nn.CrossEntropyLoss()计算Loss时报错: RuntimeError: Assertion `cur_target >= 0 ...

  4. hnswlib RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is to sma

    1. 问题现象 index = hnswlib.Index(space = '100', dim = 512) index.init_index(max_elements = 100, ef_cons ...

  5. python导入matplotlib出错_解决导入matplotlib的RuntimeError: Python is not installed as a framework....

    import matplotlib.pyplot as plt 报错: RuntimeError: Python is not installed as a framework. The Mac OS ...

  6. RuntimeError: each element in list of batch should be of equal size

    RuntimeError: each element in list of batch should be of equal size 示例代码: import os import re from t ...

  7. RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel

    RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel ...

  8. 迭代var()内置函数的时候出现RuntimeError: dictionary changed size during iteration的解决办法...

    下午看了Mr Seven的教学视频,其中有一段讲全局变量的视频,迭代输出全局变量的时候报错了. 视频中的做法: for k,v in vars().items():print(k) 打印结果 for ...

  9. xshell virt-manager RuntimeError: could not open display

    使用xshell连接到linux主机,使用virt-manager命令调用kvm的管理界面,结果 [root@instructor ~]# virt-manager Traceback (most r ...

最新文章

  1. 【深度学习】模型训练过程可视化思路(可视化工具TensorBoard)
  2. java:不同数据类型的转换规则
  3. vmware中的Ubuntu安装ssh全家桶(解决connect to host localhost port 22: Connection refused)...
  4. 将 iOS 应用的体积控制在 20MB 以内对于其下载量有很明显的影响吗?
  5. java quartz 2.2.3_java – Spring 3 Quartz 2错误
  6. opengl计算帧率_或许是迄今为止第一篇讲解 fps 计算原理的文章吧
  7. excel range 判断日期型_EXCEL常用函数二
  8. 2020-08-09
  9. IP核授权形式:软核、固核和硬核
  10. 【无人机】【2011.04】【含源码】四旋翼无人机的仿真与控制
  11. 阿里云商标注册怎么样?附上申请步骤流程
  12. DDos/DoS工具集(持续更新)
  13. [系统安全] 反病毒与免杀原理概论
  14. 6.misc类设备与蜂鸣器驱动
  15. oracle中间人投毒漏洞,‘TNS Listener’远程数据投毒漏洞
  16. mongodb-报错FailedToParse: Password must be URL Encoded for mongodb:// URL:
  17. 微信小程序之获取用户地址
  18. 电脑端微信dat文件怎么打开
  19. Hadoop+hive+flask+echarts大数据可视化之系统数据收集
  20. 贝叶斯例题(一)先验分布与后验分布

热门文章

  1. Mysql---表管理
  2. JAVA 好书推荐整理
  3. 20135201李辰希20135219洪韶武——信息安全系统设计基础实验报告
  4. 批量读取文件名和批量改写文件名
  5. 别人家的宝贝会做的我家的宝贝也要会
  6. 计算机详细配置快捷键,Win7电脑快捷键设置的方法
  7. CPU模块的主要组成部分探讨
  8. Gateway网关没有生效
  9. java repaint 重画图形_Java Graphics的paint和repaint方法
  10. 删除前10行sql oracle,sql server 如何实现删除前1000行数据