Skip to content

Commit 5efca70

Browse files
authored
Use numeric replica-group names (#3502)
Co-authored-by: Bihan Rana
1 parent b4b69fb commit 5efca70

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/dstack/_internal/core/models/configurations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from dstack._internal.core.models.services import AnyModel, OpenAIChatModel
3232
from dstack._internal.core.models.unix import UnixUser
3333
from dstack._internal.core.models.volumes import MountPoint, VolumeConfiguration, parse_mount_point
34-
from dstack._internal.core.services import is_valid_dstack_resource_name
34+
from dstack._internal.core.services import is_valid_replica_group_name
3535
from dstack._internal.utils.common import has_duplicates, list_enum_values_for_annotation
3636
from dstack._internal.utils.json_schema import add_extra_schema_types
3737
from dstack._internal.utils.json_utils import (
@@ -55,7 +55,7 @@
5555
DEFAULT_PROBE_READY_AFTER = 1
5656
DEFAULT_PROBE_METHOD = "get"
5757
MAX_PROBE_URL_LEN = 2048
58-
DEFAULT_REPLICA_GROUP_NAME = "default"
58+
DEFAULT_REPLICA_GROUP_NAME = "0"
5959

6060

6161
class RunConfigurationType(str, Enum):
@@ -756,7 +756,7 @@ class ReplicaGroup(CoreModel):
756756
name: Annotated[
757757
Optional[str],
758758
Field(
759-
description="The name of the replica group. If not provided, defaults to 'replica-group-0', 'replica-group-1', etc. based on position."
759+
description="The name of the replica group. If not provided, defaults to '0', '1', etc. based on position."
760760
),
761761
]
762762
count: Annotated[
@@ -784,8 +784,8 @@ class ReplicaGroup(CoreModel):
784784
@validator("name")
785785
def validate_name(cls, v: Optional[str]) -> Optional[str]:
786786
if v is not None:
787-
if not is_valid_dstack_resource_name(v):
788-
raise ValueError("Resource name should match regex '^[a-z][a-z0-9-]{1,40}$'")
787+
if not is_valid_replica_group_name(v):
788+
raise ValueError("Resource name should match regex '^[a-z0-9][a-z0-9-]{0,39}$'")
789789
return v
790790

791791
@validator("count")
@@ -920,7 +920,7 @@ def validate_replicas(
920920
# Assign default names to groups without names
921921
for index, group in enumerate(v):
922922
if group.name is None:
923-
group.name = f"replica-group-{index}"
923+
group.name = str(index)
924924

925925
# Check for duplicate names
926926
names = [group.name for group in v]

src/dstack/_internal/core/services/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ def validate_dstack_resource_name(resource_name: str):
1010

1111
def is_valid_dstack_resource_name(resource_name: str) -> bool:
1212
return re.match("^[a-z][a-z0-9-]{1,40}$", resource_name) is not None
13+
14+
15+
def is_valid_replica_group_name(name: str) -> bool:
16+
return re.match("^[a-z0-9][a-z0-9-]{0,39}$", name) is not None

src/tests/_internal/server/routers/test_runs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def get_dev_env_run_plan_dict(
257257
"replica_num": 0,
258258
"job_num": 0,
259259
"jobs_per_replica": 1,
260-
"replica_group": "default",
260+
"replica_group": "0",
261261
"single_branch": False,
262262
"max_duration": None,
263263
"stop_duration": 300,
@@ -494,7 +494,7 @@ def get_dev_env_run_dict(
494494
"replica_num": 0,
495495
"job_num": 0,
496496
"jobs_per_replica": 1,
497-
"replica_group": "default",
497+
"replica_group": "0",
498498
"single_branch": False,
499499
"max_duration": None,
500500
"stop_duration": 300,

0 commit comments

Comments
 (0)