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
  • Loading branch information
kiukchung committed Sep 15, 2023
1 parent 1f5eac8 commit 9b9a22b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .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 Down
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 9b9a22b

Please sign in to comment.