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

add executor.prepare #9022

Merged
merged 18 commits into from
Mar 20, 2018
Merged

Conversation

jacquesqiao
Copy link
Member

No description provided.

return static_cast<void *>(Executor::Prepare(pdesc, block_id));
},
py::return_value_policy::reference)
.def_static("delete_prepared_ctx",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method is not needed.

We can just return ExecutorPrepareContext in prepare method, and make Python delete this object.

Copy link
Member Author

@jacquesqiao jacquesqiao Mar 14, 2018

Choose a reason for hiding this comment

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

@reyoung Ok, I use copy to return the void * now:

    /** Create a new copy of the returned object, which will be owned by
        Python. This policy is comparably safe because the lifetimes of the two
        instances are decoupled. */
    copy,

I am not sure how will Python manage this returned pointer, can you give some information?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The default policy is OK

@@ -414,8 +414,26 @@ All parameter, weight, gradient are variables in Paddle.
self.set_falsenet(net.Clone());
});

py::class_<ExecutorPrepareContext>(m, "ExecutorPrepareContext")
.def("__init__", [](ExecutorPrepareContext &instance, ProgramDesc &desc,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that __init__ method is not needed

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

int block_id) -> std::unique_ptr<ExecutorPrepareContext> {
return Executor::Prepare(pdesc, block_id);
},
py::return_value_policy::automatic)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default policy is OK

Copy link
Member 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

@panyx0718 panyx0718 left a comment

Choose a reason for hiding this comment

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

high level question: The plan is to keep prepare as private method called within run, right?

py::class_<framework::Executor>(m, "Executor")
.def(py::init<const platform::Place &>())
.def_static("prepare",
Copy link
Contributor

Choose a reason for hiding this comment

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

_prepare?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the visibility can be controlled on the Python side.

int block_id) -> std::unique_ptr<ExecutorPrepareContext> {
return Executor::Prepare(pdesc, block_id);
})
.def("run_prepared_ctx",
Copy link
Contributor

Choose a reason for hiding this comment

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

_run_prepared_ctx

Copy link
Member Author

Choose a reason for hiding this comment

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

same as above

self.program = program
self.fetch_list = fetch_list
self.feed_var_name = feed_var_name
self.fetch_var_name = fetch_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.

Are all of them public members?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this class if it's no longer used?

@@ -235,6 +245,119 @@ def parselod(data):
tensor.set_lod(lod)
return tensor

def _get_program_cache(self, feed, fetch_list):
program_cache_key = get_program_cache_key(feed, fetch_list)
program_cache = self.program_caches.get(program_cache_key, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: return at this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

done


return tmp_program

def feed_data(self, program, feed, feed_var_name, scope):
Copy link
Contributor

Choose a reason for hiding this comment

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

private member?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

]
return outs

def prepare(self,
Copy link
Contributor

Choose a reason for hiding this comment

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

private member?

return PreparedContext(handle, program, fetch_list, feed_var_name,
fetch_var_name)

def run_prepared_ctx(self, ctx, feed=None, scope=None, return_numpy=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

private?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

exe = Executor(place)
feed = {'a': a_np, 'b': b_np, 'c': c_np}

prepared_ctx = exe.prepare(feed=feed, fetch_list=[out])
Copy link
Contributor

Choose a reason for hiding this comment

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

do you plan to expose prepare as a public member?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, prepare should be public, because a user should use it directly.

core.get_fetch_variable(scope, fetch_var_name, i)
for i in xrange(len(fetch_list))
]
program = self._add_feed_fetch_ops(
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it no longer poping the cached program here?

Copy link
Member Author

Choose a reason for hiding this comment

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

done, add back.

]
return outs

def _prepare(self,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is _prepare still called in python? If not, we can remove it

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, it can be used for the unit test, we can delete it future when we implement the right program version and cache in the CPP side.

Copy link
Contributor

@panyx0718 panyx0718 Mar 20, 2018

Choose a reason for hiding this comment

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

I think we can test it without using _prepare? if we don't use_program_cache, the run will give us up-to-date result, if we do use program_cache, the executor will give us stale result?

If not necessary, I would prefer to avoid exposing _prepare to python.

panyx0718
panyx0718 previously approved these changes Mar 20, 2018
self.program = program
self.fetch_list = fetch_list
self.feed_var_name = feed_var_name
self.fetch_var_name = fetch_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.

Remove this class if it's no longer used?

@jacquesqiao jacquesqiao merged commit 37a272e into PaddlePaddle:develop Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants