由于Keras中的语义相似性,TPU在BERT上失败,但可在GPU上工作

问题描述

我正在试验BERT的语义相似性,我在这里https://keras.io/examples/nlp/semantic_similarity_with_bert/

遵循此代码

当我使用代码时,一切都能顺利运行,,但是实现仅在GPU上实现,我想对其进行修改,以便可以与TPU一起使用,以更快地运行它。我做了一些修改,但是TPU失败了,我不明白为什么:(。

您可以检查我在此处创建的修改后的代码https://colab.research.google.com/drive/1y2wKBXWscBcaH-UMr6MnE_xJCkJ3Vr4h?usp=sharing

这也是它输出错误

Truncation was not explicitely activated but `max_length` is provided a specific value,please use `truncation=True` to explicitely truncate examples to max length. Defaulting to 'longest_first' truncation strategy. If you encode pairs of sequences (gluE-style) with the tokenizer you can select this strategy more precisely by providing a specific strategy to `truncation`.
/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py:1944: FutureWarning: The `pad_to_max_length` argument is deprecated and will be removed in a future version,use `padding=True` or `padding='longest'` to pad to the longest sequence in the batch,or use `padding='max_length'` to pad to a max length. In this case,you can give a specific length with `max_length` (e.g. `max_length=45`) or leave max_length to None to pad to the maximal input size of the model (e.g. 512 for Bert).
  FutureWarning,Epoch 1/2
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/data/ops/multi_device_iterator_ops.py:601: get_next_as_optional (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Iterator.get_next_as_optional()` instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/data/ops/multi_device_iterator_ops.py:601: get_next_as_optional (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Iterator.get_next_as_optional()` instead.
---------------------------------------------------------------------------
UnavailableError                          Traceback (most recent call last)
<ipython-input-14-06e7db75838d> in <module>()
      4     epochs=epochs,5     use_multiprocessing=True,----> 6     workers=-1,7 )

14 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value,from_value)

UnavailableError: 9 root error(s) found.
  (0) Unavailable: {{function_node __inference_train_function_51069}} Failed to connect to all addresses
Additional GRPC error information from remote target /job:localhost/replica:0/task:0/device:cpu:0:
:{"created":"@1603907191.027747674","description":"Failed to pick subchannel","file":"third_party/grpc/src/core/ext/filters/client_channel/client_channel.cc","file_line":3948,"referenced_errors":[{"created":"@1603907191.027745401","description":"Failed to connect to all addresses","file":"third_party/grpc/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":394,"grpc_status":14}]}
     [[{{node MultideviceIteratorGetNextFromShard}}]]
     [[RemoteCall]]
     [[IteratorGetNextAsOptional]]
     [[cond_11/switch_pred/_135/_78]]
  (1) Unavailable: {{function_node __inference_train_function_51069}} Failed to connect to all addresses
Additional GRPC error information from remote target /job:localhost/replica:0/task:0/device:cpu:0:
:{"created":"@1603907191.027747674","grpc_status":14}]}
     [[{{node MultideviceIteratorGetNextFromShard}}]]
     [[RemoteCall]]
     [[IteratorGetNextAsOptional]]
     [[strided_slice_120/_282]]
  (2) Unavailable: {{function_node __inference_train_function_51069}} Failed to connect to all addresses
Additional GRPC error information from remote target /job:localhost/replica:0/task:0/device:cpu:0:
:{"created":"@1603907191.027747674","grpc_status":14}]}
     [[{{node MultideviceIteratorGetNextFromShard}}]]
     [[RemoteCall]]
     [[IteratorGetNextAsOptional]]
     [[strided_slice_30/_406]]
  (3) Unavailable: {{function_node __inference_train_function_51069}} Failed to connect to all addresses
Additional GRPC error information from remote target /job:localhost/replica:0/task:0/device:cpu:0:
:{"created":"@1603907191.027747674","grpc_status":14}]}
     [[{{node MultideviceIteratorGetNextFromShard}}]]
     [[RemoteCall]]
     [[IteratorGetNextAsOptional]]
     [[strided_slice_174/_334]]
  (4) Unavailable: {{function_node __inference_train ... [truncated]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)