MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _add_fetch_ops

Method _add_fetch_ops

python/paddle/base/executor.py:2785–2821  ·  view source on GitHub ↗
(
        cls, program, fetch_list, fetch_var_name, use_fetch_v2=False
    )

Source from the content-addressed store, hash-verified

2783
2784 @classmethod
2785 def _add_fetch_ops(
2786 cls, program, fetch_list, fetch_var_name, use_fetch_v2=False
2787 ):
2788 tmp_program = program.clone()
2789
2790 global_block = tmp_program.global_block()
2791
2792 if fetch_var_name in global_block.vars:
2793 fetch_var = global_block.var(fetch_var_name)
2794 else:
2795 fetch_var = global_block.create_var(
2796 name=fetch_var_name,
2797 type=core.VarDesc.VarType.FETCH_LIST,
2798 persistable=True,
2799 )
2800
2801 if use_fetch_v2:
2802 fetch_op = 'fetch_v2'
2803 else:
2804 fetch_op = 'fetch'
2805
2806 # append fetch_operators
2807 if not has_fetch_operators(
2808 global_block, fetch_list, fetch_var_name, fetch_op
2809 ):
2810 for i, var in enumerate(fetch_list):
2811 assert isinstance(var, (Variable, str)), (
2812 f"Wrong type for fetch_list[{i}]: {type(var)}"
2813 )
2814 global_block.append_op(
2815 type=fetch_op,
2816 inputs={'X': [var]},
2817 outputs={'Out': [fetch_var]},
2818 attrs={'col': i},
2819 )
2820
2821 return tmp_program
2822
2823 @classmethod
2824 def _remove_fetch_ops(cls, program, fetch_op_name='fetch'):

Callers 1

_apply_single_implMethod · 0.80

Calls 7

global_blockMethod · 0.80
has_fetch_operatorsFunction · 0.70
typeFunction · 0.50
cloneMethod · 0.45
varMethod · 0.45
create_varMethod · 0.45
append_opMethod · 0.45

Tested by

no test coverage detected