fix `AutoModel.from_pretrained(..., torch_dtype=...)`
Author: stas00
Pull request: yes

This PR fixes one of the 2 issues reported in https://github.com/huggingface/transformers/issues/13076

```
python -c "import torch; from transformers import AutoModel; AutoModel.from_pretrained('sshleifer/tiny-gpt2', torch_dtype=torch.float16)"
2021-08-20 18:45:07.802651: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/mnt/nvme1/code/huggingface/transformers-master/src/transformers/models/auto/auto_factory.py", line 382, in from_pretrained
    config, kwargs = AutoConfig.from_pretrained(
  File "/mnt/nvme1/code/huggingface/transformers-master/src/transformers/models/auto/configuration_auto.py", line 511, in from_pretrained
    return config_class.from_dict(config_dict, **kwargs)
  File "/mnt/nvme1/code/huggingface/transformers-master/src/transformers/configuration_utils.py", line 581, in from_dict
    logger.info(f"Model config {config}")
  File "/mnt/nvme1/code/huggingface/transformers-master/src/transformers/configuration_utils.py", line 613, in __repr__
    return f"{self.__class__.__name__} {self.to_json_string()}"
  File "/mnt/nvme1/code/huggingface/transformers-master/src/transformers/configuration_utils.py", line 677, in to_json_string
    return json.dumps(config_dict, indent=2, sort_keys=True) + "\n"
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/home/stas/anaconda3/envs/py38-pt19/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type dtype is not JSON serializable
```

Additionally, it corrects the config object to convert the short "float32" string into `torch.float32` at object creation time.

Note, I had a to change `from_dict` a bit to preserve `torch_dtype` arg in `AutoModel.from_pretrained(..., torch_dtype=...), as without this change `from_pretrained` was ignoring this argument.

To remind, the issue is that we decided to store `torch_dtype` in the config object, but ignore it for now at load time. Which this PR also documents.

Of course, tests added.

Thank you.

Fixes: https://github.com/huggingface/transformers/issues/13076

(note: 2 separate issues were reported there but it looks like only this is the real issue, so linking to close it with this PR)

@sgugger, @LysandreJik 



Comments:
Note, I first tried a simple monkeypatching method, but it doesn't work with C extensions, which `torch.dtype` is:

```
        if config.torch_dtype is not None:
            # in v5 convert str to torch.dtype
            import torch
            if not hasattr(torch.dtype, "to_json_string"):
                import builtins
                #torch.dtype.to_json_string = builtins.str
                setattr(torch.dtype, "to_json_string", builtins.str)
```
got:
```
setattr(torch.dtype, "to_json_string", builtins.str)
TypeError: can't set attributes of built-in/extension type 'torch.dtype'
```