@ -1042,13 +1042,14 @@ class Program(object):
Returns ( Program ) :
The cloned Program object .
"""
p = Program ( )
if for_test :
p . desc = core . inference_optimize ( self . desc )
p = self . inference_optimize ( )
else :
p = Program ( )
p . desc = core . ProgramDesc ( self . desc )
p . blocks = [ Block ( p , i ) for i in xrange ( self . desc . num_blocks ( ) ) ]
p . sync_with_cpp ( )
p . blocks = [ Block ( p , i ) for i in xrange ( self . desc . num_blocks ( ) ) ]
p . sync_with_cpp ( )
p . copy_param_info_from ( self )
return p
@ -1061,7 +1062,7 @@ class Program(object):
if isinstance ( t , Variable ) :
# After transpiler processing, the op that output this
# variable maybe has been changed, so t.op is not reliable
# and we need to find the current op that generate this
# and we need to find the current op that generate this
# variable here.
t . op = None
global_block = self . global_block ( )
@ -1087,8 +1088,16 @@ class Program(object):
return res
def inference_optimize ( self ) :
# this is an alternative implement before
# core.inference_optimize being fixed.
res = Program ( )
res . desc = core . inference_optimize ( self . desc )
res . desc = core . ProgramDesc ( self . desc )
for i in xrange ( res . desc . num_blocks ( ) ) :
block = res . desc . block ( i )
for j in xrange ( block . op_size ( ) ) :
op = block . op ( j )
if op . has_attr ( ' is_test ' ) :
op . set_attr ( ' is_test ' , True )
res . blocks = [ Block ( res , i ) for i in xrange ( res . desc . num_blocks ( ) ) ]
res . sync_with_cpp ( )
return res