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

Method create_variable

ppq/IR/base/graph.py:765–812  ·  view source on GitHub ↗

Create a variable and attach it it current graph. PPQ will automatically generates a name for your variable: PPQ_Variable_{self._num_of_generated_op}. Use this function carefully, cause once your network is quantized, simply create an variable via this function m

(self, name: str = None, value: Any = None, is_parameter: bool = False,
        dest_ops: List[OperationBase] = None, source_op: OperationBase = None, **kwargs)

Source from the content-addressed store, hash-verified

763 return created
764
765 def create_variable(self, name: str = None, value: Any = None, is_parameter: bool = False,
766 dest_ops: List[OperationBase] = None, source_op: OperationBase = None, **kwargs) -> Variable:
767 """Create a variable and attach it it current graph. PPQ will
768 automatically generates a name for your variable:
769 PPQ_Variable_{self._num_of_generated_op}.
770
771 Use this function carefully, cause once your network is quantized,
772 simply create an variable via this function might cause unexpected error.
773 You'd better invoke this function before running your quantizer.
774
775 If dest_ops and source_op is not None, this function will auto link created variable with them.
776
777 Args:
778 name (str, optional): _description_. Defaults to None.
779 value (Any, optional): _description_. Defaults to None.
780 is_parameter (bool, optional): _description_. Defaults to False.
781 dest_ops (List[OperationBase], optional): _description_. Defaults to None.
782 source_op (OperationBase, optional): _description_. Defaults to None.
783
784 Returns:
785 Variable: _description_
786 """
787 if name is None:
788 name = f'PPQ_Variable_{self._num_of_generated_var}'
789 self._num_of_generated_var += 1
790
791 created = Variable(
792 name=name,
793 value=value,
794 is_parameter=is_parameter,
795 dest_ops=dest_ops,
796 source_op=source_op)
797
798 if dest_ops is not None:
799 if not isinstance(dest_ops, list):
800 raise TypeError(f'Parameter dest ops should be a list of Operation, however {type(dest_ops)} was given.')
801 for op in dest_ops:
802 if not isinstance(op, Operation):
803 raise TypeError(f'Parameter dest ops should be a list of Operation, however {type(op)} was given.')
804 op.inputs.append(created)
805
806 if source_op is not None:
807 if not isinstance(source_op, Operation):
808 raise TypeError(f'Parameter dest ops should be an Operation, however {type(source_op)} was given.')
809 op.outputs.append(created)
810
811 self.append_variable(created)
812 return created
813
814 def mark_variable_as_graph_input(self, var: Variable):
815 if not isinstance(var, Variable):

Callers 15

insert_op_on_varMethod · 0.95
insert_op_beforeMethod · 0.95
insert_op_afterMethod · 0.95
create_link_with_opMethod · 0.95
optimizeMethod · 0.80
optimizeMethod · 0.80
exportMethod · 0.80
insert_quantize_nodeMethod · 0.80
insert_quantize_nodeMethod · 0.80

Calls 3

append_variableMethod · 0.95
VariableClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected