Verify that the paddings argument to Pad ops has rank 2.

Otherwise legalization of tf.Pad to mhlo.pad was giving the mysterious error
'mhlo.pad' op requires attribute 'edge_padding_low'.

PiperOrigin-RevId: 357017629
Change-Id: I4271f559d8ebc0c43fa35cbdd80a344770b252ea
This commit is contained in:
Richard Uhler 2021-02-11 11:17:07 -08:00 committed by TensorFlower Gardener
parent 8eb7fc2631
commit 84377fe862
2 changed files with 32 additions and 4 deletions

View File

@ -8389,7 +8389,7 @@ def TF_MinimumOp : TF_Op<"Minimum", [NoSideEffect, ResultsBroadcastableShape, TF
TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
}
def TF_MirrorPadOp : TF_Op<"MirrorPad", [NoSideEffect]> {
def TF_MirrorPadOp : TF_Op<"MirrorPad", [NoSideEffect, TF_OperandHasRank<1, 2>]> {
let summary = "Pads a tensor with mirrored values.";
let description = [{
@ -8436,7 +8436,7 @@ rows must be the same as the rank of `input`.}]>:$paddings,
TF_DerivedOperandTypeAttr Tpaddings = TF_DerivedOperandTypeAttr<1>;
}
def TF_MirrorPadGradOp : TF_Op<"MirrorPadGrad", [NoSideEffect]> {
def TF_MirrorPadGradOp : TF_Op<"MirrorPadGrad", [NoSideEffect, TF_OperandHasRank<1, 2>]> {
let summary = [{
Gradient op for `MirrorPad` op. This op folds a mirror-padded tensor.
}];
@ -9315,7 +9315,7 @@ This is the opposite of `unpack`.
let hasFolder = 1;
}
def TF_PadOp : TF_Op<"Pad", [NoSideEffect, TF_FoldOperandsTransposeInterface]> {
def TF_PadOp : TF_Op<"Pad", [NoSideEffect, TF_FoldOperandsTransposeInterface, TF_OperandHasRank<1, 2>]> {
let summary = "Pads a tensor with zeros.";
let description = [{
@ -9363,7 +9363,7 @@ pad(t, paddings) ==> [[0, 0, 0, 0, 0, 0]
}];
}
def TF_PadV2Op : TF_Op<"PadV2", [NoSideEffect]> {
def TF_PadV2Op : TF_Op<"PadV2", [NoSideEffect, TF_OperandHasRank<1, 2>]> {
let summary = "Pads a tensor.";
let description = [{

View File

@ -308,6 +308,34 @@ func @testIncompatibleElementTypes(%arg0: tensor<3x2xf32>, %arg1: tensor<3x2xf32
// -----
func @testPadRank1Paddings(%input: tensor<2xi64>) -> tensor<3xi64> {
%paddings = "tf.Const"() {value = dense<[0, 1]> : tensor<2xi64>} : () -> tensor<2xi64>
// expected-error @+1 {{failed to verify that operand 1 is 2-D}}
%0 = "tf.Pad"(%input, %paddings) : (tensor<2xi64>, tensor<2xi64>) -> tensor<3xi64>
return %0 : tensor<3xi64>
}
// -----
func @testPadV2Rank1Paddings(%input: tensor<2xi64>) -> tensor<3xi64> {
%constant = "tf.Const"() {value = dense<1> : tensor<i64>} : () -> tensor<i64>
%paddings = "tf.Const"() {value = dense<[0, 1]> : tensor<2xi64>} : () -> tensor<2xi64>
// expected-error @+1 {{failed to verify that operand 1 is 2-D}}
%0 = "tf.PadV2"(%input, %paddings, %constant) : (tensor<2xi64>, tensor<2xi64>, tensor<i64>) -> tensor<3xi64>
return %0 : tensor<3xi64>
}
// -----
func @testMirrorPadRank1Paddings(%input: tensor<2xi64>) -> tensor<3xi64> {
%paddings = "tf.Const"() {value = dense<[0, 1]> : tensor<2xi64>} : () -> tensor<2xi64>
// expected-error @+1 {{failed to verify that operand 1 is 2-D}}
%0 = "tf.MirrorPad"(%input, %paddings) { mode = "SYMMETRIC" }: (tensor<2xi64>, tensor<2xi64>) -> tensor<3xi64>
return %0 : tensor<3xi64>
}
// -----
// CHECK-LABEL: func @testReshape(%arg0: tensor<*xf32>, %arg1: tensor<*xf32>, %arg2: tensor<10000xf32>, %arg3: tensor<*xi32>)
func @testReshape(%arg0: tensor<*xf32>, %arg1: tensor<*xf32>, %arg2: tensor<10000xf32>, %arg3: tensor<*xi32>) -> (tensor<100x100xf32>, tensor<*xf32>, tensor<100x100xf32>, tensor<100x100xf32>, tensor<*xf32>, tensor<*xf32>) {
%shape1 = constant dense<100> : tensor<2xi32>