Skip to content

Commit

Permalink
[torchx/specs] Use default_factory for the default value of Role.reso…
Browse files Browse the repository at this point in the history
…urce and mlflow_test.Config.model_config to support python 3.11 clients (#768)
  • Loading branch information
kiukchung committed Sep 20, 2023
1 parent 12856f7 commit a45c4ca
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/python-unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
unittest:
strategy:
matrix:
python-version: [3.8, 3.9, '3.10']
python-version: [3.8, 3.9, "3.10", 3.11]
platform: ["linux.20_04.4x"]
include:
- python-version: 3.9
Expand All @@ -32,7 +32,10 @@ jobs:
run: |
set -eux
pip install pytest pytest-cov
pip install -e .[dev]
# use legacy resolver for python 3.11, otherwise pip will timeout trying to resolve deps
# TODO(kiukchung) long term we should narrowly scope dependency versions
# see: https://pip.pypa.io/en/latest/topics/dependency-resolution/
pip install --use-deprecated=legacy-resolver -e .[dev]
- name: Run tests
run: pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ipython
kfp==1.8.22
mlflow-skinny
moto==4.1.6
# kfp==1.8.22 needs protobuf < 4
protobuf==3.20.3
pyre-extensions
pyre-check
pytest
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ importlib-metadata
pyyaml
docker
filelock
fsspec
# more recent versions of fsspec causes torchx/workspace/test/dir_workspace_test#test_torchcxignore to fail
fsspec==2023.1.0
# To resolve confliciting dependencies for urllib3: https://github.com/pytorch/torchx/actions/runs/3484190429/jobs/5828784263#step:4:552
urllib3<1.27,>=1.21.1
tabulate
9 changes: 8 additions & 1 deletion torchx/specs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def copy(original: "Resource", **capabilities: Any) -> "Resource":
# sentinel value used for cases when resource does not matter (e.g. ignored)
NULL_RESOURCE: Resource = Resource(cpu=-1, gpu=-1, memMB=-1)


# no-arg static factory method to use with default_factory in @dataclass
# needed to support python 3.11 since mutable defaults for dataclasses are not allowed in 3.11
def _null_resource() -> Resource:
return NULL_RESOURCE


# used as "*" scheduler backend
ALL: str = "all"

Expand Down Expand Up @@ -333,7 +340,7 @@ class Role:
num_replicas: int = 1
max_retries: int = 0
retry_policy: RetryPolicy = RetryPolicy.APPLICATION
resource: Resource = NULL_RESOURCE
resource: Resource = field(default_factory=_null_resource)
port_map: Dict[str, int] = field(default_factory=dict)
metadata: Dict[str, Any] = field(default_factory=dict)
mounts: List[Union[BindMount, VolumeMount, DeviceMount]] = field(
Expand Down
2 changes: 1 addition & 1 deletion torchx/tracker/test/mlflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Config:
locales: List[str] = field(default_factory=lambda: ["us", "eu", "fr"])
empty_list: List[str] = field(default_factory=list)
empty_map: Dict[str, str] = field(default_factory=dict)
model_config: ModelConfig = ModelConfig()
model_config: ModelConfig = field(default_factory=ModelConfig)
datasets: List[DatasetConfig] = field(
default_factory=lambda: [
DatasetConfig(url="s3://dataset1"),
Expand Down

0 comments on commit a45c4ca

Please sign in to comment.