Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

python - Incompatible shape error in tensorflow when I try to run generate function of gpt-2?

I have finetuned gpt-2 with my own dataset on colab and I managed to generate text but when I downloaded my model and tried to generate text in spyder I got this ValueError: Trying to share variable model/wpe, but specified shape (1024, 1280) and found shape (1024, 768).

Here is the code I run ` import gpt_2_simple as 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=''
          )` 

Here is the error:

` File "", line 11, in sample_delim=''

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesgpt_2_simplegpt_2.py", line 459, in generate temperature=temperature, top_k=top_k, top_p=top_p

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesgpt_2_simplesrcsample.py", line 67, in sample_sequence context_output = step(hparams, context[:, :-1])

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesgpt_2_simplesrcsample.py", line 52, in step past=past, reuse=tf.compat.v1.AUTO_REUSE)

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesgpt_2_simplesrcmodel.py", line 183, in model initializer=tf.compat.v1.random_normal_initializer(stddev=0.01))

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesensorflow_corepythonopsvariable_scope.py", line 1501, in get_variable aggregation=aggregation)

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesensorflow_corepythonopsvariable_scope.py", line 1244, in get_variable aggregation=aggregation)

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesensorflow_corepythonopsvariable_scope.py", line 567, in get_variable aggregation=aggregation)

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesensorflow_corepythonopsvariable_scope.py", line 519, in _true_getter aggregation=aggregation)

File "C:UsersWahibaanaconda3envsPythonKerasCPUlibsite-packagesensorflow_corepythonopsvariable_scope.py", line 874, in _get_single_variable (name, shape, found_var.get_shape()))

ValueError: Trying to share variable model/wpe, but specified shape (1024, 1280) and found shape (1024, 768). `

enter image description here enter image description here

What am I doing wrong?

question from:https://stackoverflow.com/questions/65934468/incompatible-shape-error-in-tensorflow-when-i-try-to-run-generate-function-of-gp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...