Skip to content

Commit

Permalink
Remove legacy run configuration fields (#725)
Browse files Browse the repository at this point in the history
* Remove legacy run configuration fields

* Document profiles

* Generate Union types in reference

* Fix tests
  • Loading branch information
r4victor authored Oct 17, 2023
1 parent c3e47d5 commit 6e060df
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ nav:
- dev-environment: docs/reference/dstack.yml/dev-environment.md
- task: docs/reference/dstack.yml/task.md
- service: docs/reference/dstack.yml/service.md
- "server/config.yml": docs/reference/server/config.yml.md
- profiles.yml: docs/reference/profiles.yml.md
- "server/config.yml": docs/reference/server/config.yml.md
# - Backends:
# - AWS: docs/reference/backends/aws.md
# - GCP: docs/reference/backends/gcp.md
Expand Down
14 changes: 8 additions & 6 deletions scripts/docs/gen_schema_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import re
from fnmatch import fnmatch
from typing import Any, Dict, Type, Union
from typing import Any, Dict, Optional, Type, Union

import mkdocs_gen_files
import yaml
Expand All @@ -20,11 +20,13 @@ def get_type(annotation: Type) -> str:
if get_origin(annotation) is Annotated:
return get_type(get_args(annotation)[0])
if get_origin(annotation) is Union:
args = get_args(annotation)
if type(None) in args:
args = [arg for arg in args if arg is not type(None)]
return f"Optional[{get_type(args[-1])}]"
return get_type(args[-1])
# Optional is Union with None.
# We don't want to show Optional[A, None] but just Optional[A]
if annotation.__name__ == "Optional":
args = ",".join(get_type(arg) for arg in get_args(annotation)[:-1])
else:
args = ",".join(get_type(arg) for arg in get_args(annotation))
return f"{annotation.__name__}[{args}]"
if get_origin(annotation) is Literal:
return str(annotation).split(".", maxsplit=1)[-1]
if get_origin(annotation) is list:
Expand Down
8 changes: 0 additions & 8 deletions src/dstack/_internal/core/models/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,7 @@ class BaseConfiguration(ForbidExtra):
Union[List[constr(regex=r"^[a-zA-Z_][a-zA-Z0-9_]*=.*$")], Dict[str, str]],
Field(description="The mapping or the list of environment variables"),
] = {}
# deprecated
build: Annotated[
CommandsList, Field(description="The bash commands to run during build stage")
] = []
setup: Annotated[CommandsList, Field(description="The bash commands to run on the boot")] = []
# not supported yet
cache: Annotated[
List[str], Field(description="The directories to be cached between configuration runs")
] = []

@validator("python", pre=True, always=True)
def convert_python(cls, v, values) -> Optional[PythonVersion]:
Expand Down
40 changes: 31 additions & 9 deletions src/dstack/_internal/core/models/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ def parse_max_duration(v: Union[int, str]) -> int:


class ProfileGPU(ForbidExtra):
name: Optional[str]
count: int = 1
name: Annotated[
Optional[str],
Field(description='The name of the GPU (e.g., "A100" or "H100")'),
]
count: Annotated[
int,
Field(description="The minimum number of GPUs"),
] = 1
memory: Annotated[
Optional[Union[int, str]],
Field(description='The minimum size of GPU memory (e.g., "16GB")'),
Expand All @@ -82,18 +88,21 @@ def _validate_name(cls, name: Optional[str]) -> Optional[str]:


class ProfileResources(ForbidExtra):
gpu: Optional[Union[int, ProfileGPU]]
cpu: Annotated[int, Field(description="The minimum number of CPUs")] = DEFAULT_CPU
memory: Annotated[
Union[int, str], Field(description='The minimum size of RAM memory (e.g., "16GB")')
] = parse_memory(DEFAULT_MEM)
gpu: Annotated[
Optional[Union[int, ProfileGPU]],
Field(description="The minimum number of GPUs or a GPU spec"),
]
shm_size: Annotated[
Optional[Union[int, str]],
Field(
description='The size of shared memory (e.g., "8GB"). If you are using parallel communicating processes ('
"e.g., dataloaders in PyTorch), you may need to configure this."
),
]
cpu: int = DEFAULT_CPU
_validate_mem = validator("memory", "shm_size", pre=True, allow_reuse=True)(parse_memory)

@validator("gpu", pre=True)
Expand Down Expand Up @@ -123,9 +132,20 @@ def _validate_fields(cls, field_values):


class Profile(ForbidExtra):
name: str
backends: Optional[List[BackendType]]
resources: ProfileResources = ProfileResources()
name: Annotated[
str,
Field(
description="The name of the profile that can be passed as `--profile` to `dstack run`"
),
]
backends: Annotated[
Optional[List[BackendType]],
Field(description='The backends to consider for provisionig (e.g., "[aws, gcp]")'),
]
resources: Annotated[
ProfileResources,
Field(description="The minimum resources of the instance to be provisioned"),
] = ProfileResources()
spot_policy: Annotated[
Optional[SpotPolicy],
Field(
Expand All @@ -138,13 +158,15 @@ class Profile(ForbidExtra):
max_duration: Annotated[
Optional[Union[Literal["off"], str, int]],
Field(
description="The maximum duration of a run (e.g., 2h, 1d, etc). After it elapses, the run is forced to stop"
description="The maximum duration of a run (e.g., 2h, 1d, etc). After it elapses, the run is forced to stop."
),
]
max_price: Annotated[
Optional[confloat(gt=0.0)], Field(description="The maximum price per hour, in dollars")
]
default: bool = False
default: Annotated[
bool, Field(description="If set to true, `dstack run` will use this profile by default.")
] = False

_validate_max_duration = validator("max_duration", pre=True, allow_reuse=True)(
parse_max_duration
Expand Down
4 changes: 0 additions & 4 deletions src/tests/_internal/server/routers/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def get_dev_env_run_plan_dict(
"user": username,
"run_spec": {
"configuration": {
"build": [],
"cache": [],
"entrypoint": None,
"env": {},
"home_dir": "/root",
Expand Down Expand Up @@ -140,8 +138,6 @@ def get_dev_env_run_dict(
"status": "submitted",
"run_spec": {
"configuration": {
"build": [],
"cache": [],
"entrypoint": None,
"env": {},
"home_dir": "/root",
Expand Down

0 comments on commit 6e060df

Please sign in to comment.