Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generate() - During handling of the above exception, another exception occurred #223

Open
skorotkiewicz opened this issue Jul 23, 2020 · 1 comment

Comments

@skorotkiewicz
Copy link

Tensorflow: 1.15.2
Python: 3.6.10
CUDA: 10.0.130_411.31_win10
cudNN: 10.0-windows10-x64-v7.6.5.32

generate.py

import gpt_2_simple as gpt2
import os
import requests

model_name = "124M"
file_name = "tekst.txt"
sess = gpt2.start_tf_sess()
gpt2.generate(sess)

Finetuning by the CPU is done without any problems, but I can't generate any text because the following errors are coming out:

(tf-cpu) C:\Users\sebas\Desktop\GPT-2\gpt-2-simple>python generate.py
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

2020-07-23 11:54:58.675088: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1365, in _do_call
    return fn(*args)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1350, in _run_fn         target_list, run_metadata)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1443, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value model/h8/attn/c_attn/b
         [[{{node model/h8/attn/c_attn/b/read}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "generate.py", line 10, in <module>
    gpt2.generate(sess)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\gpt_2.py", line 475, in generate
    out = sess.run(output)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run
    run_metadata_ptr)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1180, in _run            feed_dict_tensor, options, run_metadata)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1359, in _do_run         run_metadata)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\client\session.py", line 1384, in _do_call        raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value model/h8/attn/c_attn/b
         [[node model/h8/attn/c_attn/b/read (defined at C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\framework\ops.py:1748) ]]

Original stack trace for 'model/h8/attn/c_attn/b/read':
  File "generate.py", line 10, in <module>
    gpt2.generate(sess)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\gpt_2.py", line 466, in generate
    temperature=temperature, top_k=top_k, top_p=top_p
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\sample.py", line 67, in sample_sequence
    context_output = step(hparams, context[:, :-1])
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\sample.py", line 52, in step
    past=past, reuse=tf.compat.v1.AUTO_REUSE)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\model.py", line 197, in model
    h, present = block(h, 'h%d' % layer, past=past, hparams=hparams)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\model.py", line 156, in block
    a, present = attn(norm(x, 'ln_1'), 'attn', nx, past=past, hparams=hparams)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\model.py", line 132, in attn
    c = conv1d(x, 'c_attn', n_state*3)
  File "C:\Users\sebas\Desktop\GPT-2\gpt-2-simple\gpt_2_simple\src\model.py", line 84, in conv1d
    b = tf.compat.v1.get_variable('b', [nf], initializer=tf.compat.v1.constant_initializer(0))
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 1500, in get_variable
    aggregation=aggregation)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 1243, in get_variable
    aggregation=aggregation)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 567, in get_variable
    aggregation=aggregation)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 519, in _true_getter
    aggregation=aggregation)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 933, in _get_single_variable
    aggregation=aggregation)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 258, in __call__          return cls._variable_v1_call(*args, **kwargs)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 219, in _variable_v1_call
    shape=shape)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 197, in <lambda>          previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 2519, in default_variable_creator
    shape=shape)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 262, in __call__          return super(VariableMetaclass, cls).__call__(*args, **kwargs)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 1688, in __init__         shape=shape)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\variables.py", line 1872, in _init_from_args
    self._snapshot = array_ops.identity(self._variable, name="read")
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper           return target(*args, **kwargs)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\array_ops.py", line 203, in identity          ret = gen_array_ops.identity(input, name=name)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\ops\gen_array_ops.py", line 4238, in identity     "Identity", input=input, name=name)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\framework\op_def_library.py", line 794, in _apply_op_helper
    op_def=op_def)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\util\deprecation.py", line 507, in new_func       return func(*args, **kwargs)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3357, in create_op        attrs, op_def, compute_device)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "C:\Miniconda\envs\tf-cpu\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1748, in __init__         self._traceback = tf_stack.extract_stack()


(tf-cpu) C:\Users\sebas\Desktop\GPT-2\gpt-2-simple>
@briansemrau
Copy link

This is solved by loading the model before generating text.

sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess, model_name=model_name)  # <- this line is necessary
gpt2.generate(sess, model_name=model_name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants