代码拉取完成,页面将自动刷新
#!/usr/bin/python3
# coding=utf-8
#
# Copyright (C) 2023-2024. Huawei Technologies Co., Ltd. All rights reserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# ===============================================================================
import torch
import torch.nn as nn
import torch_npu
from torch_npu.testing.testcase import TestCase, run_tests
import sys, os
sys.path.append(os.getcwd())
import matmul_leakyrelu_custom
torch.npu.config.allow_internal_format = False
class TestCustomMatmulLeakyrelu(TestCase):
def test_matmul_leakyrelu_custom_ops(self):
a = torch.rand([1024, 256], device='cpu', dtype=torch.float16).npu()
b = torch.rand([256, 640], device='cpu', dtype=torch.float16).npu()
bias = torch.randn([640], device='cpu', dtype=torch.float32).npu()
output = matmul_leakyrelu_custom.run_matmul_leakyrelu_custom(a, b, bias)
m = nn.LeakyReLU(0.001)
cpuout = m(torch.matmul(a.cpu().type(output.dtype), b.cpu().type(output.dtype)) + bias.cpu())
self.assertRtolEqual(output, cpuout)
if __name__ == "__main__":
run_tests()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。