Tensorflow 在 GPT 2 Git 版本中没有“排序”属性?

Posted

技术标签:

【中文标题】Tensorflow 在 GPT 2 Git 版本中没有“排序”属性?【英文标题】:Tensorflow has no Attribute "sort" in GPT 2 Git Release? 【发布时间】:2020-08-14 01:50:19 【问题描述】:

我下载了 git repo (https://github.com/openai/gpt-2) 并按照 python3 说明(在 DEVELOPERS.MD 中)在我的 Kubuntu 18.04LTS 机器上安装,但我无法运行它,而是出现错误。

这是我到目前为止所做的:

pip3 install tensorflow==1.12.0
pip3 install -r requirements.txt
python3 download_model.py 124M
python3 download_model.py 355M
python3 download_model.py 774M
python3 download_model.py 1558M
export PYTHONIOENCODING=UTF-8

然后我跑了:

sarah@LesserArk:~/Custom Programs/gpt-2$ python3 src/interactive_conditional_samples.py 
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/sarah/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
2020-04-29 16:08:30.016586: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
  File "src/interactive_conditional_samples.py", line 91, in <module>
    fire.Fire(interact_model)
  File "/home/sarah/.local/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/sarah/.local/lib/python3.6/site-packages/fire/core.py", line 468, in _Fire
    target=component.__name__)
  File "/home/sarah/.local/lib/python3.6/site-packages/fire/core.py", line 672, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "src/interactive_conditional_samples.py", line 65, in interact_model
    temperature=temperature, top_k=top_k, top_p=top_p
  File "/home/sarah/Custom Programs/gpt-2/src/sample.py", line 74, in sample_sequence
    past, prev, output = body(None, context, context)
  File "/home/sarah/Custom Programs/gpt-2/src/sample.py", line 66, in body
    logits = top_p_logits(logits, p=top_p)
  File "/home/sarah/Custom Programs/gpt-2/src/sample.py", line 28, in top_p_logits
    sorted_logits = tf.sort(logits, direction='DESCENDING', axis=-1)
AttributeError: module 'tensorflow' has no attribute 'sort'

最终导致错误:AttributeError: module 'tensorflow' has no attribute 'sort'

这很奇怪,我不知道该怎么做。我原以为这些说明会导致安装成功,但似乎没有。

卸载重装对最终结果没有影响吗?如何让 tensorflow 执行 GPT-II?

【问题讨论】:

看起来你需要一个不同的 TF 版本。 1.12 似乎没有tf.sort。 1.13应该有。我敢打赌,他们在某个时候更新了 repo,但忘记更新说明。 【参考方案1】:

我能够使用以下方法让示例工作:

pip3 install tensorflow==1.13.1

此外,还有对 GitHub issue 的响应,其中显示将 Dockerfile.cpu 更改为构建 FROM tensorflow/tensorflow:1.15.0-py3 修复了 docker 映像问题。

【讨论】:

【参考方案2】:

pip install tesorflow==1.14.0

安装后我的问题得到解决。试试看

【讨论】:

以上是关于Tensorflow 在 GPT 2 Git 版本中没有“排序”属性?的主要内容,如果未能解决你的问题,请参考以下文章

尝试在 TensorFlow 中微调 GPT-2 模型时出现 ValueError

OpenAI GPT-2 模型与 TensorFlow JS 一起使用

Auto-GPT尝鲜使用

如何高效的学习 TensorFlow 代码

从零预训练huggingface/transformers的GPT-2代码

TensorFlow 从零到helloWorld