Beispiel #1
0
    def test_dropout_backward(self):
        rspace, y = self.states.forward(cudnn.get_handle(), self.x, self.ratio)
        gx = self.states.backward(cudnn.get_handle(), self.gy, self.ratio,
                                  rspace)

        forward_mask = y / self.x
        backward_mask = gx / self.gy

        # backward_mask must be the same as forward_mask
        self.assertTrue(cupy.all(forward_mask == backward_mask))
Beispiel #2
0
def get_cudnn_dropout_states_core(thread_id):
    states_id = next(_dropout_states_count)
    seed = os.getenv('CHAINER_SEED')
    if seed is None:
        try:
            seed_str = binascii.hexlify(os.urandom(8))
            seed = numpy.uint64(int(seed_str, 16))
        except NotImplementedError:
            seed = numpy.uint64(time.clock() * 1000000)
    else:
        seed = numpy.uint64(seed)

    seed += numpy.uint64(states_id)
    handle = cudnn.get_handle()
    return cudnn.DropoutStates(handle, seed)
Beispiel #3
0
    def test_dropout_seed(self):
        handle = cudnn.get_handle()

        # initialize Dropoutstates with the same seed
        states2 = cudnn.DropoutStates(handle, self.seed)

        rspace, y = self.states.forward(handle, self.x, self.ratio)
        rspace2, y2 = states2.forward(handle, self.x, self.ratio)
        # forward results must be the same
        self.assertTrue(cupy.all(y == y2))

        gx = self.states.backward(handle, self.gy, self.ratio, rspace)
        gx2 = states2.backward(handle, self.gy, self.ratio, rspace2)
        # backward results must be the same
        self.assertTrue(cupy.all(gx == gx2))
Beispiel #4
0
def get_cudnn_dropout_states_core(thread_id):
    states_id = next(_dropout_states_count)
    seed = os.getenv('CHAINER_SEED')
    if seed is None:
        try:
            seed_str = binascii.hexlify(os.urandom(8))
            seed = numpy.uint64(int(seed_str, 16))
        except NotImplementedError:
            seed = numpy.uint64(time.clock() * 1000000)
    else:
        seed = numpy.uint64(seed)

    seed += numpy.uint64(states_id)
    handle = cudnn.get_handle()
    return cudnn.DropoutStates(handle, seed)
Beispiel #5
0
 def test_dropout_forward(self):
     _, y = self.states.forward(cudnn.get_handle(), self.x, self.ratio)
     if self.ratio == 0:
         self.assertTrue(cupy.all(self.x == y))
     else:
         self.assertTrue(cupy.all(self.x != y))
Beispiel #6
0
 def setUp(self):
     self.x = testing.shaped_arange((3, 4), cupy, self.dtype)
     self.gy = testing.shaped_arange((3, 4), cupy, self.dtype)
     self.states = cudnn.DropoutStates(cudnn.get_handle(), self.seed)