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

Method parse_output

paddle/phi/api/generator/api_base.py:443–489  ·  view source on GitHub ↗
(self, api_name, output_config)

Source from the content-addressed store, hash-verified

441 return inputs, attrs
442
443 def parse_output(self, api_name, output_config):
444 def parse_output_item(output_item):
445 output_type_map = {
446 'Tensor': 'Tensor',
447 'Tensor[]': 'std::vector<Tensor>',
448 }
449 result = re.search(
450 r"(?P<out_type>[a-zA-Z0-9_[\]]+)\s*(?P<name>\([a-zA-Z0-9_@]+\))?\s*(?P<expr>\{[^\}]+\})?",
451 output_item,
452 )
453 assert result is not None, (
454 f"{api_name} : the output config parse error."
455 )
456 out_type = result.group('out_type')
457 assert out_type in output_type_map, (
458 f"{api_name} : Output type error: the output type only support Tensor and Tensor[], \
459 but now is {out_type}."
460 )
461
462 out_name = (
463 'out'
464 if result.group('name') is None
465 else result.group('name')[1:-1]
466 )
467 out_size_expr = (
468 None
469 if result.group('expr') is None
470 else result.group('expr')[1:-1]
471 )
472 return output_type_map[out_type], out_name, out_size_expr
473
474 temp_list = output_config.split(',')
475
476 if len(temp_list) == 1:
477 out_type, out_name, size_expr = parse_output_item(temp_list[0])
478 return [out_type], [out_name], [size_expr]
479 else:
480 out_type_list = []
481 out_name_list = []
482 out_size_expr_list = []
483 for output_item in temp_list:
484 out_type, out_name, size_expr = parse_output_item(output_item)
485 out_type_list.append(out_type)
486 out_name_list.append(out_name)
487 out_size_expr_list.append(size_expr)
488
489 return out_type_list, out_name_list, out_size_expr_list
490
491 def parse_infer_meta(self, infer_meta_config):
492 infer_meta = infer_meta_config

Callers 2

parse_argsMethod · 0.95
parse_forward_configMethod · 0.45

Calls 2

splitMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected