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

Function embed_inputs

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

r"""Embeds ``data`` to the graph's inputs of ``dst``. Args: dst: target vars representing the graph. data: data to be embeded. inputs: indicates which inputs to be replaced. All inputs(``Host2DeiceCopy``) will be replaced if not specified. Returns:

(
    dst: List[_VarNode], data: List[np.ndarray], inputs: List[_VarNode] = None
)

Source from the content-addressed store, hash-verified

402
403
404def embed_inputs(
405 dst: List[_VarNode], data: List[np.ndarray], inputs: List[_VarNode] = None
406) -> Tuple[List[_VarNode], Dict[str, _VarNode]]:
407 r"""Embeds ``data`` to the graph's inputs of ``dst``.
408
409 Args:
410 dst: target vars representing the graph.
411 data: data to be embeded.
412 inputs: indicates which inputs to be replaced. All
413 inputs(``Host2DeiceCopy``) will be replaced if not specified.
414
415 Returns:
416 new vars that correspond to ``dst`` with all inputs replaced, and new inputs dict.
417 """
418 if inputs is None:
419 inputs = get_dep_vars(dst, "Host2DeviceCopy")
420 assert len(data) == len(inputs)
421 input_dict = OrderedDict()
422 replace_dict = {}
423 for inp, d in zip(inputs, data):
424 new_inp = _imperative_rt.make_shared(inp.graph, Tensor(d)._dev_tensor())
425 new_inp.name = inp.name
426 input_dict[inp.name] = new_inp
427 replace_dict[inp] = new_inp
428 new_output_nodes = replace_vars(dst, replace_dict)
429 for old, new in zip(dst, new_output_nodes):
430 new.name = old.name
431 return new_output_nodes, input_dict
432
433
434class GraphInference:

Callers

nothing calls this directly

Calls 5

get_dep_varsFunction · 0.85
replace_varsFunction · 0.85
make_sharedMethod · 0.80
_dev_tensorMethod · 0.80
TensorClass · 0.50

Tested by

no test coverage detected