Skip to content

Commit 6b18b3c

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/paddle into enhance-include-pool
2 parents cb5a7a8 + 0d40a4d commit 6b18b3c

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

paddle/framework/shape_inference.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ std::vector<framework::DDim> InferShapeContext::GetInputsDim(
2222
return GetDims(names);
2323
}
2424

25+
DDim InferShapeContext::GetInputsElementDim(const std::string &name,
26+
int idx) const {
27+
const std::vector<std::string> &names = Inputs(name);
28+
return this->GetDim(names[idx]);
29+
}
30+
2531
void InferShapeContext::SetOutputsDim(
2632
const std::string &name, const std::vector<framework::DDim> &dims) {
2733
auto &names = Outputs(name);

paddle/framework/shape_inference.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class InferShapeContext {
3737
virtual framework::DDim GetInputDim(const std::string &name) const = 0;
3838

3939
std::vector<framework::DDim> GetInputsDim(const std::string &name) const;
40+
DDim GetInputsElementDim(const std::string &name, int idx) const;
4041

4142
virtual void SetOutputDim(const std::string &name, const DDim &dim) = 0;
4243
void SetOutputsDim(const std::string &name,

paddle/operators/tensor_array_read_write_op.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ class WriteToArrayOp : public ArrayOp {
3737
<< " to " << offset + 1;
3838
out->resize(offset + 1);
3939
}
40-
auto *out_tensor = &out->at(offset);
41-
CopyFrom(x_tensor, dev_ctx.GetPlace(), dev_ctx, out_tensor);
42-
out_tensor->set_lod(x_tensor.lod());
40+
if (x_tensor.memory_size() > 0) {
41+
auto *out_tensor = &out->at(offset);
42+
CopyFrom(x_tensor, dev_ctx.GetPlace(), dev_ctx, out_tensor);
43+
out_tensor->set_lod(x_tensor.lod());
44+
} else {
45+
VLOG(10) << "WARNING: The input tensor 'x_tensor' holds no memory, so "
46+
"nothing has been written to output array["
47+
<< offset << "].";
48+
}
4349
}
4450
};
4551

paddle/operators/while_op.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,21 @@ class WhileGradOpShapeInference : public framework::InferShapeBase {
287287

288288
auto p_names = ctx->Inputs(kParameters);
289289
auto pg_names = ctx->Outputs(kParamGrads);
290-
auto dims = ctx->GetInputsDim(kParameters);
291290
auto var_types = ctx->GetInputsVarType(kParameters);
292291
std::vector<std::string> names_to_set;
293292
std::vector<framework::DDim> dims_to_set;
294293
for (size_t i = 0; i < p_names.size(); ++i) {
295294
if (pg_names[i] == framework::kEmptyVarName) {
296295
continue;
297296
}
297+
auto dims = ctx->GetInputsElementDim(kParameters, i);
298298
if (var_types[i] == framework::VarDesc::LOD_TENSOR) {
299299
names_to_set.push_back(pg_names[i]);
300-
dims_to_set.push_back(dims[i]);
300+
dims_to_set.push_back(dims);
301301
} else if (var_types[i] == framework::VarDesc::LOD_TENSOR_ARRAY) {
302302
// not sure how to set the dim of LOD_TENSOR_ARRAY
303303
names_to_set.push_back(pg_names[i]);
304-
dims_to_set.push_back(dims[i]);
304+
dims_to_set.push_back(dims);
305305
}
306306
}
307307
ctx->SetDims(names_to_set, dims_to_set);

python/paddle/v2/fluid/layers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def data(name,
185185
shape,
186186
append_batch_size=True,
187187
dtype='float32',
188+
lod_level=0,
188189
type=core.VarDesc.VarType.LOD_TENSOR,
189190
main_program=None,
190191
startup_program=None,
@@ -198,6 +199,7 @@ def data(name,
198199
append_batch_size: Whether or not to append the data as a batch.
199200
dtype: The type of data : float32, float_16, int etc
200201
type: The output type. By default it is LOD_TENSOR.
202+
lod_level(int): The LoD Level. 0 means the input data is not a sequence.
201203
main_program: Name of the main program that calls this
202204
startup_program: Name of the startup program
203205
stop_gradient: A boolean that mentions whether gradient should flow.
@@ -228,7 +230,8 @@ def data(name,
228230
shape=shape,
229231
dtype=dtype,
230232
type=type,
231-
stop_gradient=stop_gradient)
233+
stop_gradient=stop_gradient,
234+
lod_level=lod_level)
232235

233236

234237
def create_tensor(dtype, name=None, main_program=None, startup_program=None):

0 commit comments

Comments
 (0)