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

Method create_operation

ppq/IR/base/graph.py:700–763  ·  view source on GitHub ↗

Create an operation and attach it it current graph. op_type is mandatory here, however op_name is not required. PPQ will automatically generates a name for your operation: PPQ_Operation_{self._num_of_generated_op}. Use this function carefully, cause once your network

(self, op_type: str,  name: str = None,
        attributes: Dict[str, Any] = None, platform: TargetPlatform = TargetPlatform.UNSPECIFIED,
        inputs: List[Variable] = None, outputs: List[Variable] = None, **kwargs)

Source from the content-addressed store, hash-verified

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,
702 inputs: List[Variable] = None, outputs: List[Variable] = None, **kwargs) -> Operation:
703 """Create an operation and attach it it current graph. op_type is
704 mandatory here, however op_name is not required. PPQ will automatically
705 generates a name for your operation:
706 PPQ_Operation_{self._num_of_generated_op}.
707
708 Use this function carefully, cause once your network is quantized,
709 simply create an operation via this function might cause unexpected error.
710 Beawre that operation created by this function has no meta data and quantization info,
711 which is needed to export and executing your graph.
712
713 Do not set inputs and outputs via this function,
714 to link your operation with others, use graph.create_link_with_var instead.
715
716 Args:
717 op_type (str): _description_
718 name (str, optional): _description_. Defaults to None.
719 attributes (Dict[str, Any], optional): _description_. Defaults to None.
720 platform (TargetPlatform, optional): _description_. Defaults to TargetPlatform.UNSPECIFIED.
721 inputs (List[Variable], optional): _description_. Defaults to None.
722 outputs (List[Variable], optional): _description_. Defaults to None.
723
724 Returns:
725 Operation: _description_
726 """
727 if inputs is None: inputs = []
728 if outputs is None: outputs = []
729
730 if name is None:
731 name = f'PPQ_Operation_{self._num_of_generated_op}'
732 self._num_of_generated_op += 1
733
734 if not isinstance(inputs, list):
735 raise TypeError(f'A list of input variable is required for creating operation, '
736 f'however {type(inputs)} was given')
737
738 if attributes is None: attributes = {}
739 created = Operation(
740 name=name,
741 op_type=op_type,
742 attributes=attributes,
743 platform=platform,
744 inputs=inputs,
745 outputs=outputs
746 )
747 self.append_operation(created)
748
749 for item in inputs:
750 if not isinstance(item, Variable):
751 raise TypeError(f'A list contains variables is required for creating operation, '
752 f'however there is a {type(item)} in your input list.')
753 item.dest_ops.append(created)
754
755 if not isinstance(outputs, list):
756 raise TypeError(f'A list of output variable is required for creating operation, '
757 f'however {type(inputs)} was given')

Callers 15

optimizeMethod · 0.80
optimizeMethod · 0.80
exportMethod · 0.80
insert_quantize_nodeMethod · 0.80
insert_quantize_nodeMethod · 0.80
_fuseMethod · 0.80
fuse_geluMethod · 0.80
fuse_selfattentionMethod · 0.80
decompose_gemmMethod · 0.80

Calls 3

append_operationMethod · 0.95
OperationClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected