Skip to content

Fix the OpDesc construction in BlockDesc constructor #8174

@kexinzhao

Description

@kexinzhao

for (auto &op : other.ops_) {
ops_.emplace_back(new OpDesc(*op, this));
}

The code above is how the OpDesc is constructed when we call program.clone() on the python side.
This construction will call the following function:

OpDesc(const OpDesc &other, BlockDesc *block) {
*this = other;
block_ = block;
}

Essentially, this calls a default assignment operator that copies the following data members:

proto::OpDesc desc_;
BlockDesc *block_; // not_own
// input arg name => input variable names
VariableNameMap inputs_;
// output arg name => output variable names
VariableNameMap outputs_;
AttributeMap attrs_;

Because the attribute type in the AttributeMap could be a BlockDesc*, cloning program desc in this way, makes for example the BLOCK attribute of the while operator in the copied program desc points to a BlockDesc in the original program desc.

This will be fixed along with #8161

Metadata

Metadata

Assignees

Labels

预测原名Inference,包含Capi预测问题等

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions