Support X | Y syntax on HfArgumentParser
Author: josecannete
Pull request: no

### Feature request

[PEP-604](https://peps.python.org/pep-0604/) created the X | Y syntax on python 3.10, which is equivalent to Union[X, Y]. The use of this syntax is not supported by HfArgumentParser.  

### Motivation

With this syntax I would like to use something like:

```
@dataclass
class ModelArguments:

    some_argument: str | None = field(
        default=None,
        metadata={"help": "some argument"},
    )
```

Instead of:

```
@dataclass
class ModelArguments:

    some_argument: Optional[str] = field(
        default=None,
        metadata={"help": "some argument"},
    )
```

When trying to use the first one, it throws an error:

```
Traceback (most recent call last):
  File "/home/jcanete/new-kd/kd/train.py", line 299, in <module>
    main()
  File "/home/jcanete/new-kd/kd/train.py", line 160, in main
    parser = HfArgumentParser(
  File "/home/jcanete/anaconda3/envs/venv/lib/python3.10/site-packages/transformers/hf_argparser.py", line 73, in __init__
    self._add_dataclass_arguments(dtype)
  File "/home/jcanete/anaconda3/envs/venv/lib/python3.10/site-packages/transformers/hf_argparser.py", line 178, in _add_dataclass_arguments
    self._parse_dataclass_field(parser, field)
  File "/home/jcanete/anaconda3/envs/venv/lib/python3.10/site-packages/transformers/hf_argparser.py", line 149, in _parse_dataclass_field
    parser.add_argument(field_name, **kwargs)
  File "/home/jcanete/anaconda3/envs/venv/lib/python3.10/argparse.py", line 1427, in add_argument
    raise ValueError('%r is not callable' % (type_func,))
ValueError: str | None is not callable
```



### Your contribution

Not sure if the best solution but changing [line 88 of hf_argparser.py](https://github.com/huggingface/transformers/blob/main/src/transformers/hf_argparser.py#L88) from:

`if origin_type is Union:`

to

`if origin_type is Union or type(origin_type) is UnionType:`

Does the trick on my local installation.

(it also requires to add the import of: `from types import UnionType`).



Comments:
Looks like adding support while not breaking previous Python version will be tricky, as `from types import UnionType` only work for Python 3.10 and above. We can look at a PR if you want to try a contribution, but I don't think we will add this ourselves until Python 3.10 is more widely supported (PyTorch and TensorFlow do not support Python 3.10 for instance).

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Ran into the same issue today. Any plan to support union-type annotations (`X | Y`)?

Now, Python 3.10 was released 1.5 years ago. It is widely used and has become the default Python version for `conda`. Also, if users have `from __future__ import annotations` in their scripts, some automation tools, such as `pyupgrade` / `ruff`, will automatically rewrite the type annotations (`Union[X, Y] -> X | Y`, `Optional[X] -> X | None`).