Skip to content

Conversation

@jacquesqiao
Copy link
Member

No description provided.

@jacquesqiao jacquesqiao requested a review from reyoung March 13, 2018 09:22
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

});

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

@jacquesqiao jacquesqiao requested a review from panyx0718 March 16, 2018 08:54
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?


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