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

Method format_gather

ppq/IR/morph.py:290–315  ·  view source on GitHub ↗

gather op 的参数 index 可能由 input variable 给出 但 index 参数不可以被量化,同时后端运算需要其作为Python 原生类型 因此将其转移到 gather op 的属性上。 index parameter of gather op can be given by input variable, however, it can't be quantized, thus we transfer index parameter to attribute of gather op. axis is

(self)

Source from the content-addressed store, hash-verified

288 if 'max' in op.attributes: op.attributes.pop('max')
289
290 def format_gather(self) -> None:
291 """gather op 的参数 index 可能由 input variable 给出 但 index
292 参数不可以被量化,同时后端运算需要其作为Python 原生类型 因此将其转移到 gather op 的属性上。 index parameter
293 of gather op can be given by input variable, however, it can't be
294 quantized, thus we transfer index parameter to attribute of gather op.
295
296 axis is set to 0 when it's not given gather op 的参数 axis 可能不存在,此时强制植入 0
297 作为 axis 参数
298 """
299 interested_ops = []
300 for _, operation in self.graph.operations.items():
301 if operation.type == 'Gather': interested_ops.append(operation)
302 for operation in interested_ops:
303 assert isinstance(operation, Operation)
304 if len(operation.inputs) == 2:
305 index_op = operation.inputs[1].source_op
306 if index_op.type == 'Constant':
307 index = index_op.attributes['value']
308 self.__delete_constant_input(operation, 1)
309 operation.attributes['gather_index'] = convert_any_to_python_primary_type(index)
310 if 'axis' not in operation.attributes:
311 operation.attributes['axis'] = 0
312
313 if 'indices' in operation.attributes:
314 operation.attributes['gather_index'] = operation.attributes['indices']
315 operation.attributes.pop('indices')
316
317 def format_cast(self) -> None:
318 """cast op 的参数 to 默认为 int,使用该函数将其封装为 ppq.core.DataType."""

Callers 1

processMethod · 0.95

Calls 4

appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected