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

Method _SeLU_helper

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

Source from the content-addressed store, hash-verified

1918 self._prelu_helper(gpu_dev)
1919
1920 def _SeLU_helper(self, dev):
1921 x = np.random.randn(3, 2)
1922 a = 0.2
1923 g = 0.3
1924 y = np.clip(x, 0,
1925 np.inf) * g + (np.exp(np.clip(x, -np.inf, 0)) - 1) * a * g
1926 dy = np.random.randn(3, 2)
1927 grad = (np.exp(np.clip(x, -np.inf, 0))) * g
1928 grad[x <= 0] = grad[x <= 0] * a
1929 grad *= dy
1930
1931 x = tensor.from_numpy(x)
1932 dy = tensor.from_numpy(dy)
1933 x.to_device(dev)
1934 dy.to_device(dev)
1935 result = autograd.selu(x, a, g)
1936 dx = result.creator.backward(dy.data)
1937 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1938 y,
1939 decimal=5)
1940 np.testing.assert_array_almost_equal(tensor.to_numpy(
1941 tensor.from_raw_tensor(dx)),
1942 grad,
1943 decimal=5)
1944
1945 def test_SeLU_cpu(self):
1946 self._SeLU_helper(cpu_dev)

Callers 2

test_SeLU_cpuMethod · 0.95
test_SeLU_gpuMethod · 0.95

Calls 2

to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected