Skip to content

Commit

Permalink
add resources override
Browse files Browse the repository at this point in the history
  • Loading branch information
cblmemo committed Jan 12, 2024
1 parent d5b779b commit 009de08
Showing 1 changed file with 81 additions and 3 deletions.
84 changes: 81 additions & 3 deletions sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4220,6 +4220,36 @@ def serve():
type=str,
nargs=-1,
**_get_shell_complete_args(_complete_file_name))
# Task options.
@_add_click_options(_TASK_OPTIONS + _EXTRA_RESOURCES_OPTIONS)
@click.option('--cpus',
default=None,
type=str,
required=False,
help=('Number of vCPUs each instance must have (e.g., '
'``--cpus=4`` (exactly 4) or ``--cpus=4+`` (at least 4)). '
'This is used to automatically select the instance type.'))
@click.option(
'--memory',
default=None,
type=str,
required=False,
help=('Amount of memory each instance must have in GB (e.g., '
'``--memory=16`` (exactly 16GB), ``--memory=16+`` (at least 16GB))'))
@click.option('--disk-size',
default=None,
type=int,
required=False,
help=('OS disk size in GBs.'))
@click.option(
'--disk-tier',
default=None,
type=click.Choice(['low', 'medium', 'high'], case_sensitive=False),
required=False,
help=(
'OS disk tier. Could be one of "low", "medium", "high". Default: medium'
))
# Service options.
@click.option('--service-name',
'-n',
default=None,
Expand All @@ -4232,10 +4262,28 @@ def serve():
default=False,
required=False,
help='Skip confirmation prompt.')
# TODO(tian): Support the task_option overrides for the service.
@timeline.event
@usage_lib.entrypoint
def serve_up(
service_yaml: List[str],
service_name: Optional[str],
name: Optional[str],
workdir: Optional[str],
cloud: Optional[str],
region: Optional[str],
zone: Optional[str],
num_nodes: Optional[int],
use_spot: Optional[bool],
image_id: Optional[str],
env_file: Optional[Dict[str, str]],
env: List[Tuple[str, str]],
gpus: Optional[str],
instance_type: Optional[str],
ports: Tuple[str],
cpus: Optional[str],
memory: Optional[str],
disk_size: Optional[int],
disk_tier: Optional[str],
yes: bool,
):
"""Launch a SkyServe service.
Expand Down Expand Up @@ -4267,14 +4315,44 @@ def serve_up(
sky serve up service.yaml
"""
if service_name is None:
service_name = serve_lib.generate_service_name()
if name is None:
name = service_name = serve_lib.generate_service_name()
else:
service_name = name
else:
if name is None:
name = service_name
else:
raise click.UsageError(
'Cannot specify both --name and --service-name. '
'Both of them are used to specify the name of the service. '
f'Got: {name!r} and {service_name!r}.')

is_yaml, _ = _check_yaml(''.join(service_yaml))
if not is_yaml:
raise click.UsageError('SERVICE_YAML must be a valid YAML file.')
env = _merge_env_vars(env_file, env)
# We keep nargs=-1 in service_yaml argument to reuse this function.
task = _make_task_or_dag_from_entrypoint_with_overrides(
service_yaml, entrypoint_name='Service')
service_yaml,
name=name,
workdir=workdir,
cloud=cloud,
region=region,
zone=zone,
gpus=gpus,
cpus=cpus,
memory=memory,
instance_type=instance_type,
num_nodes=num_nodes,
use_spot=use_spot,
image_id=image_id,
env=env,
disk_size=disk_size,
disk_tier=disk_tier,
ports=ports,
entrypoint_name='Service',
)
if isinstance(task, sky.Dag):
raise click.UsageError(
_DAG_NOT_SUPPORTED_MESSAGE.format(command='sky serve up'))
Expand Down

0 comments on commit 009de08

Please sign in to comment.