GPT2LMHeadModel not loading from pretrained

Python 3.7.6
Transformers 4.17.0
Pytorch 1.7.0

I have the following code:

from transformers import GPT2LMHeadModel
model = GPT2LMHeadModel.from_pretrained('gpt2')

and it is producing the following error:

2022-03-22 11:47:46.458873: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2022-03-22 11:47:46.458892: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Downloading: 100%|██████████| 665/665 [00:00<00:00, 279kB/s]
Downloading:   4%|▍         | 20.6M/523M [00:34<11:20, 774kB/s]Traceback (most recent call last):
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/urllib3/response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/home/aclifton/anaconda3/lib/python3.7/http/client.py", line 457, in read
    n = self.readinto(b)
  File "/home/aclifton/anaconda3/lib/python3.7/http/client.py", line 501, in readinto
    n = self.fp.readinto(b)
  File "/home/aclifton/anaconda3/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "/home/aclifton/anaconda3/lib/python3.7/ssl.py", line 1071, in recv_into
    return self.read(nbytes, buffer)
  File "/home/aclifton/anaconda3/lib/python3.7/ssl.py", line 929, in read
    return self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/requests/models.py", line 753, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/urllib3/response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/urllib3/response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/home/aclifton/anaconda3/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/urllib3/response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1366, in from_pretrained
    user_agent=user_agent,
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/transformers/file_utils.py", line 1929, in cached_path
    local_files_only=local_files_only,
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/transformers/file_utils.py", line 2217, in get_from_cache
    http_get(url_to_download, temp_file, proxies=proxies, resume_size=resume_size, headers=headers)
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/transformers/file_utils.py", line 2076, in http_get
    for chunk in r.iter_content(chunk_size=1024):
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/requests/models.py", line 756, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/aclifton/gpt2_dm/run_finetuning.py", line 10, in <module>
    model = GPT2LMHeadModel.from_pretrained('gpt2')
  File "/home/aclifton/anaconda3/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1421, in from_pretrained
    f"Can't load the model for '{pretrained_model_name_or_path}'. If you were trying to load it from "
OSError: Can't load the model for 'gpt2'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'gpt2' is the correct path to a directory containing a file named pytorch_model.bin, tf_model.h5, model.ckpt or flax_model.msgpack.
Downloading:   4%|▍         | 20.6M/523M [00:34<13:57, 629kB/s]

Process finished with exit code 1

Any thoughts about what I am doing wrong?

This is just a connection error. The download of the model was interrupted. Try again when the internet is better!

How stupid of me. I had my vpn on!! Turned it off and it downloaded immediately. Thanks Sylvain!

1 Like