Skip to content

Commit 3d4424b

Browse files
kiukchungfacebook-github-bot
authored andcommitted
(torchx/components) Remove dependency to pyre_extensions (#1088)
Summary: 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 3d4424b

19 files changed

+110
-86
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from torchx.specs import (
1818
AppDef,
19-
AppDryRunInfo,
19+
AppDryRunInfo, # noqa F401 reexport
2020
AppState,
2121
NONE,
2222
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: 1 addition & 1 deletion
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

@@ -43,7 +44,6 @@
4344
from torchx.schedulers.ids import make_unique
4445
from torchx.specs.api import AppDef, AppState, CfgVal, runopts
4546
from torchx.workspace.docker_workspace import DockerWorkspaceMixin
46-
from typing_extensions import TypedDict
4747

4848

4949
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: 5 additions & 5 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,6 +46,7 @@
4646
Optional,
4747
Tuple,
4848
TYPE_CHECKING,
49+
TypedDict,
4950
)
5051

5152
import torchx
@@ -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

@@ -994,7 +994,7 @@ def _submit_dryrun(
994994
if image_secret is not None and service_account is not None:
995995
msg = """Service Account and Image Secret names are both provided.
996996
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
997+
If this is the case, check service account and image secret configurations to understand the expected behavior for
998998
patched image push access."""
999999
warnings.warn(msg)
10001000
namespace = cfg.get("namespace")

torchx/schedulers/kubernetes_scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import torchx
5050
import yaml
5151
from torchx.schedulers.api import (
52-
AppDryRunInfo,
5352
DescribeAppResponse,
5453
filter_regex,
5554
ListAppResponse,
@@ -60,6 +59,7 @@
6059
from torchx.schedulers.ids import make_unique
6160
from torchx.specs.api import (
6261
AppDef,
62+
AppDryRunInfo,
6363
AppState,
6464
BindMount,
6565
CfgVal,

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,

torchx/schedulers/ray_scheduler.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@
1414
from dataclasses import dataclass, field
1515
from datetime import datetime
1616
from shutil import copy2, rmtree
17-
from typing import Any, cast, Dict, Final, Iterable, List, Optional, Tuple # noqa
17+
from typing import ( # noqa
18+
Any,
19+
cast,
20+
Dict,
21+
Final,
22+
Iterable,
23+
List,
24+
Optional,
25+
Tuple,
26+
TypedDict,
27+
)
1828

1929
import urllib3
2030

@@ -23,7 +33,6 @@
2333
from ray.dashboard.modules.job.sdk import JobSubmissionClient
2434

2535
from torchx.schedulers.api import (
26-
AppDryRunInfo,
2736
AppState,
2837
DescribeAppResponse,
2938
filter_regex,
@@ -36,7 +45,6 @@
3645
from torchx.schedulers.ray.ray_common import RayActor, TORCHX_RANK0_HOST
3746
from torchx.specs import AppDef, macros, NONE, ReplicaStatus, Role, RoleStatus, runopts
3847
from torchx.workspace.dir_workspace import TmpDirWorkspaceMixin
39-
from typing_extensions import TypedDict
4048

4149

4250
class RayOpts(TypedDict, total=False):

torchx/schedulers/slurm_scheduler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
from dataclasses import dataclass
2222
from datetime import datetime
2323
from subprocess import CalledProcessError, PIPE
24-
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple
24+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, TypedDict
2525

2626
import torchx
2727
from torchx.schedulers.api import (
28-
AppDryRunInfo,
2928
DescribeAppResponse,
3029
filter_regex,
3130
ListAppResponse,
@@ -36,6 +35,7 @@
3635
from torchx.schedulers.local_scheduler import LogIterator
3736
from torchx.specs import (
3837
AppDef,
38+
AppDryRunInfo,
3939
AppState,
4040
macros,
4141
NONE,
@@ -46,7 +46,6 @@
4646
runopts,
4747
)
4848
from torchx.workspace.dir_workspace import DirWorkspaceMixin
49-
from typing_extensions import TypedDict
5049

5150
SLURM_JOB_DIRS = ".torchxslurmjobdirs"
5251

0 commit comments

Comments
 (0)