MCPcopy Create free account
hub / github.com/apache/singa / wrapper

Method wrapper

examples/cnn_ms/pkg_model_code/model.py:60–94  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

58
59 @wraps(func)
60 def wrapper(self, *args, **kwargs):
61 if self.graph_mode and self.training:
62 if len(args) == 0:
63 raise ValueError('expect at least one input tensor')
64
65 if isinstance(args[0], list):
66 assert isinstance(
67 args[0][0],
68 Tensor), ('function expects PlaceHolders or Tensors')
69 dev = args[0][0].device
70 else:
71 assert isinstance(
72 args[0],
73 Tensor), ('function expects PlaceHolders or Tensors')
74 dev = args[0].device
75
76 if not self._buffered:
77 # buffer operations
78 dev.EnableGraph(True)
79 self._results = func(self, *args, **kwargs)
80 dev.Sync()
81 dev.EnableGraph(False)
82 self._buffered = True
83
84 # deconstruct Operations before running the entire graph
85 remove_creator(self._results)
86
87 # make sure all Operations are deallocated
88 gc.collect()
89
90 # run graph
91 dev.RunGraph(self.sequential)
92 return self._results
93 else:
94 return func(self, *args, **kwargs)
95
96 return wrapper
97

Callers

nothing calls this directly

Calls 3

EnableGraphMethod · 0.80
SyncMethod · 0.45
RunGraphMethod · 0.45

Tested by

no test coverage detected