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

runopts: infer from TypedDict #708

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

runopts: infer from TypedDict #708

wants to merge 1 commit into from

Conversation

d4l3k
Copy link
Contributor

@d4l3k d4l3k commented Mar 18, 2023

This adds a new runopts.from_typed_dict method 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:

pytest torchx/specs/test/api_test.py torchx/schedulers/test/api_test.py

(torchx) rice@ariel ~/D/torchx (runopts_typedict)> torchx runopts local_docker
local_docker:
    usage:
        [copy_env=COPY_ENV],[image_repo=IMAGE_REPO]

    optional arguments:
        copy_env=COPY_ENV (typing.List[str], None)
            list of glob patterns of environment variables to copy if not set in AppDef. Ex: FOO_*",
        image_repo=IMAGE_REPO (str, None)
            (remote jobs) the image repository to use when pushing patched images, must have push access. Ex: example.com/your/con
tainer

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 18, 2023
@d4l3k d4l3k requested a review from kiukchung March 18, 2023 00:20
@d4l3k
Copy link
Contributor Author

d4l3k commented Mar 18, 2023

cc @Sara-KS for the mcad changes -- should be a no-op, just moving image_repo opt to pull from the DockerWorkspaceMixin

@codecov
Copy link

codecov bot commented Mar 18, 2023

Codecov Report

Merging #708 (fc01593) into main (3267fa9) will decrease coverage by 0.01%.
The diff coverage is 94.11%.

@@            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     
Impacted Files Coverage Δ
torchx/schedulers/docker_scheduler.py 95.83% <ø> (-0.09%) ⬇️
torchx/specs/api.py 97.93% <92.30%> (-0.48%) ⬇️
torchx/schedulers/api.py 94.64% <100.00%> (+0.30%) ⬆️
torchx/schedulers/gcp_batch_scheduler.py 91.62% <100.00%> (ø)
torchx/schedulers/kubernetes_mcad_scheduler.py 94.56% <100.00%> (-0.02%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@d4l3k d4l3k force-pushed the runopts_typedict branch 2 times, most recently from 462586e to 29420cb Compare March 18, 2023 00:42
Copy link
Collaborator

@kiukchung kiukchung left a 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

@@ -95,6 +94,13 @@ def has_docker() -> bool:


class DockerOpts(TypedDict, total=False):
"""
Attributes
Copy link
Collaborator

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 (
Copy link
Collaborator

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:

  1. how do we interpret a Required[Optional[int]]? (disallow it? allow "required" Optional cfgs? or implicitly make this required?)
  2. are there differences between declaring a cfg as Optional[int] versus NotRequired[int]? (technically the former would be in the runopt as None by 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 to None, but then the typing breaks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants