ConnectionError during Modelcard creation causes crash at the end of a training run
Author: jphme
Pull request: no

### System Info

- `transformers` version: 4.34.0.dev0
- Platform: Linux-5.15.0-84-generic-x86_64-with-glibc2.35
- Python version: 3.9.18
- Huggingface_hub version: 0.16.4
- Safetensors version: 0.3.3
- Accelerate version: 0.24.0.dev0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.1+cu118 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?:y
- Using distributed or parallel set-up in script?:y

### Who can help?

@muellerz 

Transformers crashes due to a `ConnectionError` during a (mostly unnecessary and not configurable) step in model card creation, which is especially annoying because it makes it impossible to determine from exit code whether a training run has completed successfully.

```bash
Traceback (most recent call last):
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 466, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 461, in _make_request
    httplib_response = conn.getresponse()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/root/miniconda3/envs/py3.9/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/ssl.py", line 1275, in recv_into
    return self.read(nbytes, buffer)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/ssl.py", line 1133, 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 "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 798, in urlopen
    retries = retries.increment(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 466, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 461, in _make_request
    httplib_response = conn.getresponse()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/root/miniconda3/envs/py3.9/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/root/miniconda3/envs/py3.9/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/ssl.py", line 1275, in recv_into
    return self.read(nbytes, buffer)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/ssl.py", line 1133, in read
    return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/workspace/axolotl/scripts/finetune.py", line 54, in <module>
    fire.Fire(do_cli)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/workspace/axolotl/scripts/finetune.py", line 50, in do_cli
    train(cfg=parsed_cfg, cli_args=parsed_cli_args, dataset_meta=dataset_meta)
  File "/workspace/axolotl/src/axolotl/train.py", line 144, in train
    trainer.create_model_card(model_name=cfg.output_dir.lstrip("./"))
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/transformers/trainer.py", line 3634, in create_model_card
    training_summary = TrainingSummary.from_trainer(
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/transformers/modelcard.py", line 613, in from_trainer
    return cls(
  File "<string>", line 17, in __init__
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/transformers/modelcard.py", line 386, in __post_init__
    info = model_info(self.finetuned_from)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/huggingface_hub/hf_api.py", line 1677, in model_info
    r = get_session().get(path, headers=headers, timeout=timeout, params=params)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/huggingface_hub/utils/_http.py", line 63, in send
    return super().send(request, *args, **kwargs)
  File "/root/miniconda3/envs/py3.9/lib/python3.9/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: (ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')), '(Request ID: de2bbd7c-3153-42b7-b757-118cc56ca729)')
```


### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Use `trainer.create_model_card()` if there is some Connection problem on either side.

### Expected behavior

ConnectionError Exception should be caught like HTTPError and not lead to an uncontrolled crash

Comments: