2021-03-05 05:08:50 +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.s = "foo"
|
|
|
|
# CHECK: torch.class_type @[[CLASSTYPE:.*]] {
|
|
|
|
# TODO: Don't lose element type.
|
2021-06-15 23:29:06 +08:00
|
|
|
# CHECK: torch.attr "s" : !torch.str
|
2021-03-05 05:08:50 +08:00
|
|
|
# CHECK: }
|
2021-06-15 23:29:06 +08:00
|
|
|
# CHECK: %[[STR:.*]] = torch.constant.str "foo"
|
2021-03-05 05:08:50 +08:00
|
|
|
# CHECK: torch.nn_module {
|
2021-06-15 23:29:06 +08:00
|
|
|
# CHECK: torch.slot "s", %[[STR]] : !torch.str
|
2021-03-05 05:08:50 +08:00
|
|
|
# CHECK: } : !torch.nn.Module<"[[CLASSTYPE]]">
|
|
|
|
|
|
|
|
|
|
|
|
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()
|