MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / __map_io

Method __map_io

python/oneflow/nn/graph/proxy.py:349–391  ·  view source on GitHub ↗
(self, io_type, func, func_desc, *args, **kwargs)

Source from the content-addressed store, hash-verified

347 yield m
348
349 def __map_io(self, io_type, func, func_desc, *args, **kwargs):
350 assert isinstance(func_desc, str)
351 assert io_type in ("input", "output")
352 mapped_args = []
353
354 def map_tensor(item):
355 assert isinstance(item, Tensor)
356 return func(item)
357
358 args_tree = ArgsTree(
359 (args, kwargs),
360 True,
361 "_"
362 + self.to(GraphModule).name_prefix
363 + self.to(GraphModule).name
364 + "_"
365 + io_type,
366 None,
367 )
368
369 def leaf_node_fn(leaf_node):
370 arg = leaf_node.value()
371 name = leaf_node.prefix() + "_" + leaf_node.name()
372 is_tensor, repr_str = self.__io_tensor_check_and_gen(arg, io_type, name)
373 if is_tensor:
374 self.__print(
375 0,
376 1,
377 f"{repr_str} is a Tensor, {func_desc} transformation has been done.",
378 )
379 return map_tensor(arg)
380 else:
381 self.__print(
382 0,
383 0,
384 f"{repr_str} is not a Tensor, {func_desc} transformation will be ignored.",
385 )
386 return arg
387
388 out = args_tree.map_leaf(leaf_node_fn)
389 mapped_args = out[0]
390 mapped_kwargs = out[1]
391 return mapped_args, mapped_kwargs
392
393 def __io_tensor_check_and_gen(self, item, io_type, name):
394 assert io_type in ("input", "output")

Callers 1

__pre_forward_mapMethod · 0.95

Calls 3

map_leafMethod · 0.95
ArgsTreeClass · 0.90
toMethod · 0.45

Tested by

no test coverage detected