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

Method wrapper

python/singa/model.py:57–91  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

EnableGraphMethod · 0.80
SyncMethod · 0.45
RunGraphMethod · 0.45

Tested by

no test coverage detected