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

Method compile

python/singa/model.py:156–184  ·  view source on GitHub ↗

Compile and initialize the model This function will automatically derive the shape of parameters in each sublayer based on the shape of input placeholders. It will also do some settings. Args: inputs(list): the list of input tensors(placeholders)

(self, inputs, is_train=True, use_graph=False, sequential=False)

Source from the content-addressed store, hash-verified

154 self._results = None
155
156 def compile(self, inputs, is_train=True, use_graph=False, sequential=False):
157 """ Compile and initialize the model
158
159 This function will automatically derive the shape of parameters
160 in each sublayer based on the shape of input placeholders. It will
161 also do some settings.
162
163 Args:
164 inputs(list): the list of input tensors(placeholders)
165 is_train(bool): when is_trainis True, this model will enter
166 training mode, otherwise it will enter the evaluation mode
167 use_graph(bool): when use_graph is True, computational graph
168 will be used to train this model
169 sequential(bool): when sequential is True, model will execute ops
170 in the graph follow the order of joining the graph
171 """
172 assert len(inputs) > 0 and isinstance(inputs[0], Tensor), (
173 'compile function expects PlaceHolders or Tensors')
174
175 dev = inputs[0].device
176 dev.EnableGraph(True)
177 self.forward(*inputs)
178 dev.EnableGraph(False)
179 dev.ResetGraph()
180
181 autograd.training = is_train
182 self.training = is_train
183 self.graph_mode = use_graph
184 self.sequential = sequential
185
186 def forward(self, *input):
187 """Defines the computation performed in every forward propagation.

Callers 5

test_lstm_modelMethod · 0.45
_forward_helperMethod · 0.45

Calls 3

forwardMethod · 0.95
EnableGraphMethod · 0.80
ResetGraphMethod · 0.80

Tested by 5

test_lstm_modelMethod · 0.36
_forward_helperMethod · 0.36