Skip to content

Commit a38c151

Browse files
authored
Add GetInputsElementDim (#6091)
1 parent 1238706 commit a38c151

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
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/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);

0 commit comments

Comments
 (0)