已关闭
bge-m3 推理脚本 IndexError 报错 #946
zhoutiezhu创建于  2025年12月15日关闭于  2025年12月29日
zhoutiezhu
2025年12月15日 创建

bge-m3 推理脚本 IndexError 报错

Describe the current behavior / 问题描述

按照 ModelZoo-PyTorch 仓中 bge-m3 模型 README 文档的步骤完成源码下载、模型权重准备、依赖安装后,在 Ascend 910B 设备上执行推理脚本 infer.py 时触发 IndexError: list index out of range 异常,导致模型推理流程中断,无法正常输出 embedding 向量。

Environment / 环境信息

  • 硬件平台:Ascend 910B
  • 软件版本:
    • Python:3.10.16
    • CANN/ascend-toolkit:8.0
    • torch:2.5.1
    • torch-npu:2.5.1
    • transformers:4.51.1
    • FlagEmbedding:1.3.4
    • 其他关键依赖:
      • decorator==5.2.1
      • einops==0.8.1
      • numpy==1.26.4
      • PyYAML==6.0.2
      • tokenizers==0.21.1
  • 源码仓地址:https://gitee.com/ascend/ModelZoo-PyTorch.git(ACL_PyTorch/built-in/embedding/bge-m3 目录)
  • 模型权重:通过 git clone https://huggingface.co/BAAI/bge-m3 + git reset --hard 5617a9f 下载

Steps to reproduce the issue / 重现步骤

  1. 克隆 ModelZoo-PyTorch 源码并进入指定目录:
    git clone https://gitee.com/ascend/ModelZoo-PyTorch.git
    cd ModelZoo-PyTorch/ACL_PyTorch/built-in/embedding/bge-m3
    
  2. 下载开源模型源码和权重:
    git clone https://huggingface.co/BAAI/bge-m3
    cd bge-m3
    git reset --hard 5617a9f
    cd ..
    
  3. 安装依赖:
    pip3 install FlagEmbedding transformers==4.51.1
    # 其他基础依赖已参考 requirements.txt 补充安装
    
  4. 设置环境变量并执行推理命令:
    export ASCEND_RT_VISIBLE_DEVICES=0
    python3 infer.py  # 也尝试过指定 --model_path=bge-m3,报错一致
    
  5. 触发 IndexError 异常:
    line 190, in
    output1 = model.encode(sentences1, return_dense=True, return_sparse=True, return_colbert_vecs=True
    ....
    transformers/tokenization_utils_base.py", line 3319, in pad
    if isinstance(encoded_inputs, (list, tuple)) and isinstance(encoded_inputs[0], Mapping):
    IndexError: list index out of range
    

Describe the expected behavior / 预期结果

推理脚本能够正常执行,加载模型权重后对测试语句完成 embedding 编码,输出 dense/sparse/colbert 等向量结果,无报错中断。

关键报错堆栈信息:

Traceback (most recent call last):
  File "infer.py", line 190, in <module>
    output1 = model.encode(sentences1, return_dense=True, return_sparse=True, return_colbert_vecs=True)
  ...
  File "transformers/tokenization_utils_base.py", line 3319, in pad
    if isinstance(encoded_inputs, (list, tuple)) and isinstance(encoded_inputs[0], Mapping):
IndexError: list index out of range

Special notes for this issue/备注

likedislike
Zzhoutiezhu
2025年12月15日 修改了issue 的描述
All_Fun
All_Fun
2025年12月16日 评论:

用昇腾镜像mis-tei:https://www.hiascend.com/developer/ascendhub/detail/07a016975cc341f3a5ae131f2b52399d
可通过 docker run 直接启动或手动进容器执行 bash start.sh 拉起服务(挂载本地模型目录,指定 910B 设备 ID 和端口),最后用 curl 127.0.0.1:8080/embed 发送 POST 请求验证即可

likedislike
zhoutiezhu
2025年12月16日 评论:

已解决,多谢~~

likedislike
Zzhoutiezhu
2025年12月16日 issue类型由 Bug-Report 改变为 缺陷
Nniushiya成员
2025年12月29日 issue状态由 TODO 改变为 DONE
Nniushiya成员
2025年12月29日 关闭了 issue