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

Method _remove_training_info

python/paddle/base/framework.py:6968–7077  ·  view source on GitHub ↗

This method will create a new program and do following adjustments on it: 1. Remove all variable's `is_parameter` attribute if exist. 2. Remove all variable's `stop_gradient` attribute if exist. Notes: This API is a very low level API. Returns:

(self, clip_extra=True)

Source from the content-addressed store, hash-verified

6966 return res
6967
6968 def _remove_training_info(self, clip_extra=True):
6969 """
6970 This method will create a new program and do following adjustments on it:
6971 1. Remove all variable's `is_parameter` attribute if exist.
6972
6973 2. Remove all variable's `stop_gradient` attribute if exist.
6974
6975 Notes: This API is a very low level API.
6976
6977 Returns:
6978 Program: The new program.
6979 """
6980 res = Program()
6981 res.desc = core.ProgramDesc(self.desc)
6982
6983 res.blocks = [Block(res, i) for i in range(res.desc.num_blocks())]
6984 res._sync_with_cpp()
6985
6986 # Note: The op_role and op_role_var can't be deleted currently,
6987 # and we will try to remove them in the future.
6988 common_clipped_attrs_list = ["op_callstack", "with_quant_attr"]
6989
6990 for i in range(res.desc.num_blocks()):
6991 block = res.desc.block(i)
6992 for var in block.all_vars():
6993 var.clear_is_parameter()
6994 var.clear_stop_gradient()
6995 if not clip_extra:
6996 continue
6997 for op_idx in range(0, block.op_size()):
6998 op = block.op(op_idx)
6999 if op.type() not in OpProtoHolder.instance().op_proto_map:
7000 continue
7001
7002 extra_attrs_map = core.get_op_extra_attrs(op.type())
7003
7004 proto = OpProtoHolder.instance().get_op_proto(op.type())
7005 remove_input_list = []
7006 for name in op.input_names():
7007 find = False
7008 for input_proto in proto.inputs:
7009 if input_proto.name != name:
7010 continue
7011 if input_proto.extra:
7012 remove_input_list.append(name)
7013 find = True
7014 break
7015 if not find:
7016 remove_input_list.append(name)
7017 # The extra input of op will be removed in the future
7018 # for name in remove_input_list:
7019 # op.remove_input(name)
7020
7021 remove_output_list = []
7022 for name in op.output_names():
7023 find = False
7024 for output_proto in proto.outputs:
7025 if output_proto.name != name:

Callers 1

save_inference_modelFunction · 0.80

Calls 15

_sync_with_cppMethod · 0.95
rangeFunction · 0.85
num_blocksMethod · 0.80
get_op_protoMethod · 0.80
input_namesMethod · 0.80
output_namesMethod · 0.80
remove_outputMethod · 0.80
ProgramClass · 0.70
BlockClass · 0.70
ProgramDescMethod · 0.45
blockMethod · 0.45
opMethod · 0.45

Tested by

no test coverage detected