当我尝试运行 gpt-2 的生成函数时,tensorflow 中出现不兼容的形状错误?

问题描述

我在 colab 上使用自己的数据集对 gpt-2 进行了微调,并且设法生成了文本,但是当我下载模型并尝试在 spyder 中生成文本时,我收到了这个 ValueError: Trying to share variable model/wpe,but specified shape (1024,1280) 并找到形状 (1024,768)。

这是我运行的代码` 将 gpt_2_simple 导入为 gpt2

          sess = gpt2.start_tf_sess()
          gpt2.load_gpt2(sess,run_name='path to model file')
          gpt2.generate(sess,temperature=0.7,top_k=40,nsamples=1,batch_size=1,length=200,sample_delim=''
          )` 

这里是错误

` 文件“”,第 11 行,在 sample_delim=''

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\gpt_2_simple\gpt_2.py”,第459行,生成 温度=温度,top_k=top_k,top_p=top_p

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\gpt_2_simple\src\sample.py”,第67行,在sample_sequence中 context_output = step(hparams,context[:,:-1])

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\gpt_2_simple\src\sample.py”,第52行,步骤 过去=过去,重用=tf.compat.v1.AUTO_REUSE)

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\gpt_2_simple\src\model.py”,第183行,在模型中 初始值设定项=tf.compat.v1.random_normal_initializer(stddev=0.01))

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py”,第 1501 行,在 get_variable 中 聚合=聚合)

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py”,第 1244 行,在 get_variable 中 聚合=聚合)

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py”,第 567 行,在 get_variable 中 聚合=聚合)

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py”,第519行,_true_getter 聚合=聚合)

文件“C:\Users\Wahiba\anaconda3\envs\PythonKerascpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py”,第 874 行,在 _get_single_variable (名称,形状,found_var.get_shape()))

ValueError: 试图共享变量模型/wpe,但指定形状 (1024,768)。 `

enter image description here enter image description here

我做错了什么?

解决方法

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

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

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