gpt4 book ai didi

r - 使用cuDNN内核进行LSTM

转载 作者:行者123 更新时间:2023-12-03 14:34:00 27 4
gpt4 key购买 nike

我想使用Cudnn训练我的RNN模型:

max_length <- 140 
embedding_dim <- 128

model <- keras_model_sequential()

# define model
model %>%
# layer input
layer_embedding(
name = "input",
input_dim = num_words,
input_length = max_length,
output_dim = embedding_dim,
embeddings_initializer = initializer_random_uniform(minval = -0.05, maxval = 0.05, seed = 2)
) %>%
# layer dropout
layer_spatial_dropout_1d(
name = "embedding_dropout",
rate = 0.2
) %>%
# layer lstm 1
bidirectional(layer_lstm(
name = "lstm",
units = 64,
unroll = FALSE,
dropout = 0.2,
use_bias = TRUE,
recurrent_dropout = 0,
return_sequences = TRUE
)) %>%
layer_batch_normalization() %>%
# layer output
layer_dense(
name = "output",
units = 3,
activation = "softmax"
)

当我运行这个时,我会变暖:

WARNING:tensorflow:Layer lstm will not use cuDNN kernel since it doesn't meet the cuDNN kernel criteria. It will use generic GPU kernel as fallback when running on GPU



我想我已经遵循了所有的 requirements,不确定我丢失了什么。

SessionInfo:
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] keras_2.3.0.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 lattice_0.20-41 zeallot_0.1.0 rappdirs_0.3.1
[5] grid_4.0.0 R6_2.4.1 jsonlite_1.6.1 magrittr_1.5
[9] tfruns_1.4 whisker_0.4 Matrix_1.2-18 reticulate_1.15
[13] generics_0.0.2 tools_4.0.0 xfun_0.14 compiler_4.0.0
[17] base64enc_0.1-3 tensorflow_2.2.0 knitr_1.28

最佳答案

我遇到了相同的问题,并通过手动设置选项以使用here来指定与cuDNN兼容的实现,从而解决了该问题。
“基于可用的运行时硬件和约束,该层将选择不同的实现(基于cuDNN或纯TensorFlow)以最大化性能。如果GPU可用并且该层的所有参数都满足CuDNN内核的要求(请参阅下面的详细信息),该层将使用快速的cuDNN实现。”
使用cuDNN实现的要求是:

  • 激活== tanh
  • recurrent_activation ==乙状结肠
  • recurrent_dropout == 0
  • 展开为False
  • use_bias是True
  • 如果使用掩码,则输入必须严格右填充。
  • 最外层启用急切执行
    语境。

  • 特别是,我必须指定 recurrent_activation == sigmoid。我安装的Keras/TF版本默认为 recurrent_activation == hard_sigmoid

    关于r - 使用cuDNN内核进行LSTM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62044838/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com