Skip to content

Commit f39d86c

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 f39d86c

22 files changed

+132
-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:

0 commit comments

Comments
 (0)