-
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
add executor.prepare #9022
add executor.prepare #9022
Conversation
paddle/fluid/pybind/pybind.cc
Outdated
return static_cast<void *>(Executor::Prepare(pdesc, block_id)); | ||
}, | ||
py::return_value_policy::reference) | ||
.def_static("delete_prepared_ctx", |
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.
This method is not needed.
We can just return ExecutorPrepareContext
in prepare
method, and make Python delete this object.
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.
@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?
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.
The default policy is OK
… use-executor-prepare
… use-executor-prepare
… use-executor-prepare
paddle/fluid/pybind/pybind.cc
Outdated
@@ -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, |
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.
It seems that __init__
method is not needed
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
paddle/fluid/pybind/pybind.cc
Outdated
int block_id) -> std::unique_ptr<ExecutorPrepareContext> { | ||
return Executor::Prepare(pdesc, block_id); | ||
}, | ||
py::return_value_policy::automatic) |
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.
Default policy is OK
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.
high level question: The plan is to keep prepare as private method called within run, right?
paddle/fluid/pybind/pybind.cc
Outdated
py::class_<framework::Executor>(m, "Executor") | ||
.def(py::init<const platform::Place &>()) | ||
.def_static("prepare", |
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.
_prepare?
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.
I think the visibility can be controlled on the Python side.
paddle/fluid/pybind/pybind.cc
Outdated
int block_id) -> std::unique_ptr<ExecutorPrepareContext> { | ||
return Executor::Prepare(pdesc, block_id); | ||
}) | ||
.def("run_prepared_ctx", |
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.
_run_prepared_ctx
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.
same as above
python/paddle/fluid/executor.py
Outdated
self.program = program | ||
self.fetch_list = fetch_list | ||
self.feed_var_name = feed_var_name | ||
self.fetch_var_name = fetch_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.
Are all of them public members?
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.
yes
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 this class if it's no longer used?
python/paddle/fluid/executor.py
Outdated
@@ -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) |
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.
nit: return at this line?
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
python/paddle/fluid/executor.py
Outdated
|
||
return tmp_program | ||
|
||
def feed_data(self, program, feed, feed_var_name, scope): |
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.
private member?
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
python/paddle/fluid/executor.py
Outdated
] | ||
return outs | ||
|
||
def prepare(self, |
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.
private member?
python/paddle/fluid/executor.py
Outdated
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): |
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.
private?
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
exe = Executor(place) | ||
feed = {'a': a_np, 'b': b_np, 'c': c_np} | ||
|
||
prepared_ctx = exe.prepare(feed=feed, fetch_list=[out]) |
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 you plan to expose prepare as a public member?
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.
yes, prepare should be public, because a user should use it directly.
python/paddle/fluid/executor.py
Outdated
core.get_fetch_variable(scope, fetch_var_name, i) | ||
for i in xrange(len(fetch_list)) | ||
] | ||
program = self._add_feed_fetch_ops( |
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.
why is it no longer poping the cached program 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, add back.
python/paddle/fluid/executor.py
Outdated
] | ||
return outs | ||
|
||
def _prepare(self, |
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.
Is _prepare still called in python? If not, we can remove it
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 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.
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.
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.
python/paddle/fluid/executor.py
Outdated
self.program = program | ||
self.fetch_list = fetch_list | ||
self.feed_var_name = feed_var_name | ||
self.fetch_var_name = fetch_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.
Remove this class if it's no longer used?
… use-executor-prepare
No description provided.