-
Notifications
You must be signed in to change notification settings - Fork 148
runopts: infer from TypedDict #708
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
base: main
Are you sure you want to change the base?
Conversation
|
cc @Sara-KS for the mcad changes -- should be a no-op, just moving image_repo opt to pull from the DockerWorkspaceMixin |
Codecov Report
@@ Coverage Diff @@
## main #708 +/- ##
==========================================
- Coverage 92.54% 92.54% -0.01%
==========================================
Files 86 86
Lines 5742 5767 +25
==========================================
+ Hits 5314 5337 +23
- Misses 428 430 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
462586e to
29420cb
Compare
kiukchung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, commented on a philosophical question around the new typing.Required and typing.NotRequired types in python 3.11 and their co-usages with Optional
|
|
||
| class DockerOpts(TypedDict, total=False): | ||
| """ | ||
| Attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use google-style docstring for these like everywhere else in torchx?
"""
Attributes:
copy_env: list of glob patterns of environment variables to copy if not set in AppDef. Ex: FOO_*"
"""
I validated that the runopts.from_typed_dict() parses google-style as well as numpy style docstrings equally as well.
| else: | ||
| # pyre-fixme[29]: not a function | ||
| default = default_factory() | ||
| required = not ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is going to get interesting in python 3.11 with PEP-0655 that introduces typing.Required and typing.NotRequired.
A couple of interesting questions:
- how do we interpret a
Required[Optional[int]]? (disallow it? allow "required" Optional cfgs? or implicitly make this required?) - are there differences between declaring a cfg as
Optional[int]versusNotRequired[int]? (technically the former would be in the runopt asNoneby default, and the later would simply not exist in runopt <- this concept doesn't exist in runopt yet so we'd have to default it toNone, but then the typing breaks)
This adds a new
runopts.from_typed_dictmethod and uses it to generate the runopts from the typed dict field, annotations, default parameters and docstring.This simplifies adding new fields to schedulers since you only need to define it in a single spot.
I've migrated DockerScheduler to use the new runopts and will do the rest in a follow up PR.
Test plan: