-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
New Run() method for framework::Executor #7807
Conversation
paddle/framework/executor.cc
Outdated
@@ -149,5 +150,169 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope, int block_id, | |||
} | |||
} | |||
|
|||
// Return false if the block does not have any feed operators. |
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.
Add description of Check whether the block already has feed operators.
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.
Done
paddle/framework/executor.cc
Outdated
const std::string& feed_holder_name) { | ||
size_t feed_count = 0; | ||
for (auto* op : block->AllOps()) { | ||
if (op->Type() == "feed") { |
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.
op->Type() == "feed"
-> op->Type() == kFeedOpType
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/executor.cc
Outdated
for (auto* op : block->AllOps()) { | ||
if (op->Type() == "feed") { | ||
feed_count++; | ||
PADDLE_ENFORCE(op->Input("X")[0] == feed_holder_name, |
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.
Can we use PADDLE_ENFORCE_EQ
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.
Done
paddle/framework/executor.cc
Outdated
} | ||
|
||
if (feed_count > 0) { | ||
PADDLE_ENFORCE(feed_count == feed_targets.size(), |
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.
Use PADDLE_ENFORCE_EQ
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.
Done
paddle/framework/executor.cc
Outdated
const std::string& fetch_holder_name) { | ||
size_t fetch_count = 0; | ||
for (auto* op : block->AllOps()) { | ||
if (op->Type() == "fetch") { |
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.
op->Type() == "fetch"
-> op->Type() == kFetchOpType
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/executor.cc
Outdated
feed_targets.find(feed_target_name) != feed_targets.end(), | ||
"Feed operator output name '%s' cannot be found in 'feed_targets'", | ||
feed_target_name); | ||
PADDLE_ENFORCE(op->GetAttr("col").type() == typeid(int), |
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.
Do we need to check this?
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.
Removed this.
paddle/framework/executor.cc
Outdated
"'fetch_holder_name' should match the program desc"); | ||
fetch_holder = 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.
Line 228 - 238
is used to check whether there is already a feed_holder
? In my opinion, if has_feed_operators()
returns true, there should exist a feed_holder
and we also check the feed_holder_name
in has_feed_operators()
. Maybe we can simplify the codes.
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.
Great point! Have removed these codes and move the check of feed/fetch_holder_name in has_feed/fetch_operator().
paddle/framework/executor.cc
Outdated
int i = 0; | ||
for (auto& feed_target : feed_targets) { | ||
std::string var_name = feed_target.first; | ||
LOG(INFO) << "feed target's name: " << var_name; |
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.
LOG(INFO) -> VLOG(3)
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.
"Feed operator output name '%s' cannot be found in 'feed_targets'", | ||
feed_target_name); | ||
} else { | ||
break; |
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.
Remove the else
branch. It seems not necessary here.
} | ||
|
||
void Executor::Run(const ProgramDesc& program, Scope* scope, | ||
std::map<std::string, const LoDTensor*>& feed_targets, |
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.
Can we use const LoDTensor&
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.
Reminded by @kexinzhao , it is impossible to use reference in std::map
, https://stackoverflow.com/questions/4239253/c-is-it-possible-to-use-a-reference-as-the-value-in-a-map.
SetFeedVariable(scope, *feed_targets[feed_target_name], feed_holder_name, | ||
idx); | ||
} else { | ||
break; |
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.
Remove the else branch.
@sidgoyal78 we can merge the PR first so that it will not block your work. We can fix the minor code aspects in next PR. |
Fix #7610
The API is a little bit different than in #7610. I encountered memory issue when using
std::map<std::string, LoDTensor>
. So I changed to pointer instead.