From 338f8883b4f9ea2a35431def353084eb400ffcf9 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Mon, 5 Mar 2018 15:45:37 +0800 Subject: [PATCH] add more strict check for program cache --- python/paddle/fluid/executor.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index 4c3b2f6b588..ad6bc16b40f 100644 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -253,12 +253,24 @@ class Executor(object): if scope is None: scope = global_scope() - program_cache_key = str(feed.keys() + fetch_list) - program_cache = self.program_caches.get(program_cache_key, None) - - if program_cache is None or not use_program_cache: + program_cache = None + program_cache_key = None + if use_program_cache: + # find program cache by cache_key + feed_var_names = feed.keys() + fetch_var_names = [var.desc.name() for var in fetch_list] + program_cache_key = str(feed_var_names + fetch_var_names) + program_cache = self.program_caches.get(program_cache_key, None) + if program_cache is not None: + # TODO: should make sure program and program_cache are exactly the same. + if program.desc != program_cache.desc: + program_cache = None + + if program_cache is None: program_cache = program.clone() - self.program_caches[program_cache_key] = program_cache + + if use_program_cache: + self.program_caches[program_cache_key] = program_cache global_block = program_cache.global_block() -- GitLab