Unifying training argument type annotations#17934
Unifying training argument type annotations#17934sgugger merged 4 commits intohuggingface:mainfrom jannisborn:main
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
|
I understand that the tests are failing because of: ValueError: Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union` because
the argument parser only supports one type per argument. Problem encountered in field 'evaluation_strategy'.Could this issue of not supporting multiple types be fixed in HF itself? I guess no since it's introduced upstream by Ultimately, this is inconsistency between the type annotations and the actually possible types is caused by HF. I think it's quite problematic because it's a systematic inconsistency that makes things appear more complex as they are. If the annotation has to be a single type, then should it not be the simplest type that can actually be used, in this case |
|
The type is not perfectly exact, but note that:
So to be able to accept the change in type, we would need some custom code in |
|
Looking at this from the surface, it seems that this PR is (partially?) covered by the PR that was merged earlier today? #17933 There:
|
|
We don't have the error anymore, but we are still losing the autofill of "choices" and all the custom logic we had for enums here. |
|
Thanks a lot @BramVanroy, that's a nice coincidence!! @sgugger: Could we move up that logic about the autofill to an |
|
I think there should be an if at line 94 that replaces the Basically something like: if type(None) not in field.type.__args__:
# filter `str` in Union
field.type = field.type.__args__[0] if field.type.__args__[1] == str else field.type.__args__[1]
origin_type = getattr(field.type, "__origin__", field.type)
elif bool not in field.type.__args__:before and replacing the line if bool not in field.type.__args__: |
|
Just did that! |
|
Thanks! Will play a bit with it tomorrow morning to triple-check nothing breaks then it should be good to merge! |
|
All good in my tests, thanks again for your work on this! |
* doc: Unify training arg type annotations * wip: extracting enum type from Union * blackening
What does this PR do?
This PR fixes the incorrect type annotations in the
TrainingArgumentsclass. Some arguments can handle complex types likeevaluation_strategy: IntervalStrategy. However, when calling from CLI, they can be initialized using astras well which is not reflected in the type annotations.Solution: Fix the type annotations to
Union[ComplexType, str].Note that this PR simply ensures consistency between the docstrings and the annotated types. E.g., the docstring for
evaluation_strategyis already:Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
Please have a look @sgugger!