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])
| 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']: |