×

签到

分享到微信

打开微信,使用扫一扫进入页面后,点击右上角菜单,

点击“发送给朋友”或“分享到朋友圈”完成分享

MLU220是否可以生成离线模型 解决中 fqyld2023-10-11 20:51:18 回复 4 查看 使用求助
MLU220是否可以生成离线模型
分享到:

【寒武纪硬件产品型号】必填*: MLU220 M.2

【使用操作系统】必填*:ubuntu 20.04

【使用驱动版本】必填*:v1.7.0

MLU220是否无法完成生成离线模型的工作?

我在使用cambrion pytorch的Docker镜像时尝试使用类似以下代码生成离线模型,但是无法成功

import torch
import torch_mlu.core.mlu_model as ct
import torch_mlu.core.mlu_quantize as mlu_quantize

torch.set_grad_enabled(False)

# 实例化模型,量化并放入MLU
model = TestModel()
model_q = mlu_quantize.quantize_dynamic_mlu(model)
model_mlu = model_q.to(ct.mlu_device())

# 随机生成数据,放入MLU
input_data=torch.randn((1,3,480,480))
input_mlu = input_data.to(ct.mlu_device())

# 生成离线模型相关配置
core_number = 4
ct.set_core_number(core_number)
ct.set_core_version('MLU220')
ct.save_as_cambricon('test')

# 生成离线模型
model_trace = torch.jit.trace(model_mlu, input_mlu, check_trace=False)
model_trace(input_mlu) 
torch_mlu.core.mlu_model.save_as_cambricon("")

会报以下错误

[WARNING][/pytorch/catch/torch_mlu/csrc/aten/operators/op_methods.cpp][line:3256][convolution_overrideable][thread:139840088160064][process:427]: 
convolution_overrideable Op cannot run on MLU device, start running on CPU!
Traceback (most recent call last):
  File "test.py", line 23, in <module>
    model_trace = torch.jit.trace(model_mlu, input_mlu, check_trace=False)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/jit/__init__.py", line 858, in trace
    check_tolerance, _force_outplace, _module_class)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/jit/__init__.py", line 997, in trace_module
    module._c._create_method_from_trace(method_name, func, example_inputs, var_lookup_fn, _force_outplace)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 539, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 525, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 345, in forward
    return self.conv2d_forward(input, self.weight)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
    self.padding, self.dilation, self.groups)
RuntimeError: To do for CPU

我尝试把数据都放入CPU看能否生成,也不可以,会报以下错误

[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140009352496960][process:465]: 
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: _convolution
%21 : Float(*, *, *, *) = aten::_convolution(%input, %weight, %3, %22, %23, %24, %13, %25, %4, %13, %13, %20), scope: Conv2d # /torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py:342:0

[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140009352496960][process:465]: 
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: _convolution
%21 : Float(*, *, *, *) = aten::_convolution(%input, %weight, %3, %22, %23, %24, %13, %25, %4, %13, %13, %20), scope: Conv2d # /torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py:342:0

[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140009352496960][process:465]: 
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: _convolution
%21 : Float(*, *, *, *) = aten::_convolution(%input, %weight, %3, %22, %23, %24, %13, %25, %4, %13, %13, %20), scope: Conv2d # /torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py:342:0

[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140009352496960][process:465]: 
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: _convolution
%21 : Float(*, *, *, *) = aten::_convolution(%input, %weight, %3, %22, %23, %24, %13, %25, %4, %13, %13, %20), scope: Conv2d # /torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py:342:0

[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:217][SegmentGraph][thread:140009352496960][process:465]: 
Graph is segmented into 2 subgraphs.
Please check the above WARNING logs which include "[Fusion Segment]" to see whether there are MLU unsupported ops exists in pytorch model.

Traceback (most recent call last):
  File "test.py", line 26, in <module>
    model_trace(input_data)
  File "/torch/venv3/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
RuntimeError: 
r INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/core/jit_type.h:130, please report a bug to PyTorch. 
The above operation failed shape propagation in this context:

The above operation failed in interpreter, with the following stack trace:
所以我想知道是否必须要购买MLU270才能生成离线模型?

版权所有 © 2024 寒武纪 Cambricon.com 备案/许可证号:京ICP备17003415号-1
关闭