MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / replace_oprs

Method replace_oprs

imperative/python/megengine/utils/network.py:401–417  ·  view source on GitHub ↗

r"""Replaces operators in the graph. Args: repl_dict: the map {old_opr: new_opr} that specifies how to replace the operators.

(self, repl_dict: Dict[OpNode, OpNode])

Source from the content-addressed store, hash-verified

399 self._compile()
400
401 def replace_oprs(self, repl_dict: Dict[OpNode, OpNode]):
402 r"""Replaces operators in the graph.
403
404 Args:
405 repl_dict: the map {old_opr: new_opr} that specifies how to replace the operators.
406 """
407 for opr in self.all_oprs:
408 if opr in repl_dict:
409 assert len(opr.outputs) == len(
410 repl_dict[opr].outputs
411 ), "can not replace {} with {}".format(type(opr), type(repl_dict[opr]))
412 for ind, var in enumerate(opr.outputs):
413 var.owner = repl_dict[opr]
414 var.__dict__.update(repl_dict[opr].outputs[ind].__dict__)
415 var._reset_var(repl_dict[opr].outputs[ind].var)
416 repl_dict[opr].outputs = opr.outputs
417 self._compile()
418
419 def get_opr_by_type(self, oprcls, unique=True):
420 assert issubclass(oprcls, OpNode)

Callers 2

test_replace_oprFunction · 0.45
test_replace_oprsFunction · 0.45

Calls 4

_compileMethod · 0.95
_reset_varMethod · 0.80
formatMethod · 0.45
updateMethod · 0.45

Tested by 2

test_replace_oprFunction · 0.36
test_replace_oprsFunction · 0.36