SSL3 errors from probable network issue

I finally got the :hugs: transformer library installed with CUDA support under WSL 2 Ubuntu. Yay.

- `transformers` version: 4.2.0dev0
- Platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.29
- Python version: 3.8.5
- PyTorch version (GPU?): 1.7.0 (True)
- Tensorflow version (GPU?): 2.3.1 (True)
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

However, something in the stack is giving me an unreliable network connection that :hugs: reacts badly to.

This is what I’m trying to do (standard install test - I added the resume_download optional argument after reading a bug fix report. It doesn’t help). The question is, is there either a way to MANUALLY download models from HF into its cache, or is there a setting that does re-tries from the current file position in such cases?

python -c "from transformers import pipeline; print(pipeline('sentiment-analysis',resume_download=True)('we love you'))"

A few megabytes into the download (it varies randomly, but never more than 60), I get the following exception:
(“read error: Error([(‘SSL routines’, ‘ssl3_get_record’, ‘decryption failed or bad record mac’)])”,)

`("read error: Error([('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')])",)                            | 6.65M/268M [00:02<01:12, 3.60MB/s]`
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 313, in recv_into
        return self.connection.recv_into(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1822, in recv_into
        self._raise_ssl_error(self._ssl, result)
      File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
        _raise_current_error()
      File "/usr/lib/python3/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
        raise exception_type(errors)
    OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]

The exception handler for that apparently is subject to the same exception:
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mjw/transformers/src/transformers/modeling_utils.py", line 1003, in from_pretrained
    resolved_archive_file = cached_path(
  File "/home/mjw/transformers/src/transformers/file_utils.py", line 1077, in cached_path
    output_path = get_from_cache(
  File "/home/mjw/transformers/src/transformers/file_utils.py", line 1303, in get_from_cache
    http_get(url_to_download, temp_file, proxies=proxies, resume_size=resume_size, headers=headers)
  File "/home/mjw/transformers/src/transformers/file_utils.py", line 1166, in http_get
    for chunk in r.iter_content(chunk_size=1024):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/lib/python3/dist-packages/urllib3/response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/lib/python3/dist-packages/urllib3/response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/usr/lib/python3.8/http/client.py", line 458, in read
    n = self.readinto(b)
  File "/usr/lib/python3.8/http/client.py", line 502, in readinto
    n = self.fp.readinto(b)
  File "/usr/lib/python3.8/socket.py", line 669, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 332, in recv_into
    raise ssl.SSLError("read error: %r" % e)
ssl.SSLError: ("read error: Error([('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')])",)

That extra resume-download argument turns out to be invalid, once the download succeeds randomly once. So ignore that

Got it! Is it all solved, then @witbrock?

Happy new year!

For next time, you could try cloning the model with git:

git lfs install
git clone https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english

And then loading it from its directory

(^ that’s the model used by the sentiment-analysis pipeline)