MCPcopy Create free account
hub / github.com/pytorch/pytorch / _add_ops

Method _add_ops

caffe2/python/layers/fc.py:171–204  ·  view source on GitHub ↗

Args: params : the weight and bias, passed by either add_ops or add_train_ops function version : fp16 or fp32, might support in8 in the future.

(self, net, params, version)

Source from the content-addressed store, hash-verified

169 raise Exception("unsupported FC type version {}".format(version))
170
171 def _add_ops(self, net, params, version):
172 """
173 Args:
174 params : the weight and bias,
175 passed by either add_ops or add_train_ops function
176 version : fp16 or fp32, might support in8 in the future.
177 """
178 if self.clip_args is not None:
179 clipped_params = [net.NextScopedBlob(
180 'clipped_%s' % str(p)) for p in params]
181 for p, cp in zip(params, clipped_params):
182 net.Clip([p], [cp], **self.clip_args)
183 params = clipped_params
184
185 if self.output_dim_vec is None or len(self.output_dim_vec) == 1:
186 self._insert_fc_ops(net, params, self.output_schema.field_blobs(), version)
187 else:
188 w_vec = params[:int(len(params) / 2)]
189 b_vec = params[int(len(params) / 2):]
190
191 assert len(w_vec) == len(b_vec)
192
193 output_blob_vec = []
194
195 for i in range(len(self.output_dim_vec)):
196 output_blob = net.NextScopedBlob(
197 'output_sub_{}'.format(i))
198 insert_ret = self._insert_fc_ops(
199 net, [w_vec[i], b_vec[i]], [output_blob], version
200 )
201 output_blob_vec.append(insert_ret)
202 net.Concat(output_blob_vec,
203 self.output_schema.field_blobs() +
204 [self.output_schema.field_blobs()[0] + "_concat_dims"])
205
206 def add_ops(self, net):
207 """Both the predict net and the eval net will call this function

Callers 2

add_opsMethod · 0.95
add_train_opsMethod · 0.95

Calls 7

_insert_fc_opsMethod · 0.95
NextScopedBlobMethod · 0.80
ConcatMethod · 0.80
rangeFunction · 0.50
field_blobsMethod · 0.45
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected