Remove unreferenced variables from ProgramDesc in prune()#7890
Remove unreferenced variables from ProgramDesc in prune()#7890kexinzhao merged 3 commits intoPaddlePaddle:developfrom
Conversation
| auto* var_field = output->mutable_blocks(block_id)->mutable_vars(); | ||
| for (const auto& var : *var_field) { | ||
| var_map[var.name()] = var; | ||
| } |
There was a problem hiding this comment.
Maybe, there is no need for an extra map. We can directly use var map of input ProgramDesc. We can use input.FindVar(name)->Proto() to get the proto::VarDesc.
There was a problem hiding this comment.
There are two different classes one is framework::proto::xxxDesc, one is framework::xxxDesc. The latter is basically a wrapper about the former.
For this prune function, the input is proto::ProgramDesc, so we only have limited functionality provided by the protobuf library itself. After you compile the framework.proto, you will get framework.pb.h + cc, which lists all the available functions for proto::ProgramDesc and etc.
So I don't think we can use input.FindVar() here.
There was a problem hiding this comment.
Later, when we are going to implement out transpiler function for inference optimization on the c++ side after loading a inference desc from file or buffer, we can use your suggestion, as in that case, we can take a framework::ProgramDesc as input.
@Xreki what do you think?
There was a problem hiding this comment.
For this prune function, the input is
proto::ProgramDesc, so we only have limited functionality provided by the protobuf library itself.
You are right. Sorry for didn't notice that.
paddle/framework/prune.cc
Outdated
| for (const auto& op : *op_field) { | ||
| // add VarDescs of all input arguments for each OpDesc | ||
| auto& input_field = op.inputs(); | ||
| for (auto& input : input_field) { |
There was a problem hiding this comment.
input -> input_var? Because the first argument of this function is named input.
paddle/framework/prune.cc
Outdated
| } | ||
| // add VarDescs of all output arguments for each OpDesc | ||
| auto& output_field = op.outputs(); | ||
| for (auto& output : output_field) { |
There was a problem hiding this comment.
output -> output_var? Because the second argument of this function is named output.
| auto* var_field = output->mutable_blocks(block_id)->mutable_vars(); | ||
| for (const auto& var : *var_field) { | ||
| var_map[var.name()] = var; | ||
| } |
There was a problem hiding this comment.
For this prune function, the input is
proto::ProgramDesc, so we only have limited functionality provided by the protobuf library itself.
You are right. Sorry for didn't notice that.
Fixes #7417
By following similar test procedure as in #7097, we get the testing result as follows: