Python torch.backends.cudnn 模块,DropoutDescriptor() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用torch.backends.cudnn.DropoutDescriptor()

项目:pytorch-dist    作者:apaszke    | 项目源码 | 文件源码
def init_dropout_descriptor(fn, handle):
    dropout_desc = cudnn.DropoutDescriptor()

    dropout_states_size = ctypes.c_long()
    check_error(cudnn.lib.cudnnDropoutGetStatesSize(
        handle,
        ctypes.byref(dropout_states_size)))

    dropout_states = torch.cuda.ByteTensor(dropout_states_size.value)
    dropout_desc.set(
        handle,
        fn.dropout,
        dropout_states,
        fn.seed
    )
    return dropout_desc
项目:pytorch    作者:tylergenter    | 项目源码 | 文件源码
def init_rnn_descriptor(fn, handle):
    dropout_desc_name = 'desc_' + str(torch.cuda.current_device())
    dropout_p = fn.dropout if fn.train else 0
    if (dropout_desc_name not in fn.dropout_state) or (fn.dropout_state[dropout_desc_name].get() is None):
        fn.dropout_state[dropout_desc_name] = Unserializable(
            cudnn.DropoutDescriptor(handle, dropout_p, fn.dropout_seed)
        )
    dropout_desc = fn.dropout_state[dropout_desc_name].get()
    dropout_desc.set_dropout(dropout_p, fn.dropout_seed)
    return cudnn.RNNDescriptor(
        handle,
        fn.hidden_size,
        fn.num_layers,
        dropout_desc,
        fn.input_mode,
        fn.bidirectional,
        fn.mode,
        fn.datatype
    )
项目:pytorch-coriander    作者:hughperkins    | 项目源码 | 文件源码
def init_rnn_descriptor(fn, handle):
    dropout_desc_name = 'desc_' + str(torch.cuda.current_device())
    dropout_p = fn.dropout if fn.train else 0
    if (dropout_desc_name not in fn.dropout_state) or (fn.dropout_state[dropout_desc_name].get() is None):
        fn.dropout_state[dropout_desc_name] = Unserializable(
            cudnn.DropoutDescriptor(handle, dropout_p, fn.dropout_seed)
        )
    dropout_desc = fn.dropout_state[dropout_desc_name].get()
    dropout_desc.set_dropout(dropout_p, fn.dropout_seed)
    return cudnn.RNNDescriptor(
        handle,
        fn.hidden_size,
        fn.num_layers,
        dropout_desc,
        fn.input_mode,
        fn.bidirectional,
        fn.mode,
        fn.datatype
    )
项目:pytorch    作者:ezyang    | 项目源码 | 文件源码
def init_rnn_descriptor(fn, handle):
    dropout_desc_name = 'desc_' + str(torch.cuda.current_device())
    dropout_p = fn.dropout if fn.train else 0
    if (dropout_desc_name not in fn.dropout_state) or (fn.dropout_state[dropout_desc_name].get() is None):
        fn.dropout_state[dropout_desc_name] = Unserializable(
            cudnn.DropoutDescriptor(handle, dropout_p, fn.dropout_seed)
        )
    dropout_desc = fn.dropout_state[dropout_desc_name].get()
    dropout_desc.set_dropout(dropout_p, fn.dropout_seed)
    return cudnn.RNNDescriptor(
        handle,
        fn.hidden_size,
        fn.num_layers,
        dropout_desc,
        fn.input_mode,
        fn.bidirectional,
        fn.mode,
        fn.datatype
    )
项目:pytorch    作者:pytorch    | 项目源码 | 文件源码
def init_rnn_descriptor(fn, handle):
    dropout_desc_name = 'desc_' + str(torch.cuda.current_device())
    dropout_p = fn.dropout if fn.train else 0
    if (dropout_desc_name not in fn.dropout_state) or (fn.dropout_state[dropout_desc_name].get() is None):
        fn.dropout_state[dropout_desc_name] = Unserializable(
            cudnn.DropoutDescriptor(handle, dropout_p, fn.dropout_seed)
        )
    dropout_desc = fn.dropout_state[dropout_desc_name].get()
    dropout_desc.set_dropout(dropout_p, fn.dropout_seed)
    return cudnn.RNNDescriptor(
        handle,
        fn.hidden_size,
        fn.num_layers,
        dropout_desc,
        fn.input_mode,
        fn.bidirectional,
        fn.mode,
        fn.datatype
    )