def test_forward_gpu(self):
x = chainer.Variable(self.x)
t = chainer.Variable(self.t)
y = self.link(x, t)
self.assertEqual(y.data.dtype, numpy.float32)
self.assertEqual(y.data.shape, ())
# fix samples
negative_sampling.NegativeSamplingFunction.samples = cuda.to_gpu(
y.creator.samples)
self.link.to_gpu()
y_g = self.link(chainer.Variable(cuda.to_gpu(self.x)),
chainer.Variable(cuda.to_gpu(self.t)))
del negative_sampling.NegativeSamplingFunction.samples
self.assertEqual(y_g.data.dtype, numpy.float32)
self.assertEqual(y_g.data.shape, ())
gradient_check.assert_allclose(y.data, y_g.data, atol=1.e-4)
test_negative_sampling.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录