Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend typing to path-like objects in PretrainedConfig and PreTrainedModel #8770

Merged
merged 9 commits into from
Nov 27, 2020

Conversation

gcompagnoni
Copy link
Contributor

@gcompagnoni gcompagnoni commented Nov 24, 2020

What does this PR do?

In my experience, I often call the from_pretrained and save_pretrained methods of models and configurations with a path-like variable rather than a string. Since the paths are then used by various os functions, this works just fine: however, the relevant variables are typed as strings only, raising warnings when using an IDE 😧 .

This PR extends the typing to Union[str, os.PathLike] when relevant inside PretrainedConfig and PreTrainedModel methods.
Since passing a path-like object is already tacitly supported in most cases, no significant changes to the code are necessary. In a few places, the relevant variable needs to be turned to a string in order to support functions such as is_remote_url.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors which may be interested in your PR.

Maybe (documentation): @sgugger

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@thomwolf
Copy link
Member

Good idea!

This could be done for tokenizers as well, no? (the from_pretrained for tokenizers is in tokenization_utils_base.py)

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

@gcompagnoni
Copy link
Contributor Author

I have extended the same modifications to the tokenizers, as suggested by @thomwolf , and to auto classes too.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks a lot!

@sgugger sgugger merged commit f9a2a9e into huggingface:master Nov 27, 2020
stas00 pushed a commit to stas00/transformers that referenced this pull request Dec 5, 2020
…nedModel` (huggingface#8770)

* update configuration_utils.py typing to allow pathlike objects when sensible

* update modeling_utils.py typing to allow pathlike objects when sensible

* black

* update tokenization_utils_base.py typing to allow pathlike objects when sensible

* update tokenization_utils_fast.py typing to allow pathlike objects when sensible

* update configuration_auto.py typing to allow pathlike objects when sensible

* update configuration_auto.py docstring to allow pathlike objects when sensible

* update tokenization_auto.py docstring to allow pathlike objects when sensible

* black
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants