Added support for pathlib.Path objects instead of string paths in from_pretrained() (resolves #3962)
Author: jaymody
Pull request: yes
Labels: name: wontfix

Resolves issue/feature request #3962 

This only covers string paths in `from_pretrained` (so vocab_file paths for` __init__` for tokenizers aren't covered). This may or may not be a feature that is desired (since it's fairly easy for the client to convert a path-like to a string). With the changes, you would be able to use `from_pretrained` with path-likes:

```
from pathlib import Path
from transformers import AutoModel, AutoTokenizer

my_path = Path("path/to/model_dir/")
AutoTokenizer.from_pretrained(my_path)
AutoModel.from_pretrained(my_path)
```

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=h1) Report
> Merging [#3975](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/4e817ff41885063e08bb3bcd63e5adfd835b9911&el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `85.00%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/3975/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #3975   +/-   ##
=======================================
  Coverage   78.44%   78.45%           
=======================================
  Files         111      111           
  Lines       18518    18534   +16     
=======================================
+ Hits        14527    14541   +14     
- Misses       3991     3993    +2     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/tokenization\_transfo\_xl.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fdHJhbnNmb194bC5weQ==) | `40.57% <50.00%> (-0.10%)` | :arrow_down: |
| [src/transformers/file\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9maWxlX3V0aWxzLnB5) | `68.68% <75.00%> (-0.19%)` | :arrow_down: |
| [src/transformers/configuration\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX3V0aWxzLnB5) | `96.57% <100.00%> (+0.02%)` | :arrow_up: |
| [src/transformers/modelcard.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGNhcmQucHk=) | `87.80% <100.00%> (+0.15%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `93.10% <100.00%> (+0.34%)` | :arrow_up: |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `90.95% <100.00%> (+0.01%)` | :arrow_up: |
| [src/transformers/tokenization\_auto.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fYXV0by5weQ==) | `97.50% <100.00%> (+0.13%)` | :arrow_up: |
| [src/transformers/tokenization\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3975/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fdXRpbHMucHk=) | `89.73% <100.00%> (+0.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=footer). Last update [4e817ff...033d5f8](https://codecov.io/gh/huggingface/transformers/pull/3975?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


On second thought, I probably would't merge this. I think it's better to just let the user deal with this on their end.

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.