Skip to content
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

Merged
merged 12 commits into from
Jan 26, 2018

Conversation

kexinzhao
Copy link
Contributor

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.

  void Run(const ProgramDesc& program, Scope* scope,
           std::map<std::string, const LoDTensor*>& feed_targets,
           std::map<std::string, LoDTensor*>& fetch_targets,
           const std::string& feed_holder_name = "feed",
           const std::string& fetch_holder_name = "fetch");

@kexinzhao kexinzhao requested review from Xreki and sidgoyal78 January 24, 2018 01:39
@Xreki Xreki added the 预测 原名Inference,包含Capi预测问题等 label Jan 24, 2018
@Xreki Xreki requested a review from luotao1 January 24, 2018 01:50
@@ -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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const std::string& feed_holder_name) {
size_t feed_count = 0;
for (auto* op : block->AllOps()) {
if (op->Type() == "feed") {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

for (auto* op : block->AllOps()) {
if (op->Type() == "feed") {
feed_count++;
PADDLE_ENFORCE(op->Input("X")[0] == feed_holder_name,
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if (feed_count > 0) {
PADDLE_ENFORCE(feed_count == feed_targets.size(),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const std::string& fetch_holder_name) {
size_t fetch_count = 0;
for (auto* op : block->AllOps()) {
if (op->Type() == "fetch") {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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),
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this.

"'fetch_holder_name' should match the program desc");
fetch_holder = var;
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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().

int i = 0;
for (auto& feed_target : feed_targets) {
std::string var_name = feed_target.first;
LOG(INFO) << "feed target's name: " << var_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG(INFO) -> VLOG(3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@sidgoyal78 sidgoyal78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, and seems consistent with the Python version (as modified in #7712). We can merge this first and then I can modify the load() PR accordingly.
LGTM, but will prefer @Xreki to also approve.

"Feed operator output name '%s' cannot be found in 'feed_targets'",
feed_target_name);
} else {
break;
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetFeedVariable(scope, *feed_targets[feed_target_name], feed_holder_name,
idx);
} else {
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the else branch.

@kexinzhao kexinzhao merged commit 788f5c6 into PaddlePaddle:develop Jan 26, 2018
@Xreki
Copy link
Contributor

Xreki commented Jan 26, 2018

@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.

@kexinzhao kexinzhao deleted the new_executor_run branch April 4, 2018 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
预测 原名Inference,包含Capi预测问题等
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants