Skip to content

Commit c318aa5

Browse files
authored
Merge pull request #11850 from guochaorong/revert_11496
Revert "Extend fill_zeros_like_op for zero-filling an LoDTensorArray …
2 parents d2ad4a5 + 6a35899 commit c318aa5

File tree

5 files changed

+9
-161
lines changed

5 files changed

+9
-161
lines changed

paddle/fluid/framework/operator.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,6 @@ proto::VarType::Type OperatorWithKernel::IndicateDataType(
748748
t = &var->Get<LoDTensor>();
749749
} else if (var->IsType<SelectedRows>()) {
750750
t = &(var->Get<SelectedRows>().value());
751-
} else if (var->IsType<LoDTensorArray>()) {
752-
const LoDTensorArray& arr = var->Get<LoDTensorArray>();
753-
PADDLE_ENFORCE(arr.size() > 0);
754-
t = &(arr[0]);
755751
}
756752
if (t != nullptr) {
757753
int tmp = static_cast<int>(ToDataType(t->type()));

paddle/fluid/operators/fill_zeros_like_op.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ class FillZerosLikeOp : public framework::OperatorWithKernel {
2626
"Input(X) of FillZerosLikeOp should not be null.");
2727
PADDLE_ENFORCE(ctx->HasOutput("Out"),
2828
"Output(Out) of FillZerosLikeOp should not be null.");
29-
30-
if (ctx->IsRuntime() &&
31-
ctx->GetOutputsVarType("Out")[0] ==
32-
framework::proto::VarType::LOD_TENSOR_ARRAY) {
33-
return; // skip runtime infershape when is tensor array;
34-
}
29+
ctx->SetOutputDim("Out", ctx->GetInputDim("X"));
30+
ctx->ShareLoD("X", /*->*/ "Out");
3531
}
3632
};
3733

@@ -43,7 +39,7 @@ class FillZerosLikeOpMaker : public framework::OpProtoAndCheckerMaker {
4339
AddComment(R"DOC(
4440
FillZerosLike Operator.
4541
46-
Fill up a variable with zeros, supporting both LoDTensor and LoDTensorArray.
42+
Fill up a variable with zeros.
4743
The output will have the same size as the input.
4844
4945
)DOC");

paddle/fluid/operators/fill_zeros_like_op.h

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16-
#include "paddle/fluid/framework/lod_tensor_array.h"
1716
#include "paddle/fluid/framework/op_registry.h"
1817
#include "paddle/fluid/operators/math/math_function.h"
1918

@@ -24,29 +23,12 @@ template <typename DeviceContext, typename T>
2423
class FillZerosLikeKernel : public framework::OpKernel<T> {
2524
public:
2625
void Compute(const framework::ExecutionContext& context) const override {
27-
auto var = context.InputVar("X");
28-
if (var->IsType<framework::LoDTensor>()) {
29-
auto& input = *context.Input<framework::LoDTensor>("X");
30-
auto& output = *context.Output<framework::LoDTensor>("Out");
31-
output.Resize(input.dims());
32-
output.set_lod(input.lod());
33-
output.mutable_data<T>(context.GetPlace());
34-
math::SetConstant<DeviceContext, T> setter;
35-
setter(context.template device_context<DeviceContext>(), &(output),
36-
static_cast<T>(0));
37-
} else if (var->IsType<framework::LoDTensorArray>()) {
38-
auto& input = *context.Input<framework::LoDTensorArray>("X");
39-
auto& output = *context.Output<framework::LoDTensorArray>("Out");
40-
output.resize(input.size());
41-
for (auto i = 0; i < input.size(); i++) {
42-
output[i].Resize(input[i].dims());
43-
output[i].set_lod(input[i].lod());
44-
output[i].mutable_data<T>(context.GetPlace());
45-
math::SetConstant<DeviceContext, T> setter;
46-
setter(context.template device_context<DeviceContext>(), &(output[i]),
47-
static_cast<T>(0));
48-
}
49-
}
26+
auto* out = context.Output<framework::Tensor>("Out");
27+
out->mutable_data<T>(context.GetPlace());
28+
29+
math::SetConstant<DeviceContext, T> setter;
30+
setter(context.template device_context<DeviceContext>(), out,
31+
static_cast<T>(0));
5032
}
5133
};
5234

python/paddle/fluid/layers/nn.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
'relu',
9696
'log',
9797
'crop',
98-
'fill_zeros_like',
9998
]
10099

101100

@@ -5185,40 +5184,3 @@ def crop(x, shape=None, offsets=None, name=None):
51855184
outputs={'Out': out},
51865185
attrs=None if len(attrs) == 0 else attrs)
51875186
return out
5188-
5189-
5190-
def fill_zeros_like(x):
5191-
"""
5192-
This layer takes an input and outputs a variable that has the same structure as
5193-
the input and with all the element values as zero. The variable can be a Tensor
5194-
or TensorArray.
5195-
5196-
.. code-block:: text
5197-
5198-
5199-
Given
5200-
X = [[0, 1, 2, 0],
5201-
[0, 3, 4, 0],
5202-
[0, 0, 0, 0]],
5203-
output is:
5204-
Out = [[0, 0, 0, 0],
5205-
[0, 0, 0, 0],
5206-
[0, 0, 0, 0]].
5207-
5208-
Args:
5209-
x (Variable): The input variable, which could be a tensor or tensor array
5210-
5211-
Returns:
5212-
Variable: The zero-filled variable, which has the same type and shape as
5213-
the input variable.
5214-
5215-
Examples:
5216-
5217-
.. code-block:: python
5218-
y = fluid.layers.fill_zeros_like(x)
5219-
"""
5220-
helper = LayerHelper('fill_zeros_like', **locals())
5221-
out = helper.create_tmp_variable(dtype=x.dtype)
5222-
helper.append_op(
5223-
type='fill_zeros_like', inputs={'X': [x]}, outputs={'Out': [out]})
5224-
return out

python/paddle/fluid/tests/unittests/test_fill_zeros_like_op_for_array.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)