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

Method embedding_helper

test/python/test_operation.py:3532–3547  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

3530 self.round_helper(gpu_dev)
3531
3532 def embedding_helper(self, dev):
3533 embedding = layer.Embedding(10, 3)
3534
3535 X = np.array([[0, 1, 2, 3], [9, 8, 7, 6]])
3536 x = tensor.from_numpy(X)
3537 x.to_device(dev)
3538
3539 dy = tensor.Tensor(shape=(2, 4, 3), device=dev)
3540 dy.gaussian(0.0, 1.0)
3541
3542 y = embedding(x) # PyTensor
3543 dx, dW = y.creator.backward(dy.data) # CTensor
3544
3545 self.check_shape(y.shape, (2, 4, 3))
3546 self.check_shape(dx.shape(), (2, 4))
3547 self.check_shape(dW.shape(), (10, 3))
3548
3549 def test_embedding_cpu(self):
3550 self.embedding_helper(cpu_dev)

Callers 2

test_embedding_cpuMethod · 0.95
test_embedding_gpuMethod · 0.95

Calls 7

gaussianMethod · 0.95
check_shapeMethod · 0.95
embeddingFunction · 0.85
TensorMethod · 0.80
shapeMethod · 0.80
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected