Repository navigation
Closed
Labels
Description
MLIR modules bound with the Python runtime bindings currently provide incorrect results when returning multiple values (e.g. return a, b) and when returning sequences (e.g. return (a,) or return (a, b)). This is documented in this colab and below:
class PythonTypesModule(tf.Module):
@tf.function(input_signature=[])
def output_tuple_len_0(self):
return tuple()
@tf.function(input_signature=[])
def output_tuple_len_1(self):
return (1.,) # Need to explicitly wrap.
@tf.function(input_signature=[])
def output_tuple_len_2(self):
return 1., 2.
@tf.function(input_signature=[])
def output_tuple_len_3(self):
return 1., 2., 3.module {
func @output_tuple_len_0() attributes {
iree.module.export,
iree.reflection = {abi = "sip", abiv = 1 : i32, sip = "I1!R1!"}
} {
return
}
func @output_tuple_len_1() -> tensor<f32> attributes {
iree.module.export,
iree.reflection = {abi = "sip", abiv = 1 : i32, sip = "I1!R8!S5!k0_0"}
} {
%0 = mhlo.constant dense<1.000000e+00> : tensor<f32>
return %0 : tensor<f32>
}
func @output_tuple_len_2() -> (tensor<f32>, tensor<f32>) attributes {
iree.module.export,
iree.reflection = {abi = "sip", abiv = 1 : i32, sip = "I1!R12!S9!k0_0k1_1"}
} {
%0 = mhlo.constant dense<1.000000e+00> : tensor<f32>
%1 = mhlo.constant dense<2.000000e+00> : tensor<f32>
return %0, %1 : tensor<f32>, tensor<f32>
}
func @output_tuple_len_3() -> (tensor<f32>, tensor<f32>, tensor<f32>) attributes {
iree.module.export,
iree.reflection = {abi = "sip", abiv = 1 : i32, sip = "I1!R17!S13!k0_0k1_1k2_2"}
} {
%0 = mhlo.constant dense<1.000000e+00> : tensor<f32>
%1 = mhlo.constant dense<2.000000e+00> : tensor<f32>
%2 = mhlo.constant dense<3.000000e+00> : tensor<f32>
return %0, %1, %2 : tensor<f32>, tensor<f32>, tensor<f32>
}
}Expected vs actual results:
module.output_tuple_len_1()
expected: [array([1.])]
actual: [None, array([1.])]
module.output_tuple_len_2()
expected: [array([1.]), array([2.])]
actual: [None, array([2.])]
module.output_tuple_len_3()
expected: [array([1.]), array([2.]), array([3.])]
actual: [None, array([2.]), None, array([3.])]IREE itself produces the correct values via iree-run-mlir:
iree/tools/iree-run-mlir \
-export-all \
-iree-hal-target-backends=dylib-llvm-aot \
sequences.mlir
EXEC @output_tuple_len_1
I iree/iree/tools/utils/vm_util.cc:201] result[0]: Buffer<float32[2]>
1xf32=1
EXEC @output_tuple_len_2
I iree/iree/tools/utils/vm_util.cc:201] result[0]: Buffer<float32[2]>
1xf32=1
I iree/iree/tools/utils/vm_util.cc:201] result[1]: Buffer<float32[2]>
1xf32=2
EXEC @output_tuple_len_3
I iree/iree/tools/utils/vm_util.cc:201] result[0]: Buffer<float32[2]>
1xf32=1
I iree/iree/tools/utils/vm_util.cc:201] result[1]: Buffer<float32[2]>
1xf32=2
I iree/iree/tools/utils/vm_util.cc:201] result[2]: Buffer<float32[2]>
1xf32=3
Given this I would guess that there is some error in how the python bindings are interpreting the SIP or with the SIP itself.
Activity
stellaraccident commentedon Apr 5, 2021
Do we have an isolated/minimal repro for this? (I suspect the limitation is unintentional but need to look at something a bit more concrete)
phoenix-meadowlark commentedon Apr 5, 2021
I updated the colab and my post above with the
tf.Modulethat I used to generate the MLIR, and changed the outputs of the module so that they more clearly show what is supposed to be the 1st, 2nd and 3rd outputs.phoenix-meadowlark commentedon Apr 6, 2021
The general pattern is:
Add support for returning Python tuples (#5347)