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

Function convert_inputs

imperative/python/megengine/utils/comp_graph_tools.py:358–386  ·  view source on GitHub ↗

r"""Replaces ``Host2DeviceCopy`` with :class:`~.InputNode` in the graph to :meth:`~.InputNode.set_value` and run. Args: dst: target vars representing the graph. inputs: indicates which inputs to be replaced. All inputs(``Host2DeiceCopy``) will be replaced if not

(
    dst: List[_VarNode], inputs: List[_VarNode] = None
)

Source from the content-addressed store, hash-verified

356
357
358def convert_inputs(
359 dst: List[_VarNode], inputs: List[_VarNode] = None
360) -> Tuple[List[_VarNode], Dict[str, _VarNode]]:
361 r"""Replaces ``Host2DeviceCopy`` with :class:`~.InputNode` in the graph
362 to :meth:`~.InputNode.set_value` and run.
363
364 Args:
365 dst: target vars representing the graph.
366 inputs: indicates which inputs to be replaced. All
367 inputs(``Host2DeiceCopy``) will be replaced if not specified.
368
369 Returns:
370 new vars that correspond to ``dst`` with all inputs replaced, and new inputs dict.
371 """
372 if inputs is None:
373 inputs = get_dep_vars(dst, "Host2DeviceCopy")
374 input_dict = OrderedDict()
375 replace_dict = {}
376 for inp in inputs:
377 inp_node = G.InputNode(
378 device=inp.comp_node, dtype=inp.dtype, shape=inp.shape, graph=inp.graph,
379 )
380 inp_node.name = inp.name
381 input_dict[inp.name] = inp_node
382 replace_dict[inp] = inp_node.outputs[0]
383 new_output_nodes = replace_vars(dst, replace_dict)
384 for old, new in zip(dst, new_output_nodes):
385 new.name = old.name
386 return new_output_nodes, input_dict
387
388
389def convert_outputs(dst: List[_VarNode]) -> Tuple[List[_VarNode], Dict[str, _VarNode]]:

Callers 1

__init__Method · 0.70

Calls 2

get_dep_varsFunction · 0.85
replace_varsFunction · 0.85

Tested by

no test coverage detected