matmul 运行太慢
收藏回复举报
matmul 运行太慢
新人帖
发表于2022-11-21 11:29:52
0 查看

设备:Ascend 910 框架:pytorch

当我使用 profiler 查看我的网络运行状态时:

with torch.autograd.profiler.profile(enabled=True, use_npu=True, record_shapes=False, profile_memory=False) as prof:
            pred = self.net(X)
        prof.export_chrome_trace('./resnet_profile.json')

我发现它运行的时间实在是太长了!并且大部分时间都在进行矩阵乘法! true

以下是我的 pytorch 网络:

class Model(torch.nn.Module):
    # 构建模型(简单的卷积神经网络)
    def __init__(self):
        super().__init__()
        # 1,28x28
        self.conv1 = nn.Conv2d(1, 10, 5)  # 10, 24x24
        self.conv2 = nn.Conv2d(10, 20, 3)  # 128, 10x10
        self.fc1 = nn.Linear(20 * 10 * 10, 500)
        self.fc2 = nn.Linear(500, 10)

    def forward(self, x):
        in_size = x.size(0)ss
        out = self.conv1(x)  # 24
        out = F.relu(out)
        out = F.max_pool2d(out, 2, 2)  # 12
        out = self.conv2(out)  # 10
        out = F.relu(out)
        out = out.view(in_size, -1)  # 展开成一维,方便进行FC
        out = self.fc1(out)
        out = F.relu(out)
        out = self.fc2(out)
        out = F.log_softmax(out, dim=1)
        return out

我在 Mindspore 上也试过,也是一样特别慢,希望能给指导一下。

本帖最后由 匿名用户2022/12/28 14:30:43 编辑

我要发帖子