AttributeError:模块'tensorflow_core.python.keras.api._v2.keras.activations'没有属性'swish'
Posted
技术标签:
【中文标题】AttributeError:模块\'tensorflow_core.python.keras.api._v2.keras.activations\'没有属性\'swish\'【英文标题】:AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.activations' has no attribute 'swish'AttributeError:模块'tensorflow_core.python.keras.api._v2.keras.activations'没有属性'swish' 【发布时间】:2021-02-13 11:05:57 【问题描述】:我正在使用 Azure ML 工作室使用 SQuAD 数据集训练问答 ALBERT 模型。我收到以下错误。这是我执行的代码。
# Clone transformers github repo
!git clone https://github.com/huggingface/transformers \
&& cd transformers \
&& git checkout a3085020ed0d81d4903c50967687192e3101e770
# Install libraries
# !pip install ./transformers
!pip install transformers
!pip install tensorboardX
# Get data
! mkdir dataset \
&& cd dataset \
&& wget https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v2.0.json \
&& wget https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v2.0.json
# Train model
!export SQUAD_DIR=/content/dataset \
&& python transformers/examples/run_squad.py \
--model_type albert \
--model_name_or_path albert-base-v2 \
--do_train \
--do_eval \
--do_lower_case \
--train_file $SQUAD_DIR/train-v2.0.json \
--predict_file $SQUAD_DIR/dev-v2.0.json \
--per_gpu_train_batch_size 12 \
--learning_rate 3e-5 \
--num_train_epochs 1.0 \
--max_seq_length 384 \
--doc_stride 128 \
--output_dir /content/model_output \
--save_steps 1000 \
--threads 4 \
--version_2_with_negative
我使用的是 NVIDIA Tesla K80 GPU。当我执行上面的单元格来训练模型时,我收到以下错误:
2020-10-31 01:31:45.732913: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2020-10-31 01:31:45.733023: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2020-10-31 01:31:45.733043: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Traceback (most recent call last):
File "transformers/examples/run_squad.py", line 32, in <module>
from transformers import (
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/transformers/__init__.py", line 135, in <module>
from .pipelines import (
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/transformers/pipelines.py", line 47, in <module>
from .modeling_tf_auto import (
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/transformers/modeling_tf_auto.py", line 45, in <module>
from .modeling_tf_albert import (
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/transformers/modeling_tf_albert.py", line 24, in <module>
from .activations_tf import get_tf_activation
File "/anaconda/envs/azureml_py36/lib/python3.6/site-packages/transformers/activations_tf.py", line 53, in <module>
"swish": tf.keras.activations.swish,
AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.activations' has no attribute 'swish'
【问题讨论】:
【参考方案1】:解决了
需要补充:
!pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
【讨论】:
太慢了.... 3 分钟并且仍在运行(虽然这是一个有点慢的盒子)以上是关于AttributeError:模块'tensorflow_core.python.keras.api._v2.keras.activations'没有属性'swish'的主要内容,如果未能解决你的问题,请参考以下文章
AttributeError:模块'keras'没有属性'initializers'
AttributeError:模块'asyncio'没有属性'run'
AttributeError:模块'mysql'没有属性'connector'