Skip to content

Commit a45c4ca

Browse files
authored
[torchx/specs] Use default_factory for the default value of Role.resource and mlflow_test.Config.model_config to support python 3.11 clients (#768)
1 parent 12856f7 commit a45c4ca

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

.github/workflows/python-unittests.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
unittest:
1111
strategy:
1212
matrix:
13-
python-version: [3.8, 3.9, '3.10']
13+
python-version: [3.8, 3.9, "3.10", 3.11]
1414
platform: ["linux.20_04.4x"]
1515
include:
1616
- python-version: 3.9
@@ -32,7 +32,10 @@ jobs:
3232
run: |
3333
set -eux
3434
pip install pytest pytest-cov
35-
pip install -e .[dev]
35+
# use legacy resolver for python 3.11, otherwise pip will timeout trying to resolve deps
36+
# TODO(kiukchung) long term we should narrowly scope dependency versions
37+
# see: https://pip.pypa.io/en/latest/topics/dependency-resolution/
38+
pip install --use-deprecated=legacy-resolver -e .[dev]
3639
- name: Run tests
3740
run: pytest --cov=./ --cov-report=xml
3841
- name: Upload coverage to Codecov

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ipython
1414
kfp==1.8.22
1515
mlflow-skinny
1616
moto==4.1.6
17+
# kfp==1.8.22 needs protobuf < 4
18+
protobuf==3.20.3
1719
pyre-extensions
1820
pyre-check
1921
pytest

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ importlib-metadata
44
pyyaml
55
docker
66
filelock
7-
fsspec
7+
# more recent versions of fsspec causes torchx/workspace/test/dir_workspace_test#test_torchcxignore to fail
8+
fsspec==2023.1.0
89
# To resolve confliciting dependencies for urllib3: https://github.com/pytorch/torchx/actions/runs/3484190429/jobs/5828784263#step:4:552
910
urllib3<1.27,>=1.21.1
1011
tabulate

torchx/specs/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def copy(original: "Resource", **capabilities: Any) -> "Resource":
104104
# sentinel value used for cases when resource does not matter (e.g. ignored)
105105
NULL_RESOURCE: Resource = Resource(cpu=-1, gpu=-1, memMB=-1)
106106

107+
108+
# no-arg static factory method to use with default_factory in @dataclass
109+
# needed to support python 3.11 since mutable defaults for dataclasses are not allowed in 3.11
110+
def _null_resource() -> Resource:
111+
return NULL_RESOURCE
112+
113+
107114
# used as "*" scheduler backend
108115
ALL: str = "all"
109116

@@ -333,7 +340,7 @@ class Role:
333340
num_replicas: int = 1
334341
max_retries: int = 0
335342
retry_policy: RetryPolicy = RetryPolicy.APPLICATION
336-
resource: Resource = NULL_RESOURCE
343+
resource: Resource = field(default_factory=_null_resource)
337344
port_map: Dict[str, int] = field(default_factory=dict)
338345
metadata: Dict[str, Any] = field(default_factory=dict)
339346
mounts: List[Union[BindMount, VolumeMount, DeviceMount]] = field(

torchx/tracker/test/mlflow_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Config:
4444
locales: List[str] = field(default_factory=lambda: ["us", "eu", "fr"])
4545
empty_list: List[str] = field(default_factory=list)
4646
empty_map: Dict[str, str] = field(default_factory=dict)
47-
model_config: ModelConfig = ModelConfig()
47+
model_config: ModelConfig = field(default_factory=ModelConfig)
4848
datasets: List[DatasetConfig] = field(
4949
default_factory=lambda: [
5050
DatasetConfig(url="s3://dataset1"),

0 commit comments

Comments
 (0)