MCPcopy
hub / github.com/OpenPPL/ppq / remove_variable

Method remove_variable

ppq/IR/base/graph.py:663–698  ·  view source on GitHub ↗

Remove variable from graph, this function will unlink removing variable from current graph, pop it from graph.variables, and remove it from its source op and dest ops. Args: removing_var (Variable): [description]

(self, removing_var: Variable)

Source from the content-addressed store, hash-verified

661 return self
662
663 def remove_variable(self, removing_var: Variable):
664 """Remove variable from graph, this function will unlink removing
665 variable from current graph, pop it from graph.variables, and remove it
666 from its source op and dest ops.
667
668 Args:
669 removing_var (Variable): [description]
670 """
671 if removing_var.name not in self.variables:
672 raise KeyError(f'Can not remove variable {removing_var.name}, variable not found.')
673
674 # remove from source operation
675 source_op = removing_var.source_op
676 if source_op is not None:
677 assert isinstance(source_op, Operation), (
678 f'Can not remove variable {removing_var.name}, it links to a unexpected source operation.')
679 if removing_var in source_op.outputs:
680 source_op.outputs.remove(removing_var)
681 removing_var.source_op = None
682
683 # remove from all dest ops
684 for dest_op in removing_var.dest_ops:
685 assert isinstance(dest_op, Operation), (
686 f'Can not remove variable {removing_var.name}, it links to a unexpected dest operation.')
687 if removing_var in dest_op.inputs:
688 dest_op.inputs.remove(removing_var)
689 removing_var.dest_ops.clear()
690
691 if removing_var.name in self.outputs:
692 self.outputs.pop(removing_var.name)
693
694 if removing_var.name in self.inputs:
695 self.inputs.pop(removing_var.name)
696
697 self.variables.pop(removing_var.name)
698 return self
699
700 def create_operation(self, op_type: str, name: str = None,
701 attributes: Dict[str, Any] = None, platform: TargetPlatform = TargetPlatform.UNSPECIFIED,

Callers 13

create_link_with_varMethod · 0.95
remove_operationMethod · 0.95
exportMethod · 0.80
delete_isolatedMethod · 0.80
format_parameterMethod · 0.80
fuse_layernormMethod · 0.80
fuse_skiplayernormMethod · 0.80
fuse_geluMethod · 0.80
fuse_selfattentionMethod · 0.80

Calls 2

clearMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected