【问题标题】:Is there cudnnLSTM or cudNNGRU alternative in tensorflow 2.0tensorflow 2.0 中是否有 cudnnLSTM 或 cudNNGRU 替代方案
【发布时间】:2020-06-13 12:59:31
【问题描述】:

TensorFlow 1.0 中的CuDNNGRU 非常快。但是当我转移到TensorFlow 2.0 时,我找不到CuDNNGRU。简单的GRUTensorFlow 2.0 中真的很慢。

有没有办法在TensorFlow 2.0中使用CuDNNGRU

【问题讨论】:

    标签: python tensorflow keras recurrent-neural-network tensorflow2.0


    【解决方案1】:

    可导入的实现已被弃用 - 相反,LSTMGRU 将默认为 CuDNNLSTMCuDNNGRU(如果全部为 conditions are met):

    1. activation = 'tanh'
    2. recurrent_activation = 'sigmoid'
    3. recurrent_dropout = 0
    4. unroll = False
    5. use_bias = True
    6. 输入,如果被屏蔽,严格右填充
    7. reset_after = True(仅限 GRU)

    还要确保 TensorFlow 使用 GPU:

    import tensorflow as tf
    from tensorflow.python.client import device_lib
    print(device_lib.list_local_devices())
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
    

    更新:在 Colab 上运行时,TF 2.0.0 似乎存在问题,无法让 CuDNN 正常工作;试试!pip install tensorflow==2.1.0

    【讨论】:

    • 我试过这个`x, x_h, x_c = Bidirectional(GRU(50, activation= 'tanh',recurrent_activation ='sigmoid',recurrent_dropout=0, unroll =False,use_bias =True,reset_after= True,return_sequences = True, return_state = True))(x)` 但它与没有这些参数的时间相同。这是10 的时间超过CuDNNGRU
    • @TalhaAnwar 你的 TensorFlow 使用 GPU 吗?查看更新的答案;另外,您的输入是填充还是屏蔽?
    • 是的,我正在使用 colab gpu,我的输入被后填充以使所有句子的长度相等,我认为这是右填充
    • @TalhaAnwar 别介意我之前的建议,文档字符串的措辞是错误的;输入,如果被填充,应该被严格地向右填充(即永远不会离开)。是这样吗,你使用掩蔽吗?
    • 感谢这对我来说确实有效,因为它设置了指定的周长。
    猜你喜欢
    • 2021-11-26
    • 1970-01-01
    • 2019-06-16
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多