打开微信,使用扫一扫进入页面后,点击右上角菜单,
点击“发送给朋友”或“分享到朋友圈”完成分享
CNML和CNRT版本和运行结果如下:
CNML: 7.10.2 0a592c0ee
CNRT: 4.10.1 a884a9a
[WARNING][/pytorch/catch/torch_mlu/csrc/aten/operators/op_methods.cpp][line:1437][min][thread:140534314493760][process:17394]:
min Op cannot run on MLU device, start running on CPU!
double free or corruption (out)
Aborted (core dumped)
运行代码就是用户 寒武纪PyTorch用户手册 中的样例代码,如下:
```python
import torchimport torch.nn as nnimport torch.nn.functional as Fimport torch_mluimport torch_mlu.core.mlu_model as ctimport torch_mlu.core.mlu_quantize as mlu_quantizeimport torchvision.models as modelsct.set_core_number(1)ct.set_core_version("MLU270")torch.set_grad_enabled(False)class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 32, 3, 1) self.conv2 = nn.Conv2d(32, 64, 3, 1) self.dropout1 = nn.Dropout2d(0.25) self.dropout2 = nn.Dropout2d(0.5) self.fc1 = nn.Linear(9216, 128) self.fc2 = nn.Linear(128, 10) def forward(self, x): x = self.conv1(x) x = F.relu(x) x = self.conv2(x) x = F.relu(x) x = F.max_pool2d(x, 2) x = self.dropout1(x) x = torch.flatten(x, 1) x = self.fc1(x) x = F.relu(x) x = self.dropout2(x) x = self.fc2(x) output = F.log_softmax(x, dim=1) return outputnet=Net().eval()torch.save(net.state_dict(), 'test_weights.pth')input_data = torch.rand((1,1,28,28), dtype=torch.float)mean = [0]std = [1/255]net.load_state_dict(torch.load('test_weights.pth', map_location='cpu'), False)net_quantization = mlu_quantize.quantize_dynamic_mlu(net, {'mean':mean, 'std':std, 'firstconv':True}, dtype='int8', gen_quant=True)output = net_quantization(input_data)torch.save(net_quantization.state_dict(), 'test_quantization.pth')net_quantization.load_state_dict(torch.load('test_quantization.pth'))net_mlu = net_quantization.to(ct.mlu_device())input_mlu = input_data.to(ct.mlu_device())output=net_mlu(input_mlu)print(output.cpu())
```
热门帖子
精华帖子