【发布时间】:2020-01-07 23:37:46
【问题描述】:
我正在尝试this BERT model from TFHub。 可悲的是,它的运行速度非常慢,根据 Windows 任务管理器仅使用 1-2% 的 GPU。
有什么办法可以加快速度吗?
import tensorflow as tf
import tensorflow_hub as hub
tf.test.is_gpu_available(True) # returns True
max_seq_length = 128
input_word_ids = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="input_word_ids")
input_mask = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="input_mask")
segment_ids = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="segment_ids")
bert_layer = hub.KerasLayer("https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/1", trainable=False)
pooled_out, seq_out = bert_layer([input_word_ids, input_mask, segment_ids])
model = tf.keras.Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=[pooled_out, seq_out])
t = tf.random.uniform((1000, max_seq_length), maxval=1, dtype=tf.int32)
outputs = model.predict([t, t, t]) # super slow...
【问题讨论】:
-
程序可能在 CPU 而不是 GPU 上执行。请对此进行验证。另外,验证你是否安装了
tensorflow-gpu
标签: python tensorflow keras nlp tensorflow2.0