-
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 program cache for executor.py #8744
Add program cache for executor.py #8744
Conversation
… add-program-cache-for-executor
python/paddle/fluid/executor.py
Outdated
return_numpy=True, | ||
use_program_cache=False): | ||
""" | ||
:param program: the program that need to run |
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 is core API. I would suggest more comments. For example, does the program run from begin to end, or does it just run the nodes in the fetch dependency.
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.
Even better, add a small python example of using Executor.
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
:param program: the program that need to run | ||
:param feed: feed variable list | ||
:param fetch_list: fetch variable list | ||
:param feed_var_name: feed_var_name default to '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.
Maybe a bit more comment here? I'm confused about the difference between "fetch_list" and "fetch_var_name". And the meaning of default 'feed'/'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.
done
@@ -225,7 +226,19 @@ def run(self, | |||
feed_var_name='feed', | |||
fetch_var_name='fetch', | |||
scope=None, | |||
return_numpy=True): | |||
return_numpy=True, | |||
use_program_cache=False): |
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 would remove this 'option' and use 'True' by default. Then as a follow up, auto-detect the program change (preferred) and auto invalidate cache.
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.
currently, the cache cannot check if the program has changed, so user need to set this flag if they are sure the program has not changed, so we have to set this to false by default.
python/paddle/fluid/executor.py
Outdated
:param return_numpy: convert the fetched tensor to numpy | ||
:param use_program_cache: set use_program_cache to true if program not changed compare to the last step. | ||
:return: | ||
""" |
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.
more return comment?
python/paddle/fluid/executor.py
Outdated
|
||
for op in global_block.ops: | ||
if use_program_cache: | ||
self.program_caches[program_cache_key] = program_cache |
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.
Maybe limit the number cached here? Save memory if the program change often.
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.
Will drop cache of program_cache_key when use_program_cache is False now.
BTW, in fact, our |
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.
In the future, we want to auto-detect program change and refresh the cache. Currently, user explicitly set to enable cache
@@ -177,6 +193,7 @@ def __init__(self, places): | |||
# TODO(dzhwinter) : only use the first place | |||
self.executor = core.Executor(act_places[0]) | |||
self.places = places | |||
self.program_caches = dict() |
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.
self._program_caches?
name=feed_var_name, | ||
type=core.VarDesc.VarType.FEED_MINIBATCH, | ||
persistable=True) | ||
self.program_caches.pop(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.
why pop here?
program_cache = program.clone() | ||
|
||
if use_program_cache: | ||
self.program_caches[program_cache_key] = program_cache |
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.
Leave a TODO here to avoid caching too many programs?
related issue: #8729