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 to support python 3.11 clients
  • Loading branch information
kiukchung committed Sep 15, 2023
1 parent 1f5eac8 commit 20fe684
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion torchx/specs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ 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 +338,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

0 comments on commit 20fe684

Please sign in to comment.