专栏算法工具链export模型报错IndexError: list index out of range

export模型报错IndexError: list index out of range

默认514562026-07-09
221
2

在J6M芯片上,calibration和qat训练都结束了,在导出模型export的时候,报错:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/tensor_dispatch_wrapper.py", line 275, in torch_function
    rets = func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 938, in torch_function
    location = LocationManager.get(op=func, update_user_stack=True)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/location_info.py", line 307, in get
    mod_name, user_stack = self.loc_info_stack[-1]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/workspace/gcu4szh/SOP_remove_dynamic/train.py", line 1268, in <module>
    main()
  File "/usr/local/lib/python3.10/dist-packages/torch/distributed/elastic/multiprocessing/errors/init.py", line 355, in wrapper
    return f(*args, **kwargs)
  File "/workspace/gcu4szh/SOP_remove_dynamic/train.py", line 919, in main
    runquantization_stage(args)
  File "/workspace/gcu4szh/SOP_remove_dynamic/train.py", line 739, in runquantization_stage
    runexport_stage(
  File "/workspace/gcu4szh/SOP_remove_dynamic/train.py", line 641, in runexport_stage
    qat_hbir = hbir_export(
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/deprecate.py", line 284, in wrapped_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/typeguard.py", line 1096, in wrapper
    retval = func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 230, in export
    ret = Exporter.export(
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 1313, in export
    FuncOp.from_py_func(*hbir_inputs, name=name)(forward)
  File "/usr/local/lib/python3.10/dist-packages/hbdk4/compiler/dialects/func.py", line 195, in decorator
    return_values = f(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 1294, in forward
    tensor_struct_repr(JitTensor.get_base(ret))
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 666, in get_base
    "Gathered base tensors {}".format(tensor_struct_repr(base_tensors))
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/misc.py", line 61, in tensor_struct_repr
    x.dtype,
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/tensor_dispatch_wrapper.py", line 286, in torch_function
    + tensor_struct_repr((args, kwargs))
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/misc.py", line 61, in tensor_struct_repr
    x.dtype,
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/quantization/hbdk4/export_hbir/export_hbir.py", line 938, in torch_function
    location = LocationManager.get(op=func, update_user_stack=True)
  File "/usr/local/lib/python3.10/dist-packages/horizon_plugin_pytorch/utils/location_info.py", line 307, in get
    mod_name, user_stack = self.loc_info_stack[-1]
IndexError: list index out of range
算法工具链
技术深度解析征程6
评论2
0/600
  • XZH
    Lv.2

    您好,从堆栈看 IndexError: list index out of range 出现在 Export 阶段的 LocationManager 中,更像是导出器在处理某个前序异常、并尝试补充算子位置信息时触发的二次异常;当前日志里没有保留最初导致导出失败的具体算子信息。建议先确认以下几点:1.导出前模型是否已执行 model.eval(),且导出输入的数量、类型、shape 与模型 forward 完全一致。2.将 export 单独放到单卡/单进程脚本中复现,避免 DDP 包装、训练循环或自定义 hook 对导出上下文造成影响。3.检查 forward 内是否包含动态控制流、Python 容器的动态增删、依赖 tensor 值的分支/循环,或自定义 torch.autograd.Function 等非标准计算逻辑;这类逻辑需要按插件导出要求改写或标注处理。4.确认 horizon_plugin_pytorch、HBDK 与 J6M 对应 OE 包版本匹配,不要混用不同版本环境。

    2026-07-13
    0
    0
  • HuangHui
    Lv.5

    客户您好,鉴于长时间未收到你的答复,我们暂将该问题做关闭处理,如您仍有相同问题,请在新的帖子中重新发起提问,祝您工作愉快!

    2026-08-05
    0
    0