Skip to content

Commit 338f888

Browse files
committed
add more strict check for program cache
1 parent a8fd6d5 commit 338f888

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

python/paddle/fluid/executor.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,24 @@ def run(self,
253253
if scope is None:
254254
scope = global_scope()
255255

256-
program_cache_key = str(feed.keys() + fetch_list)
257-
program_cache = self.program_caches.get(program_cache_key, None)
258-
259-
if program_cache is None or not use_program_cache:
256+
program_cache = None
257+
program_cache_key = None
258+
if use_program_cache:
259+
# find program cache by cache_key
260+
feed_var_names = feed.keys()
261+
fetch_var_names = [var.desc.name() for var in fetch_list]
262+
program_cache_key = str(feed_var_names + fetch_var_names)
263+
program_cache = self.program_caches.get(program_cache_key, None)
264+
if program_cache is not None:
265+
# TODO: should make sure program and program_cache are exactly the same.
266+
if program.desc != program_cache.desc:
267+
program_cache = None
268+
269+
if program_cache is None:
260270
program_cache = program.clone()
261-
self.program_caches[program_cache_key] = program_cache
271+
272+
if use_program_cache:
273+
self.program_caches[program_cache_key] = program_cache
262274

263275
global_block = program_cache.global_block()
264276

0 commit comments

Comments
 (0)