专栏算法工具链Compile阶段Argmax降维报错

Compile阶段Argmax降维报错

已解决
默认435202024-07-03
96
11

1. 芯片型号:J5

2. 天工开物开发包 OpenExplorer 版本:horizon_j5_open_explorer_v1.1.74-py38_20240319
3. 问题定位:模型转换、板端部署

4. 问题具体描述:模型compile阶段加入argmax,提示

 File "/usr/local/lib/python3.8/dist-packages/hbdk/torch_script/parser.py", line 112, in _visit_node

  ret = getattr(aten, func_name)(self, annotated_name, node,

 File "/usr/local/lib/python3.8/dist-packages/hbdk/torch_script/aten_registry.py", line 205, in aten_argmax

  ret = _max_like(builder, annotated_name, node, input, dim, keep_dim,

 File "/usr/local/lib/python3.8/dist-packages/hbdk/torch_script/aten_registry.py", line 111, in _max_like

  assert keep_dim == True, "only supports 4d tensor. reducing dim is not allowed"

AssertionError: only supports 4d tensor. reducing dim is not allowed


算法工具链
征程5
评论1
0/1000
  • kotei左文亮
    Lv.3

    "only supports 4d tensor. reducing dim is not allowed" 这是输入的tensor维度不对啊,有没有检查一下

    2024-07-03
    0
    10
    • 默认43520回复kotei左文亮:

      你好,检查过了,Float训练在这个节点的tensor维度是 [bn,c,256,256]

      pred = self.head(feat) #train: [bn,c,256,256]

      在compile时加入 pred_argmax = pred.argmax(dim=1),会报这个错误

      AssertionError: only supports 4d tensor. reducing dim is not allowed

      在compile时加入 pred_argmax = pred.argmax(dim=1, keepdim=True),会报这个错误

      WARNING: _view_transformer_grid_sample_hz_grid_sample_grid_rescale is useless. iscale vs. oscale: tensor([0.0156]) , tensor([0.0156])

      _aten_argmax_get_val Input element type should be s8 or s16terminate called after throwing an instance of 'std::runtime_error'

       what(): file=1dd407e711313b05866a069639a7ca86bd40be52:4451, in <>, internal error: 

      Please contact HBDK team 

      Aborted (core dumped)

      补充:

      1. argmax未参与float、calib和qat过程,只是最后compile加上的

      2. argmax接的是dequant反量化后的结果

      3. 不接argmax可编译成功

      2024-07-03
      0
    • 默认43520回复默认43520:

      在compile时加入 pred_argmax = pred.argmax(dim=1, keepdim=True) 后

      尝试

      1.取消反量化 -> 报同一错误

      2.取消反量化+argmax前转数据格式 -> 报同一错误

      pred_argmax = QTensor(pred, scale=pred.scale, dtype=torch.int16/torch.int8/torch.ShortTensor/torch.CharTensor, per_channel_axis=pred.per_channel_axis)
      2024-07-03
      0
    • kotei左文亮回复默认43520:
      这是要求哪个维度的最大值 ? 可不可以换成max()
      2024-07-03
      0
    • 默认43520回复kotei左文亮:

      输入是 [1,c,256,256],要求c这个维度的最大值索引

      我试试替换一下

      2024-07-03
      0
    • 默认43520回复kotei左文亮:

      用max()替换也报错

      修改方式:_, pred_argmax = pred.max(dim=1, keepdim=True)

      报错:

      _aten_max_get_val Input element type should be s8 or s16terminate called after throwing an instance of 'std::runtime_error'

       what(): file=1dd407e711313b05866a069639a7ca86bd40be52:4451, in <>, internal error: 

      Please contact HBDK team 

      2024-07-03
      0
    • kotei左文亮回复默认43520:
      根据您上面的输入,自己写一个argmax()函数试一试呢
      2024-07-04
      0
    • 默认43520回复kotei左文亮:

      我看hbdk包里,argmax()和max()都会转成 _max_like,报的错也是在这里

      _aten_argmax_get_val Input element type should be s8 or s16terminate called after throwing an instance of 'std::runtime_error

      这里 s8 or s16terminate 是啥特殊的格式吗?

      2024-07-05
      0
    • kotei左文亮回复默认43520:
      HB_DNN_TENSOR_TYPE_S8张量类型为有符号8bit。HB_DNN_TENSOR_TYPE_S16张量类型为有符号16bit。
      2024-07-08
      0
    • 默认43520回复kotei左文亮:

      好的,谢谢,我再试一下

      2024-07-08
      0
    • kotei左文亮回复默认43520:

      鉴于您长时间未回复,此问题就先关闭了,如还有问题,可再发帖求助。

      2024-07-11
      0