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

Method compile

python/paddle/base/compiler.py:1154–1285  ·  view source on GitHub ↗

This interface is used to compile the input Program to a program to run the model on the ipu. Args: feed_list(list): This parameter represents the input Tensors of the model. fetch_list(list): This parameter represents the Tensors that need to be re

(self, feed_list: list[str], fetch_list: list[str])

Source from the content-addressed store, hash-verified

1152 self._backend = core.IpuBackend.get_instance()
1153
1154 def compile(self, feed_list: list[str], fetch_list: list[str]) -> Program:
1155 """
1156 This interface is used to compile the input Program to a program
1157 to run the model on the ipu.
1158
1159 Args:
1160 feed_list(list): This parameter represents the input Tensors of the model.
1161
1162 fetch_list(list): This parameter represents the Tensors that need to be returned
1163 after the model.
1164
1165 Returns:
1166 Program
1167
1168 Example:
1169 .. code-block:: pycon
1170
1171 >>> # doctest: +REQUIRES(env:IPU)
1172
1173 >>> import paddle
1174 >>> import paddle.static as static
1175
1176 >>> paddle.enable_static()
1177
1178 >>> a = static.data(name='data', shape=[None, 1], dtype='int32')
1179 >>> b = a + 1
1180 >>> main_prog = static.default_main_program()
1181
1182 >>> ipu_strategy = static.IpuStrategy()
1183 >>> ipu_strategy.set_graph_config(num_ipus=1, is_training=True, micro_batch_size=1)
1184 >>> ipu_strategy.set_pipelining_config(
1185 ... enable_pipelining=False,
1186 ... batches_per_step=1,
1187 ... enable_gradient_accumulation=False,
1188 ... accumulation_factor=1,
1189 ... )
1190 >>> ipu_strategy.set_precision_config(enable_fp16=False)
1191
1192 >>> program = static.IpuCompiledProgram(
1193 ... main_prog,
1194 ... ipu_strategy=ipu_strategy,
1195 ... ).compile([a.name], [b.name])
1196 """
1197 self._backend.set_scope(self._scope)
1198 self._backend.set_ipu_strategy(self._ipu_strategy._ipu_strategy)
1199
1200 # feed and fetch doesn't have corresponding popart op, so we rm both here
1201 global_block = self._program.global_block()
1202 need_to_remove_op_index = []
1203 for i, op in enumerate(global_block.ops):
1204 op.desc.set_is_target(False)
1205 if op.type == 'feed' or op.type == 'fetch':
1206 need_to_remove_op_index.append(i)
1207
1208 for index in need_to_remove_op_index[::-1]:
1209 global_block._remove_op(index)
1210
1211 for var in ['feed', 'fetch']:

Callers 15

run_modelMethod · 0.95
_test_baseMethod · 0.95
TestDistTrainingFunction · 0.95
TestFunction · 0.95
extract_code_blocksFunction · 0.45
commitlist.pyFile · 0.45
get_all_kernelsFunction · 0.45
parse_input_and_attrMethod · 0.45
_slot_patternFunction · 0.45

Calls 12

global_blockMethod · 0.80
_remove_opMethod · 0.80
_remove_varMethod · 0.80
_construct_from_descMethod · 0.80
appendMethod · 0.45
has_varMethod · 0.45
flushMethod · 0.45
GraphMethod · 0.45
applyMethod · 0.45
setMethod · 0.45
ProgramDescMethod · 0.45
varMethod · 0.45

Tested by 15

run_modelMethod · 0.76
_test_baseMethod · 0.76
TestDistTrainingFunction · 0.76
TestFunction · 0.76
catch_errorMethod · 0.36
convert_place_to_deviceFunction · 0.36
parse_kernels_nameFunction · 0.36
test_subgraphMethod · 0.36
run_op_testMethod · 0.36
_test_optimizerMethod · 0.36
run_modelMethod · 0.36
run_modelMethod · 0.36