Example #1
0
 def _oper_gpu(cls, x, dropout_ratio):
     mask = get_gpu(x).empty_like_me()
     curand_generator().rand_bernoulli(mask, 1 - dropout_ratio)
     mask = mask / dropout_ratio
     value = get_gpu(x) * mask
     ret = cls._create_node(value)
     ret.attrs._x = x
     ret.attrs._mask = mask
     return ret
Example #2
0
 def _oper_gpu(cls, x, drop_out_ratio):
     shape = (x.shape[0], x.shape[1], 1, 1)
     mask = GPUValue(shape=shape)
     curand_generator().rand_bernoulli(mask, 1 - drop_out_ratio)
     mask = mask / drop_out_ratio
     mask = mask * get_gpu(x).ones_like_me()
     value = get_gpu(x) * get_gpu(mask)
     ret = cls._create_node(value)
     ret.attrs._x = x
     ret.attrs._mask = mask
     return ret
Example #3
0
def test_rand():
    set_cuda_active(True)

    x = get_gpu(np.random.rand(2, 2)).empty_like_me()

    np.random.seed(2)
    curand_generator().rand_bernoulli(x, 0.5)
    g1 = x.new_array()

    np.random.seed(2)
    curand_generator().rand_bernoulli(x, 0.5)
    g2 = x.new_array()

    assert np.allclose(g1, g2)
Example #4
0
 def func(node):
     if is_cuda_active():
         curand_generator().set_seed(seed)
     else:
         np.random.seed(seed)
     return sum(layer(node))
Example #5
0
 def func(node):
     if use_gpu:
         curand_generator().set_seed(seed)
     else:
         np.random.seed(seed)
     return sum(layer(node))