MCPcopy Index your code
hub / github.com/OpenPPL/ppq / format_clip

Method format_clip

ppq/IR/morph.py:257–288  ·  view source on GitHub ↗

对于不同的模型格式, clip 算子将有两种不同的输入格式: for different models, possibly clip op has the following input formats 1. min, max 参数由 第二、第三个输入变量给出 min, max parameter will be given by the second and third input variable 2. min, max 参数由 attri

(self)

Source from the content-addressed store, hash-verified

255 op.inputs[1], op.inputs[2] = op.inputs[2], op.inputs[1]
256
257 def format_clip(self) -> None:
258 """
259 对于不同的模型格式, clip 算子将有两种不同的输入格式:
260 for different models, possibly clip op has the following input formats
261 1. min, max 参数由 第二、第三个输入变量给出
262 min, max parameter will be given by the second and third input variable
263 2. min, max 参数由 attribute 给出
264 min, max parameter will be given by the attribute
265 此函数统一 clip 算子行为:所有 clip 算子的 min, max 参数第二第三个变量给出
266 this func unifies behaviors of clip op: min, max parameter will be given by input vars
267 针对可能存在的 min, max 为空的情况,将其直接置为 2 << 30(保证处理后非空)
268
269 当 min, max 参数由 第二、第三个输入变量给出时,其中一个为空时直接返回 ValueError
270 ValueError will be raised when any of min, max parameters is null
271 """
272
273 interested_ops = []
274 for _, operation in self.graph.operations.items():
275 if operation.type == 'Clip' and ('min' in operation.attributes or 'max' in operation.attributes):
276 interested_ops.append(operation)
277 for op in interested_ops:
278 assert isinstance(op, Operation)
279 min = op.attributes.get('min', - 2 << 30)
280 max = op.attributes.get('max', + 2 << 30)
281 min_var = Variable(name=op.name + '_min', value=min, is_parameter=True, dest_ops=[op])
282 max_var = Variable(name=op.name + '_max', value=max, is_parameter=True, dest_ops=[op])
283 self.graph.append_variable(min_var)
284 self.graph.append_variable(max_var)
285 op.inputs.append(min_var)
286 op.inputs.append(max_var)
287 if 'min' in op.attributes: op.attributes.pop('min')
288 if 'max' in op.attributes: op.attributes.pop('max')
289
290 def format_gather(self) -> None:
291 """gather op 的参数 index 可能由 input variable 给出 但 index

Callers 1

processMethod · 0.95

Calls 4

VariableClass · 0.85
append_variableMethod · 0.80
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected