Skip to content

Commit

Permalink
Update llvm-project to 204d301
Browse files Browse the repository at this point in the history
This brings in the fix for the obscure RefBackend bug we were hitting.
  • Loading branch information
silvasean committed Sep 29, 2021
1 parent b59f2cb commit 8b2c099
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
8 changes: 2 additions & 6 deletions build_tools/build_standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ llvm_project_dir="$project_dir/external/llvm-project"
build_dir="$project_dir/build"

cmake -GNinja -B"$build_dir" "$llvm_project_dir/llvm" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG -gline-tables-only" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG -gline-tables-only" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS=torch-mlir \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$project_dir" \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_TARGETS_TO_BUILD=host

#-DLLVM_ENABLE_ASSERTIONS=ON \
#

cd "$build_dir"
ninja tools/torch-mlir/all check-torch-mlir-all
6 changes: 0 additions & 6 deletions e2e_testing/torchscript/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ def MmModule_basic(module, tu: TestUtils):
module.forward(tu.rand(4, 4), tu.rand(4, 4))


# TODO: Investigate why RefBackend sometimes can't handle two calls in a row in
# the trace.
# It actually works, if MmModule_chained is run by itself, but if other tests
# are mixed with it, it fails with a mysterious-sounding low level ctypes error
# that exceeds my current ability to debug.
#
@register_test_case(module_factory=lambda: MmModule())
def MmModule_chained(module, tu: TestUtils):
res = module.forward(tu.rand(4, 4), tu.rand(4, 4))
Expand Down
6 changes: 1 addition & 5 deletions e2e_testing/torchscript/xfail_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
'QuantizedMLP_basic',
}

XFAIL_SETS['refbackend'] = _common_torch_mlir_lowering_xfails | {
# The first test in the e2e test batch would fail with SystemError: null
# argument to internal routine. Might be some issue with refbackend.
'MmModule_basic',
}
XFAIL_SETS['refbackend'] = _common_torch_mlir_lowering_xfails

XFAIL_SETS['torchscript'] = {}

Expand Down
57 changes: 57 additions & 0 deletions examples/torchfx/examples/example_add_tanh_sigmoid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- Python -*-
# This file is licensed under a pytorch-style license
# See frontends/pytorch/LICENSE for license information.

# From the torch-mlir root, run with:
# `python -m examples.torchfx.examples.example_add_tanh_sigmoid`
# (after setting up python environment with write_env_file.sh)

import torch
from torch.fx.experimental.fx_acc import acc_tracer
import torch_mlir
from torch_mlir.dialects.torch import register_dialect
from torch_mlir.passmanager import PassManager
from torch_mlir_e2e_test.linalg_on_tensors_backends.refbackend import RefBackendLinalgOnTensorsBackend

from ..builder import build_module
from ..annotator import annotate_forward_args
from ..torch_mlir_types import TorchTensorType


class MyModule(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x, y):
return torch.tanh(x) + torch.sigmoid(y)


module = MyModule()
traced_module = acc_tracer.trace(module, [torch.Tensor(2,2),
torch.Tensor(2,2)])

print("TRACE")
arg_type = TorchTensorType(shape=[None, None], dtype=torch.float)
traced_module = annotate_forward_args(traced_module, [arg_type, arg_type])
print(traced_module.graph)
torch_mlir_module = build_module(traced_module)

print("\n\nTORCH MLIR")
torch_mlir_module.dump()
print(torch_mlir_module.operation.verify())

with torch_mlir_module.context:
pm = PassManager.parse('torchscript-to-linalg-on-tensors-backend-pipeline')
pm.run(torch_mlir_module)

print("\n\nLOWERED MLIR")
torch_mlir_module.dump()

backend = RefBackendLinalgOnTensorsBackend()
compiled = backend.compile(torch_mlir_module)
jit_module = backend.load(compiled)

print("\n\nRunning Forward Function")
t = torch.rand((2, 2), dtype=torch.float)
print("Compiled result:\n", jit_module.forward(t.numpy(), t.numpy()))
print("\nExpected result:\n", module.forward(t, t))
2 changes: 1 addition & 1 deletion external/llvm-project
Submodule llvm-project updated 2370 files
4 changes: 2 additions & 2 deletions lib/Conversion/TorchToLinalg/TorchToLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ static Value getPaddedTensor(Operation *op, OpBuilder &b, Value &input,
Type ranked4DTensorType = linalg::PadTensorOp::inferResultType(
input.getType().cast<RankedTensorType>(), paddingInts, paddingInts);
Value paddedInput = linalg::PadTensorOp::createPadScalarOp(
ranked4DTensorType, input, c0, /*low=*/paddings, /*high=*/paddings, loc,
b);
ranked4DTensorType, input, c0, /*low=*/paddings, /*high=*/paddings,
/*packing=*/false, loc, b);
return paddedInput;
}

Expand Down

0 comments on commit 8b2c099

Please sign in to comment.