rish-16 / gpt2client

✍🏻 gpt2-client: Easy-to-use TensorFlow Wrapper for GPT-2 117M, 345M, 774M, and 1.5B Transformer Models 🤖 📝
MIT License
372 stars 74 forks source link

I don't even know what to say (Raspberry Pi) #21

Open remboldt opened 4 years ago

remboldt commented 4 years ago

Describe the bug I was doing some simple steps.. Wanted to try out gpt-2 on my raspberry pi and I got some errors.

To Reproduce Steps to reproduce the behavior:

  1. pip3 install tensorflow
  2. pip3 install gpt2-client
  3. sudo nano gpttest.py Then I wrote that code:
    from gpt2_client import GPT2Client
    gpt2en = GPT2Client("1558M")                                                 gpt2en.load_model(force_download=False)
    gpt2en.generate(interactive=True)                                            gpt2en.generate(n_samples=4)
    text = gpt2en.generate(return_text=True)
    print(text)
  4. python3 gpttest.py

Expected behavior It should download the 1.5B Model and I could play around with it.

My System

What happened The model downloaded like expected. But than I got lots of errors. I tried to run again, but got the same errors.

Log (after Files already downloaded)

pi@raspberrypi:~ $ python3 gpttest.py
/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:516: 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/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:517: 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/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:518: 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/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:519: 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/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:520: 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/pi/.local/lib/python3.7/site-packages/tensorflow_core/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_resource = np.dtype([("resource", np.ubyte, 1)])
/home/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: 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/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: 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/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: 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/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: 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/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: 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/pi/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: 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)])
WARNING:tensorflow:From /home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.

WARNING:tensorflow:From /home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.AttrValue is deprecated. Please use tf.compat.v1.AttrValue instead.

WARNING:tensorflow:From /home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.COMPILER_VERSION is deprecated. Please use tf.version.COMPILER_VERSION instead.

WARNING:tensorflow:From /home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.CXX11_ABI_FLAG is deprecated. Please use tf.sysconfig.CXX11_ABI_FLAG instead.

WARNING:tensorflow:From /home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.ConditionalAccumulator is deprecated. Please use tf.compat.v1.ConditionalAccumulator instead.

Loading checkpoint File already exists
Loading encoder.json File already exists
Loading hparams.json File already exists
Loading model.ckpt.data-00000-of-00001 File already exists
Loading model.ckpt.index File already exists
Loading model.ckpt.meta File already exists
Loading vocab.bpe File already exists

Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1348, in _do_call
return fn(*args)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1333, in _run_fn
target_list, run_metadata)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1421, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.OutOfRangeError: models/1558M/model.ckpt.data-00000-of-00001; Value too large for defined data type
[[{{node save/RestoreV2}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "gpttest.py", line 4, in <module>
gpt2en.generate(interactive=True)
File "/home/pi/.local/lib/python3.7/site-packages/gpt2_client/gpt2_client.py", line 148, in generate
saver.restore(sess, ckpt)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 1286, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 941, in run
run_metadata_ptr)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1164, in _run
feed_dict_tensor, options, run_metadata)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1342, in _do_run
run_metadata)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1362, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: models/1558M/model.ckpt.data-00000-of-00001; Value too large for defined data type
[[node save/RestoreV2 (defined at /home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py:1692) ]]

Original stack trace for 'save/RestoreV2':
File "gpttest.py", line 4, in <module>
gpt2en.generate(interactive=True)
File "/home/pi/.local/lib/python3.7/site-packages/gpt2_client/gpt2_client.py", line 146, in generate
saver = tf.train.Saver()
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 825, in __init__
self.build()
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 837, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 875, in _build
build_restore=build_restore)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 508, in _build_internal
restore_sequentially, reshape)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 328, in _AddRestoreOps
restore_sequentially)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/training/saver.py", line 575, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_io_ops.py", line 1696, in restore_v2
name=name)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 793, in _apply_op_helper
op_def=op_def)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3299, in create_op
op_def=op_def)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1692, in __init__
self._traceback = tf_stack.extract_stack()
rish-16 commented 4 years ago

Hey there,

You need to download the model weights first before being able to use it. Something like this:

gpt2en = GPT2Client('1558M')
gpt2en.load_model(force_download=True) 

I suggest redownloading it and overwriting the weight checkpoints using the force_download=True flag. In the case that it fails again, you may want to opt for a smaller model. I tried running it on a Raspberry Pi (I have a small cluster at home) and it didn't really work well and things got messy real soon.

Edit: I have looked online and have spoken to a few friends who also like to do TinyML projects. They suggest using the 117M model as it is the most lightweight and shouldn't cause many problems on a RaspPi

Hope this helps!