2021-09-17 06:18:17 +08:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2021-07-10 03:22:45 +08:00
|
|
|
|
|
|
|
# RUN: %PYTHON %s | FileCheck %s
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
2021-09-28 02:36:44 +08:00
|
|
|
from torch_mlir_e2e_test.torchscript.framework import run_tests, TestUtils
|
|
|
|
from torch_mlir_e2e_test.torchscript.reporting import report_results
|
|
|
|
from torch_mlir_e2e_test.torchscript.registry import register_test_case, GLOBAL_TEST_REGISTRY
|
|
|
|
from torch_mlir_e2e_test.torchscript.configs import TorchScriptTestConfig
|
2021-07-10 03:22:45 +08:00
|
|
|
|
|
|
|
class Submodule2(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def forward(self, lhs, rhs):
|
|
|
|
return torch.mm(lhs, rhs)
|
|
|
|
|
|
|
|
class Submodule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.m2 = Submodule2()
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleWithSubmodule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.m = Submodule()
|
|
|
|
|
|
|
|
|
|
|
|
# CHECK: PASS - "ModuleWithSubmodule_basic"
|
|
|
|
@register_test_case(module_factory=lambda: ModuleWithSubmodule())
|
|
|
|
def ModuleWithSubmodule_basic(module, tu: TestUtils):
|
|
|
|
module.m.m2.forward(tu.rand(4, 4), tu.rand(4, 4))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
config = TorchScriptTestConfig()
|
|
|
|
results = run_tests(GLOBAL_TEST_REGISTRY, config)
|
|
|
|
report_results(results, set())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|