Ai
223 Star 1.3K Fork 1.1K

Ascend/samples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
matmul_leakyrelu_custom_test.py 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
诸葛文洵 提交于 2024-08-14 10:22 +08:00 . change names from MatMul to Matmul
#!/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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ascend/samples.git
git@gitee.com:ascend/samples.git
ascend
samples
samples
8.0.RC3

搜索帮助