Repository navigation
Closed
Labels
comp:xlaXLAstaleThis label marks the issue/pr stale - to be closed automatically if no activitystat:awaiting responseStatus - Awaiting response from authortype:bugBug
Description
With master branch as of 831a555 (May 26):
The xla hlo to lhlo lowering doesn't convert completely when the operand of an op (in this example below, that of broadcast_in_dim) is a constant tensor. To reproduce, please use:
func @main(%arg0: tensor<4x64x128x3xf32>, %arg1: tensor<5x3x3x10xf32>) {
%cst = constant dense<0.000000e+00> : tensor<f32>
%0 = "xla_hlo.broadcast_in_dim"(%cst) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>) -> tensor<4x30x42x10xf32>
return
}
and
$ tf-opt -hlo-legalize-to-lhlo constant-tensor-lowering.mlir
constant-tensor-lowering.mlir:3:8: error: 'xla_lhlo.broadcast_in_dim' op operand #0 must be memref of floating-point or signless integer or complex-type values, but got 'tensor<f32>'
%0 = "xla_hlo.broadcast_in_dim"(%cst) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>) -> tensor<4x30x42x10xf32>
^
constant-tensor-lowering.mlir:3:8: note: see current operation: "xla_lhlo.broadcast_in_dim"(%cst, %0) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>, memref<4x30x42x10xf32>) -> ()
Using -print-ir-after-all reveals the operand for the lhlo broadcast_in_dim op wasn't converted to a memref:
tuple.mlir:4:10: error: 'xla_lhlo.broadcast_in_dim' op operand #0 must be memref of floating-point or signless integer or complex-type values, but got 'tensor<f32>'
%0 = "xla_hlo.broadcast_in_dim"(%cst) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>) -> tensor<4x30x42x10xf32>
^
tuple.mlir:4:10: note: see current operation: "xla_lhlo.broadcast_in_dim"(%cst, %0) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>, memref<4x30x42x10xf32>) -> ()
// *** IR Dump After mlir::detail::VerifierPass Failed ***
"module"() ( {
"func"() ( {
^bb0(%arg0: memref<4x64x128x3xf32>, %arg1: memref<5x3x3x10xf32>): // no predecessors
%cst = "std.constant"() {name = "constant.5", value = dense<0.000000e+00> : tensor<f32>} : () -> tensor<f32>
%0 = "std.alloc"() : () -> memref<4x30x42x10xf32>
"xla_lhlo.broadcast_in_dim"(%cst, %0) {broadcast_dimensions = dense<[]> : tensor<0xi64>, name = "broadcast.6"} : (tensor<f32>, memref<4x30x42x10xf32>) -> ()
%1 = "std.alloc"() : () -> memref<4x30x42x10xf32>
"xla_lhlo.convolution"(%arg0, %arg1, %1) {batch_group_count = 1 : i64, dimension_numbers = {input_batch_dimension = 0 : i64, input_feature_dimension = 3 : i64, input_spatial_dimensions = dense<[1, 2]> : tensor<2xi64>, kernel_input_feature_dimension = 2 : i64, kernel_output_feature_dimension = 3 : i64, kernel_spatial_dimensions = dense<[0, 1]> : tensor<2xi64>, output_batch_dimension = 0 : i64, output_feature_dimension = 3 : i64, output_spatial_dimensions = dense<[1, 2]> : tensor<2xi64>}, feature_group_count = 1 : i64, lhs_dilations = dense<1> : tensor<2xi64>, name = "convolution.4", padding = dense<0> : tensor<2x2xi64>, precision_config = ["DEFAULT", "DEFAULT"], rhs_dilations = dense<1> : tensor<2xi64>, window_strides = dense<[2, 3]> : tensor<2xi64>} : (memref<4x64x128x3xf32>, memref<5x3x3x10xf32>, memref<4x30x42x10xf32>) -> ()
%2 = "std.alloc"() : () -> memref<4x30x42x10xf32>
"xla_lhlo.maximum"(%0, %1, %2) {name = "maximum.7"} : (memref<4x30x42x10xf32>, memref<4x30x42x10xf32>, memref<4x30x42x10xf32>) -> ()
"xla_lhlo.terminator"() : () -> ()
}) {sym_name = "main", type = (memref<4x64x128x3xf32>, memref<5x3x3x10xf32>) -> ()} : () -> ()
"module_terminator"() : () -> ()
}) : () -> ()
This is nothing specific to broadcast_in_dim (happens with say xla_hlo.add as well). This is likely a missing conversion for std.constant that needs to be completed?
Metadata
Metadata
Assignees
Labels
comp:xlaXLAstaleThis label marks the issue/pr stale - to be closed automatically if no activitystat:awaiting responseStatus - Awaiting response from authortype:bugBug
Activity
Saduf2019 commentedon May 27, 2020
@bondhugula
Please share simple stand alone code for us to replicate the issue faced.
bondhugula commentedon May 27, 2020
But that's exactly what I provided above - it's a 2-line MLIR standalone test input. Did you expect something else?
bondhugula commentedon May 29, 2020
@r4nt Please assign this issue to me - I'll add the missing rewrites needed to get this working. @MaheshRavishankar @joker-eph for visibility and their information.
MaheshRavishankar commentedon May 29, 2020
THanks Uday! But is the expectation to have xla_hlo.const and I think there is a conversion from xla_hlo.const to xla_lhlo.const. Then the conversion to memref does work. I am not sure there is an expectation to mix dialects as in your example. But I dont see any reason not to have such a pattern, but maybe you could reuse some of the conversion from hlo -> lhlo for std -> lhlo conversion.
bondhugula commentedon May 29, 2020
Dumping an XLA protobuf and using tf-mlir-translate -hlo-to-mlir-hlo actually yields such an input (std.constant instead of an xla_hlo.const). xla_hlo.const -> xla_lhlo.const would work, but the -hlo-legalize-to-lhlo pass could potentially be presented with such an input in other ways, and so making -hlo-to-mlir-hlo generate hlo.const isn't a real solution. The std.constant in these cases is isomorphic to xla_hlo.const (generates the same result type), and so as you point out, we could reuse the conversion pattern hlo -> lhlo. Since this is really "a terminal conversion" (tensor operands of some ops get their values from std.constants) and that we can't generate constant memrefs from std.constant, I guess it's fine to have this conversion pattern live in hlo_legalize_to_lhlo.
19 remaining items
joker-eph commentedon Jun 9, 2020
This makes sense to me as well: seems like a good application of transitive lowering here, isn't it?
bondhugula commentedon Jun 9, 2020
But where would you have this pattern live? I'm completely fine with this as long as this pattern can run as part of -hlo-legalize-to-lhlo. If not, it's weirder to have to run a separate pass do std to hlo, and I don't see how this solves the original issue. I would then prefer having std.const to lhlo.const in the hlo to lhlo conversion which was the original proposal.
joker-eph commentedon Jun 10, 2020
Why doesn't it solve the original issue? If you're pipeline is always including -std-to-hlo before -hlo-to-lhlo shouldn't this just work then?
Note that in practice in a real pipeline, one would include all the patterns to legalize to HLO, include the STD->HLO, and legalize there as a single pass before running the LHLO buffer alloc.
bondhugula commentedon Jun 10, 2020
The original issue was of making the -hlo to lhlo pass deal with this input.
A new pass std to hlo just for this?! What other conversions do you foresee that to have? The conversion looks backwards intuitively.
joker-eph commentedon Jun 10, 2020
Such passes are mostly testing passes, they can't support the world. This is the case with most passes that are loading A->B conversion pattern right now. If you want A+C->B you need another pass loading the right set of patterns. I don't think there is anything specific to this pass right now.
Why? A lot of
stddialect op can be seen as the same level of abstraction as HLO, using the existing XLA compiler to target TPU from a tensor-level computation involvingstdops could be useful to someone for example.Conversion don't need to be one-way: for example we have a conversion from TF->HLO and from HLO->TF.
bondhugula commentedon Jun 10, 2020
TF -> HLO and HLO -> TF is a different scenario - I assume you have many conversions there. Creating one full pass and file for a std.const to hlo.const sounds needless, and more importantly, getting back to the main question: what's the issue with having std.const to hlo.const in hlo to lhlo? It's just an intermediate step and would anyway converge at lhlo.const. Why shouldn't one have such trivial intermediate patterns for canonicalization or to facilitate / trigger other conversions towards your legal target?
bondhugula commentedon Aug 13, 2020
Bringing this back up: where should the conversion for std.const to hlo.const live? If we do this as a conversion pattern in HLO to LHLO, wouldn't it fail? (since the xla_hlo op generated out of the pattern would have been marked as illegal for the conversion target, making the dialect conversion reset state). Could one add an op rewrite pattern as part of a dialect conversion? I completely forget whether it would make sense (in spite of having reviewed a recent revision updating the documentation of pattern rewriting and dialect conversion).
@joker-eph @sherhut
bhack commentedon May 31, 2021
What is the status of this?
tilakrayal commentedon Jul 31, 2024
Hi,
Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base.
The Tensorflow team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TensorFlow version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate.
Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow space.
github-actions commentedon Aug 8, 2024
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
github-actions commentedon Aug 16, 2024
This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.
google-ml-butler commentedon Aug 16, 2024
Are you satisfied with the resolution of your issue?
Yes
No