Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
feat: Add func/cli args to specify session dependencies (#214)
Browse files Browse the repository at this point in the history
* feat: Add dependencies arg to functional APIs
* feat: Update the target API version to match with manager
  (lablup/backend.ai-manager#528)
* feat: Add cli options to specify session dependencies (`--depends`)
  • Loading branch information
achimnol committed Mar 21, 2022
1 parent 99cae84 commit 17f604d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/214.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `--depends` CLI option to the `start` & `session create` commands and the corresponding functional API arguments
10 changes: 10 additions & 0 deletions src/ai/backend/client/cli/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def _create_cmd(docs: str = None):
help='The maximum duration to wait until the session starts.')
@click.option('--no-reuse', is_flag=True,
help='Do not reuse existing sessions but return an error.')
@click.option('--depends', metavar='SESSION_ID', type=str, multiple=True,
help="Set the list of session ID or names that the newly created session depends on. "
"The session will get scheduled after all of them successfully finish.")
# execution environment
@click.option('-e', '--env', metavar='KEY=VAL', type=str, multiple=True,
help='Environment variable (may appear multiple times)')
Expand Down Expand Up @@ -112,6 +115,7 @@ def create(
enqueue_only: bool,
max_wait: bool,
no_reuse: bool,
depends: Sequence[str],
# execution environment
env: Sequence[str],
# extra options
Expand Down Expand Up @@ -164,6 +168,7 @@ def create(
enqueue_only=enqueue_only,
max_wait=max_wait,
no_reuse=no_reuse,
dependencies=depends,
cluster_size=cluster_size,
cluster_mode=cluster_mode,
mounts=mount,
Expand Down Expand Up @@ -250,6 +255,9 @@ def _create_from_template_cmd(docs: str = None):
help='The maximum duration to wait until the session starts.')
@click.option('--no-reuse', is_flag=True,
help='Do not reuse existing sessions but return an error.')
@click.option('--depends', metavar='SESSION_ID', type=str, multiple=True,
help="Set the list of session ID or names that the newly created session depends on. "
"The session will get scheduled after all of them successfully finish.")
# execution environment
@click.option('-e', '--env', metavar='KEY=VAL', type=str, multiple=True,
help='Environment variable (may appear multiple times)')
Expand Down Expand Up @@ -306,6 +314,7 @@ def create_from_template(
enqueue_only: bool,
max_wait: int | Undefined,
no_reuse: bool,
depends: Sequence[str],
# execution environment
env: Sequence[str],
# extra options
Expand Down Expand Up @@ -360,6 +369,7 @@ def create_from_template(
enqueue_only=enqueue_only,
max_wait=max_wait,
no_reuse=no_reuse,
dependencies=depends,
cluster_size=cluster_size,
mounts=prepared_mount,
mount_map=prepared_mount_map,
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Undefined(enum.Enum):
_config = None
_undefined = Undefined.token

API_VERSION = (6, '20210815')
API_VERSION = (6, '20220315')
MIN_API_VERSION = (5, '20191215')

DEFAULT_CHUNK_SIZE = 16 * (2**20) # 16 MiB
Expand Down
4 changes: 4 additions & 0 deletions src/ai/backend/client/func/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async def get_or_create(
enqueue_only: bool = False,
max_wait: int = 0,
no_reuse: bool = False,
dependencies: Sequence[str] = None,
mounts: List[str] = None,
mount_map: Mapping[str, str] = None,
envs: Mapping[str, str] = None,
Expand Down Expand Up @@ -272,6 +273,8 @@ async def get_or_create(
'scalingGroup': scaling_group,
},
}
if api_session.get().api_version >= (6, '20220315'):
params['dependencies'] = dependencies
if api_session.get().api_version >= (6, '20200815'):
params['clusterSize'] = cluster_size
params['clusterMode'] = cluster_mode
Expand Down Expand Up @@ -329,6 +332,7 @@ async def create_from_template(
starts_at: str = None,
enqueue_only: Union[bool, Undefined] = undefined,
max_wait: Union[int, Undefined] = undefined,
dependencies: Sequence[str] = None, # cannot be stored in templates
no_reuse: Union[bool, Undefined] = undefined,
image: Union[str, Undefined] = undefined,
mounts: Union[List[str], Undefined] = undefined,
Expand Down

0 comments on commit 17f604d

Please sign in to comment.