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

Method decompose_gemm

ppq/IR/morph.py:1121–1155  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1119 return super()._acceptable_command_types
1120
1121 def decompose_gemm(self):
1122 graph = self.graph
1123 interested_ops = []
1124 for operation in graph.operations.values():
1125 if operation.type == 'Gemm':
1126 interested_ops.append(operation)
1127
1128 for op in interested_ops:
1129 assert isinstance(op, Operation)
1130 output_var = op.outputs[0]
1131
1132 if op.num_of_input == 3:
1133 bias_add = graph.create_operation(op_type='Add', platform=op.platform)
1134 bias_var = op.inputs[-1]
1135
1136 graph.create_link_with_op(A=op, B=bias_add)
1137 graph.create_link_with_op(
1138 variable=graph.create_variable(
1139 value=bias_var.value * op.attributes.get('beta', 1), is_parameter=True),
1140 A=None, B=bias_add)
1141
1142 graph.remove_variable(bias_var)
1143 output_var.source_op = bias_add
1144 bias_add.outputs.append(output_var)
1145 op.outputs.remove(output_var)
1146
1147 if op.attributes.get('transA', 0) == 1:
1148 raise ValueError(f'Can not process with operation {op.name}, transA=1 is not allowed.')
1149 if op.attributes.get('alpha', 1) != 1:
1150 op.parameters[0].value *= op.attributes.get('alpha')
1151 if op.attributes.get('transB', 0) == 1:
1152 op.inputs[1].value = op.inputs[1].value.permute(1, 0)
1153
1154 op.type = 'MatMul'
1155 op.attributes.clear()
1156
1157 def decompose_gru(self):
1158 pass

Callers 2

optimizeMethod · 0.95
test_gemm_split.pyFile · 0.80

Calls 6

create_operationMethod · 0.80
create_link_with_opMethod · 0.80
create_variableMethod · 0.80
remove_variableMethod · 0.80
appendMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected