(self, program, feed, feed_var_name, scope)
| 1401 | ) |
| 1402 | |
| 1403 | def _feed_data(self, program, feed, feed_var_name, scope): |
| 1404 | # feed var to framework |
| 1405 | global_block = program.global_block() |
| 1406 | for op in global_block.ops: |
| 1407 | if op.desc.type() == 'feed': |
| 1408 | feed_target_name = op.desc.output('Out')[0] |
| 1409 | cur_feed = feed[feed_target_name] |
| 1410 | var = global_block.var(feed_target_name) |
| 1411 | if var.dtype != core.VarDesc.VarType.STRINGS: |
| 1412 | if not isinstance(cur_feed, core.DenseTensor): |
| 1413 | cur_feed = _as_lodtensor( |
| 1414 | cur_feed, self.place, var.dtype |
| 1415 | ) |
| 1416 | check_feed_shape_type(var, cur_feed) |
| 1417 | idx = op.desc.attr('col') |
| 1418 | pir_flag_name = 'FLAGS_enable_pir_in_executor' |
| 1419 | if get_flags(pir_flag_name)[pir_flag_name]: |
| 1420 | core.set_feed_variable( |
| 1421 | scope, cur_feed, feed_target_name, idx |
| 1422 | ) |
| 1423 | else: |
| 1424 | micro_cur_feed = [cur_feed] |
| 1425 | num_micro_batch = 1 |
| 1426 | if ( |
| 1427 | program._pipeline_opt |
| 1428 | and "standalone_opt" in program._pipeline_opt |
| 1429 | ): |
| 1430 | num_micro_batch = program._pipeline_opt[ |
| 1431 | "standalone_opt" |
| 1432 | ]["num_micro_batches"] |
| 1433 | batch_size = ( |
| 1434 | cur_feed.shape()[0] |
| 1435 | if callable(cur_feed.shape) |
| 1436 | else cur_feed.shape[0] |
| 1437 | ) |
| 1438 | assert batch_size % num_micro_batch == 0 |
| 1439 | micro_cur_feed = np.split( |
| 1440 | np.array(cur_feed), num_micro_batch, 0 |
| 1441 | ) |
| 1442 | for i in range(num_micro_batch): |
| 1443 | micro_feed = ( |
| 1444 | _as_lodtensor( |
| 1445 | micro_cur_feed[i], self.place, var.dtype |
| 1446 | ) |
| 1447 | if num_micro_batch > 1 |
| 1448 | else micro_cur_feed[i] |
| 1449 | ) |
| 1450 | core.set_feed_variable( |
| 1451 | scope, |
| 1452 | micro_feed, |
| 1453 | feed_var_name, |
| 1454 | idx * num_micro_batch + i, |
| 1455 | ) |
| 1456 | else: |
| 1457 | break |
| 1458 | |
| 1459 | def _pir_feed_data(self, program, feed, scope, data_op_infos): |
| 1460 | # feed var to framework |
no test coverage detected