Modifies branch_graphs so they have the same input signature. This method reorders and/or adds parameters to each graph in branch_graphs so they have the same input signature, and updates the 'inputs' and 'captured' fields of each graph accordingly. It uses the input tensors from the outer
(branch_graphs, branch_inputs)
| 506 | |
| 507 | |
| 508 | def _make_inputs_match(branch_graphs, branch_inputs): |
| 509 | """Modifies branch_graphs so they have the same input signature. |
| 510 | |
| 511 | This method reorders and/or adds parameters to each graph in branch_graphs so |
| 512 | they have the same input signature, and updates the 'inputs' and 'captured' |
| 513 | fields of each graph accordingly. It uses the input tensors from the outer |
| 514 | graph to avoid duplicating shared arguments. |
| 515 | |
| 516 | Args: |
| 517 | branch_graphs: a `list` of `FuncGraph` |
| 518 | branch_inputs: a `list` of `list`s of `Tensor`s in the outer graph. The |
| 519 | inputs for the corresponding graph in `branch_graphs`. |
| 520 | |
| 521 | Returns: |
| 522 | A new list of Tensors from the outer graph that are the new inputs for each |
| 523 | branch_graph. This is a deduped version of `sum(branch_inputs)`. |
| 524 | """ |
| 525 | assert len(branch_graphs) == len(branch_inputs) |
| 526 | added_inputs = set() |
| 527 | new_inputs = [] |
| 528 | for branch_in in branch_inputs: |
| 529 | for tensor in branch_in: |
| 530 | tensor_id = ops.tensor_id(tensor) |
| 531 | if tensor_id not in added_inputs: |
| 532 | added_inputs.add(tensor_id) |
| 533 | new_inputs.append(tensor) |
| 534 | |
| 535 | for branch_graph, branch_in in zip(branch_graphs, branch_inputs): |
| 536 | input_ids = [ops.tensor_id(t) for t in branch_in] |
| 537 | branch_input_to_param = dict(zip(input_ids, branch_graph.inputs)) |
| 538 | input_list = [] |
| 539 | for in_t in new_inputs: |
| 540 | param = branch_input_to_param.get(ops.tensor_id(in_t)) |
| 541 | if param is None: |
| 542 | param = _create_dummy_input(branch_graph, in_t) |
| 543 | input_list.append(param) |
| 544 | |
| 545 | branch_graph.inputs = input_list |
| 546 | |
| 547 | # Rewrite the FuncGraphs' state to reflect the new inputs. |
| 548 | branch_graph.reset_captures(zip(new_inputs, branch_graph.inputs)) |
| 549 | |
| 550 | return new_inputs |
| 551 | |
| 552 | |
| 553 | def _make_output_composite_tensors_match(op_type, branch_graphs): |
no test coverage detected