Skip to content

Commit a6b2441

Browse files
committed
Fix the invalid list operation on save_inference_model function.
test=develop
1 parent 6c71c1f commit a6b2441

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

python/paddle/fluid/io.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ def save_inference_model(dirname,
637637
if isinstance(target_vars, Variable):
638638
target_vars = [target_vars]
639639
elif export_for_deployment:
640-
if not (bool(target_vars) and all(
641-
isinstance(var, Variable) for var in target_vars)):
640+
if not (bool(target_vars) and
641+
all(isinstance(var, Variable) for var in target_vars)):
642642
raise ValueError("'target_vars' should be a list of Variable.")
643643

644644
if main_program is None:
@@ -667,10 +667,15 @@ def save_inference_model(dirname,
667667
if export_for_deployment:
668668
main_program = main_program.clone()
669669
global_block = main_program.global_block()
670+
need_to_remove_op_index = []
670671
for i, op in enumerate(global_block.ops):
671672
op.desc.set_is_target(False)
672673
if op.type == "feed" or op.type == "fetch":
673-
global_block._remove_op(i)
674+
need_to_remove_op_index.append(i)
675+
676+
for index in need_to_remove_op_index[::-1]:
677+
global_block._remove_op(index)
678+
674679
main_program.desc.flush()
675680

676681
main_program = main_program._prune(targets=target_vars)

0 commit comments

Comments
 (0)