Remove AliasWithName placeholder and rename the input/output of it
(predict_net, init_net)
| 597 | |
| 598 | |
| 599 | def fuse_alias_placeholder(predict_net, init_net): |
| 600 | """ Remove AliasWithName placeholder and rename the input/output of it """ |
| 601 | # First we finish all the re-naming |
| 602 | for i, op in enumerate(predict_net.op): |
| 603 | if op.type == "AliasWithName": |
| 604 | assert len(op.input) == 1 |
| 605 | assert len(op.output) == 1 |
| 606 | name = get_pb_arg_vals(op, "name", None).decode() |
| 607 | is_backward = bool(get_pb_arg_vali(op, "is_backward", 0)) |
| 608 | rename_op_input(predict_net, init_net, i, 0, name, from_producer=is_backward) |
| 609 | rename_op_output(predict_net, i, 0, name) |
| 610 | |
| 611 | # Remove AliasWithName, should be very safe since it's a non-op |
| 612 | new_ops = [] |
| 613 | for op in predict_net.op: |
| 614 | if op.type != "AliasWithName": |
| 615 | new_ops.append(op) |
| 616 | else: |
| 617 | # safety check |
| 618 | assert op.input == op.output |
| 619 | assert op.input[0] == op.arg[0].s.decode() |
| 620 | del predict_net.op[:] |
| 621 | predict_net.op.extend(new_ops) |
| 622 | |
| 623 | |
| 624 | # ==== torch/utils_caffe2/graph_transform.py =================================== |
no test coverage detected