2021-01-28 08:35:44 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
# This file is licensed under a pytorch-style license
|
|
|
|
# See frontends/pytorch/LICENSE for license information.
|
|
|
|
|
|
|
|
import typing
|
|
|
|
|
|
|
|
import torch
|
|
|
|
import torch_mlir
|
|
|
|
|
|
|
|
# RUN: %PYTHON %s | npcomp-opt | FileCheck %s
|
|
|
|
|
|
|
|
mb = torch_mlir.ModuleBuilder()
|
|
|
|
|
|
|
|
class TestModule(torch.nn.Module):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.i = 3
|
|
|
|
self.f = 42.5
|
|
|
|
|
2021-02-18 03:28:51 +08:00
|
|
|
# CHECK: torch.class_type @[[CLASSTYPE:.*]] {
|
2021-06-16 07:47:53 +08:00
|
|
|
# CHECK: torch.attr "training" : !torch.bool
|
2021-02-18 03:28:51 +08:00
|
|
|
# CHECK: torch.attr "i" : i64
|
|
|
|
# CHECK: torch.attr "f" : f64
|
|
|
|
# CHECK: }
|
2021-06-16 07:47:53 +08:00
|
|
|
# CHECK: %[[TRUE:.*]] = torch.constant.bool true
|
2021-06-16 03:42:51 +08:00
|
|
|
# CHECK: %[[N3:.*]] = torch.constant.int 3 : i64
|
|
|
|
# CHECK: %[[N42:.*]] = torch.constant.float 4.250000e+01
|
2021-01-28 08:35:44 +08:00
|
|
|
# CHECK: %[[MODULE:.*]] = torch.nn_module {
|
|
|
|
# Note: for some reason, Torch always adds a "training" property to all modules.
|
2021-06-16 07:47:53 +08:00
|
|
|
# CHECK: torch.slot "training", %[[TRUE]] : !torch.bool
|
2021-02-18 03:28:51 +08:00
|
|
|
# CHECK: torch.slot "i", %[[N3]] : i64
|
|
|
|
# CHECK: torch.slot "f", %[[N42]] : f64
|
|
|
|
# CHECK: } : !torch.nn.Module<"[[CLASSTYPE:.*]]">
|
2021-01-28 08:35:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
test_module = TestModule()
|
|
|
|
recursivescriptmodule = torch.jit.script(test_module)
|
|
|
|
# TODO: Automatically handle unpacking Python class RecursiveScriptModule into the underlying ScriptModule.
|
|
|
|
mb.import_module(recursivescriptmodule._c)
|
|
|
|
mb.module.operation.print()
|