打开微信,使用扫一扫进入页面后,点击右上角菜单,
点击“发送给朋友”或“分享到朋友圈”完成分享
matmul算子转Pytorch是会报错
import torch
from torch import nn
from torch.nn import functional as F
import torch_mlu
import torch_mlu.core.mlu_model as ct
import torch_mlu.core.mlu_quantize as mlu_quantize
class NetWork(nn.Module):
def __init__(self):
super(NetWork, self).__init__()
self.conv2d_50 = nn.Conv2d(stride=[1, 1], padding=[1, 1], dilation=[1, 1], groups=1, bias=False, in_channels=8, out_channels=8, kernel_size=[3, 3])
self.conv2d_50.weight.data.normal_(0.0,0.02)
self.relu = nn.ReLU()
def forward(self, image):
image = self.conv2d_50(image)
image = self.relu(image)
image2 = self.conv2d_50(image)
image2 = self.relu(image2)
result = torch.matmul(image, image2)
return result
#return image
torch.set_grad_enabled(False)
model = NetWork()
image = torch.randn([1, 8,15,15])
out = model(image)
qconfig = {'iteration': 2, 'firstconv': False, 'mean':[0.485,0.456,0.406], 'std':[0.229,0.224,0.225]}
quantized_model = torch_mlu.core.mlu_quantize.quantize_dynamic_mlu(model, qconfig, dtype='int8', gen_quant=True)
out = quantized_model(image)
torch.save(quantized_model.state_dict(), "test_matmul_quantize.pth")
quantized_model = torch_mlu.core.mlu_quantize.quantize_dynamic_mlu(model)
state_dict = torch.load("test_matmul_quantize.pth")
quantized_model.load_state_dict(state_dict)
ct.set_core_number(4)
ct.set_core_version('MLU220')
ct.set_device(-1)
ct.set_input_format(0)
ct.save_as_cambricon("./test_matmul")
randn_mlu = image
randn_mlu = randn_mlu.to(ct.mlu_device())
quantized_model.to(ct.mlu_device())
net_traced = torch.jit.trace(quantized_model, randn_mlu, check_trace=False)
net_traced(randn_mlu)
###########################################################################
错误信息如下:
(pytorch_mlu) [root@localhost paddle2pytorch]# python test_matmul.py
CNML: 7.10.2 ba20487
CNRT: 4.10.1 8532541
2023-10-12 10:19:49.359124: [cnrtWarning] [744912] [Card : NONE] Failed to initialize CNDEV. Host manage interface disabled
2023-10-12 10:19:49.363088: [cnrtError] [744912] [Card : NONE] No MLU can be found !
2023-10-12 10:19:49.363106: [cnrtError] [744912] [Card : NONE] Error occurred in cnrtInit during calling driver interface.
2023-10-12 10:19:49.363117: [cnrtError] [744912] [Card : NONE] Return value is 5, MLU_ERROR_NO_DEVICE, means that "No useful mlu device"
2023-10-12 10:19:49.363141: [cnmlError] No MLU device
2023-10-12 10:19:49.363318: [cnmlError] No MLU device
WARNING:root:The 'iteration' key in qconfig has been deprecated in this version. Users needn't
set this key. We will calculate quantization parameters by real forward times controlled by users.
WARNING:root:
You are using conv, but set mean and std. Mean and std are only used
for first conv, which will not be used in the situation. Please do not set them!
2023-10-12 10:19:49.440627: [cnrtError] [744912] [Card : NONE] input param is invalid device handle in cnrtSetCurrentDevice
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
[WARNING][/pytorch/catch/torch_mlu/csrc/jit/passes/segment_graph.cpp][line:41][MLUSupport][thread:140522997507904][process:744912]:
[Fusion Segment] Please check mlu_functions.yaml && Maybe MLU fusion does NOT supports op: matmul
%31 : Tensor = aten::matmul(%input.3, %image2), scope: NetWork # test_matmul.py:23:0
Traceback (most recent call last):
File "test_matmul.py", line 54, in <module>
net_traced(randn_mlu)
File "/mnt/disk1/anaconda3/envs/pytorch_mlu/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(*input, **kwargs)
RuntimeError: isTensor() INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/core/ivalue_inl.h:86, please report a bug to PyTorch. Expected Tensor but got IntList
The above operation failed in interpreter, with the following stack trace:
test_matmul.py(23): forward
/mnt/disk1/anaconda3/envs/pytorch_mlu/lib/python3.6/site-packages/torch/nn/modules/module.py(525): _slow_forward
/mnt/disk1/anaconda3/envs/pytorch_mlu/lib/python3.6/site-packages/torch/nn/modules/module.py(539): __call__
/mnt/disk1/anaconda3/envs/pytorch_mlu/lib/python3.6/site-packages/torch/jit/__init__.py(997): trace_module
/mnt/disk1/anaconda3/envs/pytorch_mlu/lib/python3.6/site-packages/torch/jit/__init__.py(858): trace
test_matmul.py(53): <module>
热门帖子
精华帖子