_pickle.PicklingError: Can't pickle typing.Union[str, NoneType]: it's not the same object as typing.Union
Author: JeremySun1224
Pull request: no
Labels: name: wontfix

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version:3.4.0
- Platform:linux
- Python version:3.6
- PyTorch version (GPU?):1.6 cuda10
- Tensorflow version (GPU?):
- Using GPU in script?:
- Using distributed or parallel set-up in script?:

When I try to train roberta-wwm from scratch for my dataset , I get this error when I follow transformers' run_mlm_wwm.py code

```
!python run_mlm_wwm.py --model_name_or_path hfl/chinese-roberta-wwm-ext --train_file ../../../../pretrain_data/pretrain_train.txt --validation_file ../../../../pretrain_data/pretrain_val.txt --train_ref_file ../../../../pretrain_data/ref_train.txt --validation_ref_file ../../../../pretrain_data/ref_val.txt --do_train --do_eval --output_dir ./output
```

```
All the weights of BertForMaskedLM were initialized from the model checkpoint at hfl/chinese-roberta-wwm-ext.
If your task is similar to the task the model of the checkpoint was trained on, you can already use BertForMaskedLM for predictions without further training.
Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.
Traceback (most recent call last):
  File "run_mlm_wwm.py", line 333, in <module>
    main()
  File "run_mlm_wwm.py", line 274, in main
    load_from_cache_file=not data_args.overwrite_cache,
  File "/usr/local/lib/python3.6/dist-packages/datasets/dataset_dict.py", line 300, in map
    for k, dataset in self.items()
  File "/usr/local/lib/python3.6/dist-packages/datasets/dataset_dict.py", line 300, in <dictcomp>
    for k, dataset in self.items()
  File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 1256, in map
    update_data=update_data,
  File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 156, in wrapper
    out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 158, in wrapper
    self._fingerprint, transform, kwargs_for_fingerprint
  File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 105, in update_fingerprint
    hasher.update(transform_args[key])
  File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 57, in update
    self.m.update(self.hash(value).encode("utf-8"))
  File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 53, in hash
    return cls.hash_default(value)
  File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 46, in hash_default
    return cls.hash_bytes(dumps(value))
  File "/usr/local/lib/python3.6/dist-packages/datasets/utils/py_utils.py", line 367, in dumps
    dump(obj, file)
  File "/usr/local/lib/python3.6/dist-packages/datasets/utils/py_utils.py", line 339, in dump
    Pickler(file, recurse=True).dump(obj)
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 454, in dump
    StockPickler.dump(self, obj)
  File "/usr/lib/python3.6/pickle.py", line 409, in dump
    self.save(obj)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 1447, in save_function
    obj.__dict__, fkwdefaults), obj=obj)
  File "/usr/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.6/pickle.py", line 751, in save_tuple
    save(element)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 1178, in save_cell
    pickler.save_reduce(_create_cell, (f,), obj=obj)
  File "/usr/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/usr/lib/python3.6/pickle.py", line 521, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/lib/python3.6/pickle.py", line 605, in save_reduce
    save(cls)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 1374, in save_type
    obj.__bases__, _dict), obj=obj)
  File "/usr/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.6/pickle.py", line 751, in save_tuple
    save(element)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 941, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/usr/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 941, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/usr/lib/python3.6/pickle.py", line 507, in save
    self.save_global(obj, rv)
  File "/usr/lib/python3.6/pickle.py", line 927, in save_global
    (obj, module_name, name))
**_pickle.PicklingError: Can't pickle typing.Union[str, NoneType]: it's not the same object as typing.Union**
```
please help me.

<!-- A clear and concise description of what you would expect to happen. -->


Comments:
Maybe @sgugger has an idea

This is a duplicate of #8212 which gives the workaround (install python 3.7) while waiting for the new release of datasets, which will fix that bug.

Maybe we should do a quick patch release of `datasets` just for this one @lhoestq?

It seems an issue ´till Python 3.6 on Pickle (I´m exactly on 3.6). As I´m (really) on a hurry, just commented the error on Pickle and It run normally.

> This is a duplicate of #8212 which gives the workaround (install python 3.7) while waiting for the new release of datasets, which will fix that bug.

**Thank you very much. 🌹**
I did run the above code correctly in Python 3.7.9, but it's strange that the following error occurred. This didn't happen in my previous Python 3.6.9 environment.
Traceback (most recent call last):
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\connection.py", line 502, in _connect_tls_proxy
    ssl_context=ssl_context,
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\util\ssl_.py", line 424, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\util\ssl_.py", line 466, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\ssl.py", line 423, in wrap_socket
    session=session
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\ssl.py", line 870, in _create
    self.do_handshake()
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
**ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\urllib3\util\retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='s3.amazonaws.com', port=443): Max retries exceeded with url: /datasets.huggingface.co/datasets/datasets/text/text.py (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./run_mlm_wwm.py", line 336, in <module>
    main()
  File "./run_mlm_wwm.py", line 213, in main
    datasets = load_dataset(extension, data_files=data_files)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\datasets\load.py", line 590, in load_dataset
    path, script_version=script_version, download_config=download_config, download_mode=download_mode, dataset=True
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\datasets\load.py", line 264, in prepare_module
    head_hf_s3(path, filename=name, dataset=dataset)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\datasets\utils\file_utils.py", line 200, in head_hf_s3
    return requests.head(hf_bucket_url(identifier=identifier, filename=filename, use_cdn=use_cdn, dataset=dataset))
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\api.py", line 104, in head
    return request('head', url, **kwargs)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "D:\Anaconda3\envs\RobertaWWMExt\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='s3.amazonaws.com', port=443): Max retries exceeded with url: /datasets.huggingface.co/datasets/datasets/text/text.py **(Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)')))**

Could you give me a suggestion about this bug, please.

Pinging @julien-c and @Pierrci here additionally (connection to S3)

> Maybe we should do a quick patch release of `datasets` just for this one @lhoestq?

Yes will do a patch release soon

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.