-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unreferenced variables from ProgramDesc in prune() #7890
Remove unreferenced variables from ProgramDesc in prune() #7890
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input -> input_var? Because the first argument of this function is named input
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output -> output_var? Because the second argument of this function is named output
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: