Skip to content

Commit d7d5d7d

Browse files
kiukchungfacebook-github-bot
authored andcommitted
(torchx/components) Remove dependency to pyre_extensions (#1088)
Summary: Pull Request resolved: #1088 There was only a single usage of `pyre_extensions` in the entire code base. Get rid of this dependency by using an `assert` statement rather than `pyre_extensions.none_throws`. Reviewed By: highker Differential Revision: D77621041
1 parent 7fabab4 commit d7d5d7d

22 files changed

+135
-99
lines changed

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ torchmetrics==1.6.3
3030
torchserve>=0.10.0
3131
torchtext==0.18.0
3232
torchvision==0.22.0
33+
typing-extensions
3334
ts==0.5.1
3435
ray[default]
3536
wheel

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pyre-extensions
21
docstring-parser>=0.8.1
32
importlib-metadata
43
pyyaml

torchx/components/structured_arg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from pathlib import Path
3131
from typing import Optional
3232

33-
from pyre_extensions import none_throws
34-
3533
from torchx import specs
3634

3735

@@ -148,7 +146,8 @@ def parse_from(
148146
if m: # use the last module name
149147
run_name = m.rpartition(".")[2]
150148
else: # use script name w/ no extension
151-
run_name = Path(none_throws(script)).stem
149+
assert script, "`script` can't be `None` here due checks above"
150+
run_name = Path(script).stem
152151
return StructuredNameArgument(
153152
experiment_name or default_experiment_name, run_name
154153
)

torchx/runner/api.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
import warnings
1515
from datetime import datetime
1616
from types import TracebackType
17-
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar
17+
from typing import (
18+
Any,
19+
Dict,
20+
Iterable,
21+
List,
22+
Mapping,
23+
Optional,
24+
Tuple,
25+
Type,
26+
TYPE_CHECKING,
27+
TypeVar,
28+
)
1829

1930
from torchx.runner.events import log_event
2031
from torchx.schedulers import get_scheduler_factories, SchedulerFactory
@@ -43,7 +54,9 @@
4354

4455
from torchx.util.types import none_throws
4556
from torchx.workspace.api import PkgInfo, WorkspaceBuilder, WorkspaceMixin
46-
from typing_extensions import Self
57+
58+
if TYPE_CHECKING:
59+
from typing_extensions import Self
4760

4861
from .config import get_config, get_configs
4962

@@ -121,7 +134,7 @@ def _get_scheduler_params_from_env(self) -> Dict[str, str]:
121134
scheduler_params[lower_case_key.strip("torchx_")] = value
122135
return scheduler_params
123136

124-
def __enter__(self) -> Self:
137+
def __enter__(self) -> "Self":
125138
return self
126139

127140
def __exit__(

torchx/schedulers/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
# pyre-strict
99

1010
import importlib
11-
from typing import Dict, Mapping
11+
from typing import Mapping, Protocol
1212

1313
from torchx.schedulers.api import Scheduler
1414
from torchx.util.entrypoints import load_group
15-
from typing_extensions import Protocol
1615

1716
DEFAULT_SCHEDULER_MODULES: Mapping[str, str] = {
1817
"local_docker": "torchx.schedulers.docker_scheduler",
@@ -44,15 +43,15 @@ def run(*args: object, **kwargs: object) -> Scheduler:
4443

4544
def get_scheduler_factories(
4645
group: str = "torchx.schedulers", skip_defaults: bool = False
47-
) -> Dict[str, SchedulerFactory]:
46+
) -> dict[str, SchedulerFactory]:
4847
"""
4948
get_scheduler_factories returns all the available schedulers names under `group` and the
5049
method to instantiate them.
5150
5251
The first scheduler in the dictionary is used as the default scheduler.
5352
"""
5453

55-
default_schedulers: Dict[str, SchedulerFactory] = {}
54+
default_schedulers: dict[str, SchedulerFactory] = {}
5655
for scheduler, path in DEFAULT_SCHEDULER_MODULES.items():
5756
default_schedulers[scheduler] = _defer_load_scheduler(path)
5857

torchx/schedulers/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from torchx.specs import (
1818
AppDef,
19-
AppDryRunInfo,
2019
AppState,
2120
NONE,
2221
NULL_RESOURCE,

torchx/schedulers/aws_batch_scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
Optional,
5454
Tuple,
5555
TYPE_CHECKING,
56+
TypedDict,
5657
TypeVar,
5758
)
5859

5960
import torchx
6061
import yaml
6162
from torchx.schedulers.api import (
62-
AppDryRunInfo,
6363
DescribeAppResponse,
6464
filter_regex,
6565
ListAppResponse,
@@ -71,6 +71,7 @@
7171
from torchx.schedulers.ids import make_unique
7272
from torchx.specs.api import (
7373
AppDef,
74+
AppDryRunInfo,
7475
AppState,
7576
BindMount,
7677
CfgVal,
@@ -86,7 +87,6 @@
8687
from torchx.specs.named_resources_aws import instance_type_from_resource
8788
from torchx.util.types import none_throws
8889
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
89-
from typing_extensions import TypedDict
9090

9191
ENV_TORCHX_ROLE_IDX = "TORCHX_ROLE_IDX"
9292

torchx/schedulers/aws_sagemaker_scheduler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
OrderedDict,
2626
Tuple,
2727
TYPE_CHECKING,
28+
TypedDict,
2829
TypeVar,
2930
)
3031

@@ -34,16 +35,14 @@
3435
from sagemaker.pytorch import PyTorch
3536
from torchx.components.structured_arg import StructuredNameArgument
3637
from torchx.schedulers.api import (
37-
AppDryRunInfo,
3838
DescribeAppResponse,
3939
ListAppResponse,
4040
Scheduler,
4141
Stream,
4242
)
4343
from torchx.schedulers.ids import make_unique
44-
from torchx.specs.api import AppDef, AppState, CfgVal, runopts
44+
from torchx.specs.api import AppDef, AppDryRunInfo, AppState, CfgVal, runopts
4545
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
46-
from typing_extensions import TypedDict
4746

4847

4948
if TYPE_CHECKING:

torchx/schedulers/docker_scheduler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
import tempfile
1414
from dataclasses import dataclass
1515
from datetime import datetime
16-
from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING, Union
16+
from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING, TypedDict, Union
1717

1818
import torchx
1919
import yaml
2020
from torchx.schedulers.api import (
21-
AppDryRunInfo,
2221
DescribeAppResponse,
2322
filter_regex,
2423
ListAppResponse,
@@ -30,6 +29,7 @@
3029
from torchx.schedulers.ids import make_unique
3130
from torchx.specs.api import (
3231
AppDef,
32+
AppDryRunInfo,
3333
AppState,
3434
BindMount,
3535
DeviceMount,
@@ -42,7 +42,6 @@
4242
VolumeMount,
4343
)
4444
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
45-
from typing_extensions import TypedDict
4645

4746

4847
if TYPE_CHECKING:

torchx/schedulers/gcp_batch_scheduler.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424

2525
from dataclasses import dataclass
2626
from datetime import datetime
27-
from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING
27+
from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING, TypedDict
2828

2929
import torchx
3030
import yaml
3131

3232
from torchx.schedulers.api import (
33-
AppDryRunInfo,
3433
DescribeAppResponse,
3534
ListAppResponse,
3635
Scheduler,
3736
Stream,
3837
)
3938
from torchx.schedulers.ids import make_unique
40-
from torchx.specs.api import AppDef, AppState, macros, Resource, Role, runopts
39+
from torchx.specs.api import (
40+
AppDef,
41+
AppDryRunInfo,
42+
AppState,
43+
macros,
44+
Resource,
45+
Role,
46+
runopts,
47+
)
4148
from torchx.util.strings import normalize_str
42-
from typing_extensions import TypedDict
4349

4450

4551
if TYPE_CHECKING:

torchx/schedulers/kubernetes_mcad_scheduler.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
1818
TorchX Kubernetes_MCAD scheduler depends on AppWrapper + MCAD.
1919
20-
Install MCAD:
21-
See deploying Multi-Cluster-Application-Dispatcher guide
20+
Install MCAD:
21+
See deploying Multi-Cluster-Application-Dispatcher guide
2222
https://github.com/project-codeflare/multi-cluster-app-dispatcher/blob/main/doc/deploy/deployment.md
2323
2424
This implementation requires MCAD v1.34.1 or higher.
@@ -46,12 +46,12 @@
4646
Optional,
4747
Tuple,
4848
TYPE_CHECKING,
49+
TypedDict,
4950
)
5051

5152
import torchx
5253
import yaml
5354
from torchx.schedulers.api import (
54-
AppDryRunInfo,
5555
DescribeAppResponse,
5656
filter_regex,
5757
ListAppResponse,
@@ -62,6 +62,7 @@
6262
from torchx.schedulers.ids import make_unique
6363
from torchx.specs.api import (
6464
AppDef,
65+
AppDryRunInfo,
6566
AppState,
6667
BindMount,
6768
CfgVal,
@@ -78,7 +79,6 @@
7879
)
7980

8081
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
81-
from typing_extensions import TypedDict
8282

8383
if TYPE_CHECKING:
8484
from docker import DockerClient
@@ -600,7 +600,7 @@ def app_to_resource(
600600

601601
"""
602602
Create Service:
603-
The selector will have the key 'appwrapper.workload.codeflare.dev', and the value will be
603+
The selector will have the key 'appwrapper.workload.codeflare.dev', and the value will be
604604
the appwrapper name
605605
"""
606606

@@ -797,7 +797,8 @@ class KubernetesMCADOpts(TypedDict, total=False):
797797

798798

799799
class KubernetesMCADScheduler(
800-
DockerWorkspaceMixin, Scheduler[KubernetesMCADOpts, AppDef, AppDryRunInfo]
800+
DockerWorkspaceMixin,
801+
Scheduler[KubernetesMCADOpts, AppDef, AppDryRunInfo[KubernetesMCADJob]],
801802
):
802803
"""
803804
KubernetesMCADScheduler is a TorchX scheduling interface to Kubernetes.
@@ -994,7 +995,7 @@ def _submit_dryrun(
994995
if image_secret is not None and service_account is not None:
995996
msg = """Service Account and Image Secret names are both provided.
996997
Depending on the Service Account configuration, an ImagePullSecret may be defined in your Service Account.
997-
If this is the case, check service account and image secret configurations to understand the expected behavior for
998+
If this is the case, check service account and image secret configurations to understand the expected behavior for
998999
patched image push access."""
9991000
warnings.warn(msg)
10001001
namespace = cfg.get("namespace")

torchx/schedulers/kubernetes_scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
Optional,
4545
Tuple,
4646
TYPE_CHECKING,
47+
TypedDict,
4748
)
4849

4950
import torchx
5051
import yaml
5152
from torchx.schedulers.api import (
52-
AppDryRunInfo,
5353
DescribeAppResponse,
5454
filter_regex,
5555
ListAppResponse,
@@ -60,6 +60,7 @@
6060
from torchx.schedulers.ids import make_unique
6161
from torchx.specs.api import (
6262
AppDef,
63+
AppDryRunInfo,
6364
AppState,
6465
BindMount,
6566
CfgVal,
@@ -75,7 +76,6 @@
7576
)
7677
from torchx.util.strings import normalize_str
7778
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
78-
from typing_extensions import TypedDict
7979

8080

8181
if TYPE_CHECKING:

torchx/schedulers/local_scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
Protocol,
4141
TextIO,
4242
Tuple,
43+
TypedDict,
4344
)
4445

4546
from torchx.schedulers.api import (
46-
AppDryRunInfo,
4747
DescribeAppResponse,
4848
filter_regex,
4949
ListAppResponse,
@@ -53,10 +53,10 @@
5353
)
5454
from torchx.schedulers.ids import make_unique
5555
from torchx.schedulers.streams import Tee
56+
from torchx.specs import AppDryRunInfo
5657
from torchx.specs.api import AppDef, AppState, is_terminal, macros, NONE, Role, runopts
5758

5859
from torchx.util.types import none_throws
59-
from typing_extensions import TypedDict
6060

6161
log: logging.Logger = logging.getLogger(__name__)
6262

torchx/schedulers/lsf_scheduler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
import tempfile
3030
from dataclasses import dataclass
3131
from datetime import datetime
32-
from typing import Any, Dict, Iterable, List, Optional
32+
from typing import Any, Dict, Iterable, List, Optional, TypedDict
3333

3434
import torchx
3535
from torchx.schedulers.api import (
36-
AppDryRunInfo,
3736
DescribeAppResponse,
3837
filter_regex,
3938
ListAppResponse,
@@ -45,6 +44,7 @@
4544
from torchx.schedulers.local_scheduler import LogIterator
4645
from torchx.specs import (
4746
AppDef,
47+
AppDryRunInfo,
4848
AppState,
4949
BindMount,
5050
DeviceMount,
@@ -57,7 +57,6 @@
5757
VolumeMount,
5858
)
5959
from torchx.util import shlex
60-
from typing_extensions import TypedDict
6160

6261
JOB_STATE: Dict[str, AppState] = {
6362
"DONE": AppState.SUCCEEDED,

0 commit comments

Comments
 (0)