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

Method forward

python/singa/autograd.py:4838–4879  ·  view source on GitHub ↗
(self, x, hx, cx, w)

Source from the content-addressed store, hash-verified

4836 self.seq_lengths = seq_lengths
4837
4838 def forward(self, x, hx, cx, w):
4839 if training:
4840 if self.use_mask:
4841 (y, hy,
4842 cy) = singa.GpuRNNForwardTrainingEx(x, hx, cx, w,
4843 self.seq_lengths.data,
4844 self.handle)
4845 else:
4846 (y, hy,
4847 cy) = singa.GpuRNNForwardTraining(x, hx, cx, w, self.handle)
4848 self.inputs = {
4849 'x': x,
4850 'hx': hx,
4851 'cx': cx,
4852 'w': w,
4853 'y': y,
4854 'hy': hy,
4855 'cy': cy
4856 }
4857 else:
4858 if self.use_mask:
4859 (y, hy,
4860 cy) = singa.GpuRNNForwardInferenceEx(x, hx, cx, w,
4861 self.seq_lengths.data,
4862 self.handle)
4863 else:
4864 (y, hy,
4865 cy) = singa.GpuRNNForwardInference(x, hx, cx, w, self.handle)
4866
4867 if self.return_sequences:
4868 # (seq, bs, data)
4869 return y
4870 else:
4871 # return last time step of y
4872 # (seq, bs, data)[-1] -> (bs, data)
4873 last_y_shape = (y.shape()[1], y.shape()[2])
4874 last_y = singa.Tensor(list(last_y_shape), x.device())
4875
4876 src_offset = y.Size() - last_y.Size()
4877 # def copy_data_to_from(dst, src, size, dst_offset=0, src_offset=0):
4878 singa.CopyDataToFrom(last_y, y, last_y.Size(), 0, src_offset)
4879 return last_y
4880
4881 def backward(self, grad):
4882 assert training is True and hasattr(

Callers

nothing calls this directly

Calls 5

SizeMethod · 0.95
shapeMethod · 0.80
TensorMethod · 0.80
deviceMethod · 0.80
CopyDataToFromMethod · 0.45

Tested by

no test coverage detected