llm-lab-runtime 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. llm_lab_runtime-0.2.0/PKG-INFO +20 -0
  2. llm_lab_runtime-0.2.0/pyproject.toml +147 -0
  3. llm_lab_runtime-0.2.0/pyproject.toml.orig +147 -0
  4. llm_lab_runtime-0.2.0/src/llm_lab/__init__.py +0 -0
  5. llm_lab_runtime-0.2.0/src/llm_lab/cli/__init__.py +12 -0
  6. llm_lab_runtime-0.2.0/src/llm_lab/cli/db/__init__.py +37 -0
  7. llm_lab_runtime-0.2.0/src/llm_lab/cli/db/deps.py +17 -0
  8. llm_lab_runtime-0.2.0/src/llm_lab/cli/dependent_typer.py +83 -0
  9. llm_lab_runtime-0.2.0/src/llm_lab/cli/jobs/__init__.py +134 -0
  10. llm_lab_runtime-0.2.0/src/llm_lab/cli/jobs/deps.py +76 -0
  11. llm_lab_runtime-0.2.0/src/llm_lab/cli/secrets/__init__.py +42 -0
  12. llm_lab_runtime-0.2.0/src/llm_lab/cli/yaml_files.py +19 -0
  13. llm_lab_runtime-0.2.0/src/llm_lab/database.py +26 -0
  14. llm_lab_runtime-0.2.0/src/llm_lab/dependencies.py +140 -0
  15. llm_lab_runtime-0.2.0/src/llm_lab/errors.py +2 -0
  16. llm_lab_runtime-0.2.0/src/llm_lab/jobs/__init__.py +0 -0
  17. llm_lab_runtime-0.2.0/src/llm_lab/jobs/access.py +151 -0
  18. llm_lab_runtime-0.2.0/src/llm_lab/jobs/code.py +31 -0
  19. llm_lab_runtime-0.2.0/src/llm_lab/jobs/orchestrator.py +323 -0
  20. llm_lab_runtime-0.2.0/src/llm_lab/jobs/protocol.py +210 -0
  21. llm_lab_runtime-0.2.0/src/llm_lab/jobs/tables.py +26 -0
  22. llm_lab_runtime-0.2.0/src/llm_lab/jobs/vast.py +344 -0
  23. llm_lab_runtime-0.2.0/src/llm_lab/keyring_settings.py +50 -0
  24. llm_lab_runtime-0.2.0/src/llm_lab/migrations/__init__.py +0 -0
  25. llm_lab_runtime-0.2.0/src/llm_lab/migrations/env.py +13 -0
  26. llm_lab_runtime-0.2.0/src/llm_lab/migrations/script.py.mako +17 -0
  27. llm_lab_runtime-0.2.0/src/llm_lab/migrations/versions/9395d98d9cb4_create_job_transitions.py +31 -0
  28. llm_lab_runtime-0.2.0/src/llm_lab/migrations/versions/__init__.py +0 -0
  29. llm_lab_runtime-0.2.0/src/llm_lab/py.typed +0 -0
  30. llm_lab_runtime-0.2.0/src/llm_lab/runtime/__init__.py +0 -0
  31. llm_lab_runtime-0.2.0/src/llm_lab/runtime/chat.py +164 -0
  32. llm_lab_runtime-0.2.0/src/llm_lab/runtime/deps.py +26 -0
  33. llm_lab_runtime-0.2.0/src/llm_lab/runtime/serving.py +48 -0
  34. llm_lab_runtime-0.2.0/src/llm_lab/runtime/settings.py +43 -0
  35. llm_lab_runtime-0.2.0/src/llm_lab/secrets.py +29 -0
  36. llm_lab_runtime-0.2.0/src/llm_lab/settings.py +141 -0
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: llm-lab-runtime
3
+ Version: 0.2.0
4
+ Summary: Run jobs on rented Vast.ai instances and manage their lifecycle.
5
+ Requires-Dist: alembic>=1.20.1
6
+ Requires-Dist: cryptography>=50.0.2
7
+ Requires-Dist: httpx>=0.28.1
8
+ Requires-Dist: keyring>=25.7.0
9
+ Requires-Dist: pycountry>=26.2.16
10
+ Requires-Dist: pydantic>=2.14.4
11
+ Requires-Dist: pydantic-extra-types>=2.11.1
12
+ Requires-Dist: pydantic-settings>=2.16.3
13
+ Requires-Dist: pyyaml>=6.0.4
14
+ Requires-Dist: questionary>=2.1.1
15
+ Requires-Dist: sqlalchemy>=2.1.9
16
+ Requires-Dist: typer>=0.29.2
17
+ Requires-Dist: openai>=3.60.0 ; extra == 'runtime'
18
+ Requires-Dist: pregel-redux>=0.6.0 ; extra == 'runtime'
19
+ Requires-Python: >=3.12
20
+ Provides-Extra: runtime
@@ -0,0 +1,147 @@
1
+ [project]
2
+ name = "llm-lab-runtime"
3
+ version = "0.2.0"
4
+ description = "Run jobs on rented Vast.ai instances and manage their lifecycle."
5
+ requires-python = ">=3.12"
6
+ dependencies = [
7
+ "alembic>=1.20.1",
8
+ "cryptography>=50.0.2",
9
+ "httpx>=0.28.1",
10
+ "keyring>=25.7.0",
11
+ "pycountry>=26.2.16",
12
+ "pydantic>=2.14.4",
13
+ "pydantic-extra-types>=2.11.1",
14
+ "pydantic-settings>=2.16.3",
15
+ "pyyaml>=6.0.4",
16
+ "questionary>=2.1.1",
17
+ "sqlalchemy>=2.1.9",
18
+ "typer>=0.29.2",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ runtime = [
23
+ "openai>=3.60.0",
24
+ "pregel-redux>=0.6.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ llm-lab = "llm_lab.cli:app"
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.13.9,<0.14.0"]
32
+ build-backend = "uv_build"
33
+
34
+ [tool.uv.build-backend]
35
+ module-name = "llm_lab"
36
+
37
+ [tool.uv.sources.llm-lab-runtime]
38
+ workspace = true
39
+
40
+ [tool.pytest]
41
+ minversion = "9.1"
42
+ strict = true
43
+ testpaths = ["tests"]
44
+ addopts = ["-ra"]
45
+ filterwarnings = ["error"]
46
+
47
+ [tool.basedpyright]
48
+ pythonVersion = "3.12"
49
+ typeCheckingMode = "recommended"
50
+ enableTypeIgnoreComments = false
51
+ reportAny = "hint"
52
+ reportConstantRedefinition = "none"
53
+ reportImplicitOverride = "none"
54
+ reportImplicitStringConcatenation = "none"
55
+ reportInvalidCast = "none"
56
+ reportMissingModuleSource = "none"
57
+ reportMissingSuperCall = "none"
58
+ reportMissingTypeStubs = "hint"
59
+ reportUnannotatedClassAttribute = "none"
60
+ reportUnknownLambdaType = "none"
61
+ reportUnknownMemberType = "information"
62
+ reportUnnecessaryComparison = "hint"
63
+ reportUnsafeMultipleInheritance = "none"
64
+ reportUnusedCallResult = "none"
65
+ reportUnusedImport = "none"
66
+ reportUnusedParameter = "none"
67
+
68
+ [tool.ruff]
69
+ line-length = 120
70
+ src = ["src"]
71
+ target-version = "py312"
72
+
73
+ [tool.ruff.lint]
74
+ select = [
75
+ "A",
76
+ "ANN001",
77
+ "ANN201",
78
+ "ANN205",
79
+ "ANN206",
80
+ "ASYNC",
81
+ "B",
82
+ "BLE",
83
+ "C4",
84
+ "DTZ",
85
+ "ERA",
86
+ "F",
87
+ "FA",
88
+ "FAST",
89
+ "FBT",
90
+ "FLY",
91
+ "FURB",
92
+ "I",
93
+ "INP",
94
+ "N",
95
+ "NPY",
96
+ "PD",
97
+ "PERF",
98
+ "PIE",
99
+ "PLC0105",
100
+ "PLC0131",
101
+ "PLC0132",
102
+ "PLC0207",
103
+ "PLC0208",
104
+ "PLE",
105
+ "PLR",
106
+ "PLW",
107
+ "PYI",
108
+ "RET",
109
+ "RUF",
110
+ "SIM",
111
+ "TRY",
112
+ "UP",
113
+ "YTT",
114
+ ]
115
+ ignore = [
116
+ "A002",
117
+ "ASYNC119",
118
+ "N818",
119
+ "PLR0904",
120
+ "PLR0911",
121
+ "PLR0912",
122
+ "PLR0913",
123
+ "PLR0915",
124
+ "PLR0917",
125
+ "PLR2004",
126
+ "PLW0603",
127
+ "RET504",
128
+ "RUF001",
129
+ "RUF077",
130
+ "RUF105",
131
+ "RUF106",
132
+ "RUF201",
133
+ "TRY003",
134
+ "UP048",
135
+ "UP051",
136
+ "UP052",
137
+ ]
138
+
139
+ [dependency-groups]
140
+ dev = [
141
+ "llm-lab-runtime[runtime]",
142
+ "ast-grep-cli>=0.51.2",
143
+ "basedpyright>=1.40.2",
144
+ "pytest>=9.1.1,<9.2",
145
+ "ruff>=0.17.6",
146
+ "types-pyyaml>=6.0.12.20261122",
147
+ ]
@@ -0,0 +1,147 @@
1
+ [project]
2
+ name = "llm-lab-runtime"
3
+ version = "0.2.0"
4
+ description = "Run jobs on rented Vast.ai instances and manage their lifecycle."
5
+ requires-python = ">=3.12"
6
+ dependencies = [
7
+ "alembic>=1.20.1",
8
+ "cryptography>=50.0.2",
9
+ "httpx>=0.28.1",
10
+ "keyring>=25.7.0",
11
+ "pycountry>=26.2.16",
12
+ "pydantic>=2.14.4",
13
+ "pydantic-extra-types>=2.11.1",
14
+ "pydantic-settings>=2.16.3",
15
+ "pyyaml>=6.0.4",
16
+ "questionary>=2.1.1",
17
+ "sqlalchemy>=2.1.9",
18
+ "typer>=0.29.2",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ runtime = [
23
+ "openai>=3.60.0",
24
+ "pregel-redux>=0.6.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ llm-lab = "llm_lab.cli:app"
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.13.9,<0.14.0"]
32
+ build-backend = "uv_build"
33
+
34
+ [tool.uv.build-backend]
35
+ module-name = "llm_lab"
36
+
37
+ [tool.uv.sources]
38
+ llm-lab-runtime = { workspace = true }
39
+
40
+ [dependency-groups]
41
+ dev = [
42
+ "llm-lab-runtime[runtime]",
43
+ "ast-grep-cli>=0.51.2",
44
+ "basedpyright>=1.40.2",
45
+ "pytest>=9.1.1,<9.2",
46
+ "ruff>=0.17.6",
47
+ "types-pyyaml>=6.0.12.20261122",
48
+ ]
49
+
50
+ [tool.pytest]
51
+ minversion = "9.1"
52
+ strict = true
53
+ testpaths = ["tests"]
54
+ addopts = ["-ra"]
55
+ filterwarnings = ["error"]
56
+
57
+ [tool.basedpyright]
58
+ pythonVersion = "3.12"
59
+ typeCheckingMode = "recommended"
60
+ enableTypeIgnoreComments = false
61
+ reportAny = "hint"
62
+ reportConstantRedefinition = "none"
63
+ reportImplicitOverride = "none"
64
+ reportImplicitStringConcatenation = "none"
65
+ reportInvalidCast = "none"
66
+ reportMissingModuleSource = "none"
67
+ reportMissingSuperCall = "none"
68
+ reportMissingTypeStubs = "hint"
69
+ reportUnannotatedClassAttribute = "none"
70
+ reportUnknownLambdaType = "none"
71
+ reportUnknownMemberType = "information"
72
+ reportUnnecessaryComparison = "hint"
73
+ reportUnsafeMultipleInheritance = "none"
74
+ reportUnusedCallResult = "none"
75
+ reportUnusedImport = "none"
76
+ reportUnusedParameter = "none"
77
+
78
+ [tool.ruff]
79
+ line-length = 120
80
+ src = ["src"]
81
+ target-version = "py312"
82
+
83
+ [tool.ruff.lint]
84
+ select = [
85
+ "A",
86
+ "ANN001",
87
+ "ANN201",
88
+ "ANN205",
89
+ "ANN206",
90
+ "ASYNC",
91
+ "B",
92
+ "BLE",
93
+ "C4",
94
+ "DTZ",
95
+ "ERA",
96
+ "F",
97
+ "FA",
98
+ "FAST",
99
+ "FBT",
100
+ "FLY",
101
+ "FURB",
102
+ "I",
103
+ "INP",
104
+ "N",
105
+ "NPY",
106
+ "PD",
107
+ "PERF",
108
+ "PIE",
109
+ "PLC0105",
110
+ "PLC0131",
111
+ "PLC0132",
112
+ "PLC0207",
113
+ "PLC0208",
114
+ "PLE",
115
+ "PLR",
116
+ "PLW",
117
+ "PYI",
118
+ "RET",
119
+ "RUF",
120
+ "SIM",
121
+ "TRY",
122
+ "UP",
123
+ "YTT",
124
+ ]
125
+ ignore = [
126
+ "A002",
127
+ "ASYNC119",
128
+ "N818",
129
+ "PLR0904",
130
+ "PLR0911",
131
+ "PLR0912",
132
+ "PLR0913",
133
+ "PLR0915",
134
+ "PLR0917",
135
+ "PLR2004",
136
+ "PLW0603",
137
+ "RET504",
138
+ "RUF001",
139
+ "RUF077",
140
+ "RUF105",
141
+ "RUF106",
142
+ "RUF201",
143
+ "TRY003",
144
+ "UP048",
145
+ "UP051",
146
+ "UP052",
147
+ ]
File without changes
@@ -0,0 +1,12 @@
1
+ from llm_lab.cli import db, jobs, secrets
2
+ from llm_lab.cli.dependent_typer import DependentTyper
3
+
4
+ app = DependentTyper(name="llm-lab", no_args_is_help=True)
5
+ app.add_typer(db.app)
6
+ app.add_typer(jobs.app)
7
+ app.add_typer(secrets.app)
8
+
9
+
10
+ @app.callback()
11
+ def main() -> None:
12
+ pass
@@ -0,0 +1,37 @@
1
+ from typing import Annotated
2
+
3
+ import typer
4
+ from alembic import command
5
+
6
+ from llm_lab.cli.dependent_typer import DependentTyper
7
+ from llm_lab.database import build_migration_config, read_revision
8
+ from llm_lab.settings import SettingsDep
9
+
10
+ app = DependentTyper(name="db", no_args_is_help=True, help="Manage the job database.")
11
+
12
+
13
+ def prompt_for_revision_message() -> str:
14
+ return typer.prompt("Revision message", type=str)
15
+
16
+
17
+ @app.command("upgrade", help="Apply migrations.")
18
+ def upgrade_database(settings: SettingsDep) -> None:
19
+ engine = settings.database_engine
20
+ before = read_revision(engine)
21
+ command.upgrade(build_migration_config(engine), "head")
22
+ after = read_revision(engine)
23
+ typer.echo("Already current." if before == after else f"Migrated to {after}.")
24
+
25
+
26
+ @app.command("revision", help="Create a migration.")
27
+ def create_revision(
28
+ message: Annotated[
29
+ str,
30
+ typer.Argument(
31
+ help="Migration description.",
32
+ default_factory=prompt_for_revision_message,
33
+ ),
34
+ ],
35
+ settings: SettingsDep,
36
+ ) -> None:
37
+ command.revision(build_migration_config(settings.database_engine), message=message, autogenerate=True)
@@ -0,0 +1,17 @@
1
+ from collections.abc import Iterator
2
+ from typing import Annotated
3
+
4
+ from sqlalchemy.orm import Session
5
+
6
+ from llm_lab.database import require_current_schema
7
+ from llm_lab.dependencies import Depends
8
+ from llm_lab.settings import SettingsDep
9
+
10
+
11
+ def get_database_session(settings: SettingsDep) -> Iterator[Session]:
12
+ require_current_schema(settings.database_engine)
13
+ with Session(settings.database_engine) as session:
14
+ yield session
15
+
16
+
17
+ type DatabaseSessionDep = Annotated[Session, Depends(get_database_session)]
@@ -0,0 +1,83 @@
1
+ from collections.abc import Callable, Mapping
2
+ from copy import copy
3
+ from functools import update_wrapper
4
+ from typing import Self
5
+
6
+ import typer
7
+ from typer.core import TyperCommand
8
+
9
+ from llm_lab.dependencies import execute_plan, plan_call
10
+ from llm_lab.errors import CommandError
11
+
12
+
13
+ class DependentCommand:
14
+ function: Callable[..., object]
15
+
16
+ def __init__(
17
+ self, function: Callable[..., object], overrides: Mapping[Callable[..., object], Callable[..., object]]
18
+ ) -> None:
19
+ self.function = function
20
+ self.plan = plan_call(function, overrides)
21
+ self.__signature__ = self.plan.signature
22
+ update_wrapper(self, function)
23
+
24
+ def __call__(self, **arguments: object) -> object:
25
+ try:
26
+ return execute_plan(self.plan, arguments)
27
+ except CommandError as error:
28
+ typer.echo(f"Error: {error}", err=True)
29
+ raise typer.Exit(1) from error
30
+
31
+
32
+ class DependentTyper(typer.Typer):
33
+ def command[CommandT: Callable[..., object]](
34
+ self,
35
+ name: str | None = None,
36
+ *,
37
+ cls: type[TyperCommand] | None = None,
38
+ context_settings: dict[object, object] | None = None,
39
+ help: str | None = None,
40
+ epilog: str | None = None,
41
+ short_help: str | None = None,
42
+ options_metavar: str | None = None,
43
+ add_help_option: bool = True,
44
+ no_args_is_help: bool = False,
45
+ hidden: bool = False,
46
+ deprecated: bool = False,
47
+ rich_help_panel: str | None = None,
48
+ ) -> Callable[[CommandT], CommandT]:
49
+ register = super().command(
50
+ name,
51
+ cls=cls,
52
+ context_settings=context_settings,
53
+ help=help,
54
+ epilog=epilog,
55
+ short_help=short_help,
56
+ options_metavar=options_metavar,
57
+ add_help_option=add_help_option,
58
+ no_args_is_help=no_args_is_help,
59
+ hidden=hidden,
60
+ deprecated=deprecated,
61
+ rich_help_panel=rich_help_panel,
62
+ )
63
+
64
+ def decorator(function: CommandT) -> CommandT:
65
+ register(DependentCommand(function, {}))
66
+ return function
67
+
68
+ return decorator
69
+
70
+ def with_dependency_overrides(self, overrides: Mapping[Callable[..., object], Callable[..., object]]) -> Self:
71
+ overridden = copy(self)
72
+ overridden.registered_commands = [copy(info) for info in self.registered_commands]
73
+ for info in overridden.registered_commands:
74
+ if isinstance(info.callback, DependentCommand):
75
+ info.callback = DependentCommand(info.callback.function, overrides)
76
+ overridden.registered_groups = [copy(info) for info in self.registered_groups]
77
+ for info in overridden.registered_groups:
78
+ match info.typer_instance:
79
+ case DependentTyper() as group:
80
+ info.typer_instance = group.with_dependency_overrides(overrides)
81
+ case _:
82
+ pass
83
+ return overridden
@@ -0,0 +1,134 @@
1
+ import json
2
+ import os
3
+ from datetime import UTC
4
+ from pathlib import Path
5
+ from typing import Annotated, assert_never
6
+
7
+ import typer
8
+ import yaml
9
+ from pydantic.json_schema import GenerateJsonSchema
10
+ from sqlalchemy import select
11
+
12
+ from llm_lab.cli.db.deps import DatabaseSessionDep
13
+ from llm_lab.cli.dependent_typer import DependentTyper
14
+ from llm_lab.cli.jobs.deps import JobAccessStoreDep, JobOrchestratorDep
15
+ from llm_lab.cli.yaml_files import reading_yaml_file
16
+ from llm_lab.jobs.protocol import Aborted, Failed, JobRecord, JobSpec, Pending, Running, Succeeded
17
+ from llm_lab.jobs.tables import JobTransitionRow, select_latest_transitions
18
+
19
+ app = DependentTyper(name="jobs", no_args_is_help=True, help="Run jobs on Vast.ai.")
20
+
21
+
22
+ def prompt_for_manifest() -> Path:
23
+ return typer.prompt("Manifest file", type=Path)
24
+
25
+
26
+ def prompt_for_job_name() -> str:
27
+ return typer.prompt("Job name", type=str)
28
+
29
+
30
+ type ManifestArgument = Annotated[
31
+ Path,
32
+ typer.Argument(
33
+ exists=True,
34
+ dir_okay=False,
35
+ help="Job manifest file.",
36
+ default_factory=prompt_for_manifest,
37
+ ),
38
+ ]
39
+ type JobNameArgument = Annotated[
40
+ str,
41
+ typer.Argument(
42
+ help="Job name.",
43
+ default_factory=prompt_for_job_name,
44
+ ),
45
+ ]
46
+
47
+
48
+ def load_job_spec(manifest: Path) -> JobSpec:
49
+ with reading_yaml_file(manifest, "job manifest"):
50
+ spec = JobSpec.model_validate(yaml.safe_load(manifest.read_text()))
51
+ match spec.project:
52
+ case None:
53
+ return spec
54
+ case Path() as project:
55
+ return spec.model_copy(update={"project": manifest.parent / project})
56
+ case _:
57
+ assert_never(spec.project)
58
+
59
+
60
+ def report(record: JobRecord) -> None:
61
+ typer.echo(record.model_dump_json(indent=2))
62
+ match record.status:
63
+ case Pending() | Running() | Succeeded():
64
+ pass
65
+ case Failed() | Aborted():
66
+ raise typer.Exit(1)
67
+ case _:
68
+ assert_never(record.status)
69
+
70
+
71
+ @app.command("submit", help="Start a job.")
72
+ def submit_job(manifest: ManifestArgument, orchestrator: JobOrchestratorDep) -> None:
73
+ report(orchestrator.submit(load_job_spec(manifest)))
74
+
75
+
76
+ @app.command("schema", help="Print the JSON schema of job manifest files.")
77
+ def print_manifest_schema() -> None:
78
+ schema = {"$schema": GenerateJsonSchema.schema_dialect, **JobSpec.model_json_schema()}
79
+ typer.echo(json.dumps(schema, indent=2))
80
+
81
+
82
+ @app.command("status", help="Refresh and show a job.")
83
+ def show_job_status(name: JobNameArgument, orchestrator: JobOrchestratorDep) -> None:
84
+ report(orchestrator.sync(name))
85
+
86
+
87
+ @app.command("sync", help="Refresh all unfinished jobs.")
88
+ def sync_jobs(orchestrator: JobOrchestratorDep) -> None:
89
+ for record in orchestrator.sync_all():
90
+ typer.echo(f"{record.spec.name}\t{record.status.condition}")
91
+
92
+
93
+ @app.command("list", help="List jobs.")
94
+ def list_jobs(session: DatabaseSessionDep) -> None:
95
+ for row in session.scalars(select_latest_transitions()):
96
+ typer.echo(f"{row.name}\t{row.condition}")
97
+
98
+
99
+ @app.command("history", help="Show the state history of a job.")
100
+ def show_job_history(name: JobNameArgument, session: DatabaseSessionDep) -> None:
101
+ rows = session.scalars(
102
+ select(JobTransitionRow).where(JobTransitionRow.name == name).order_by(JobTransitionRow.sequence)
103
+ )
104
+ for row in rows:
105
+ status = JobRecord.model_validate_json(row.record).status
106
+ typer.echo(f"{row.recorded_at.replace(tzinfo=UTC).isoformat()}\t{status.model_dump_json()}")
107
+
108
+
109
+ type DownloadOption = Annotated[
110
+ bool,
111
+ typer.Option(
112
+ "--download/--no-download",
113
+ help="Download the artifacts directory of a running job before its instance is destroyed.",
114
+ ),
115
+ ]
116
+
117
+
118
+ @app.command("destroy", help="Destroy the instances of a job.")
119
+ def destroy_job(name: JobNameArgument, orchestrator: JobOrchestratorDep, *, download: DownloadOption = True) -> None:
120
+ abandonment = orchestrator.abandon(name, download=download)
121
+ match abandonment.downloaded_to:
122
+ case Path() as directory:
123
+ typer.echo(f"Downloaded the artifacts of job {name} to {directory}.", err=True)
124
+ case None:
125
+ pass
126
+ case _:
127
+ assert_never(abandonment.downloaded_to)
128
+ report(abandonment.record)
129
+
130
+
131
+ @app.command("ssh", help="Open a shell on the instance of a running job.")
132
+ def open_job_shell(name: JobNameArgument, orchestrator: JobOrchestratorDep, access: JobAccessStoreDep) -> None:
133
+ command = access.build_ssh_command(name, orchestrator.find_ssh_endpoint(name))
134
+ os.execvp(command[0], command)
@@ -0,0 +1,76 @@
1
+ import time
2
+ from collections.abc import Iterator
3
+ from datetime import UTC, datetime
4
+ from typing import Annotated
5
+
6
+ import httpx
7
+
8
+ from llm_lab.cli.db.deps import DatabaseSessionDep
9
+ from llm_lab.dependencies import Depends
10
+ from llm_lab.jobs.access import JobAccessStore, RsyncDownloader, RsyncUploader
11
+ from llm_lab.jobs.code import WheelBuilder
12
+ from llm_lab.jobs.orchestrator import ArtifactDownloader, CodeUploader, InstanceProvider, JobOrchestrator
13
+ from llm_lab.jobs.vast import VastInstanceProvider
14
+ from llm_lab.secrets import SettingsSecretSource
15
+ from llm_lab.settings import SettingsDep
16
+
17
+
18
+ def get_http_client(settings: SettingsDep) -> Iterator[httpx.Client]:
19
+ with httpx.Client(timeout=settings.vast_request_timeout_seconds) as http:
20
+ yield http
21
+
22
+
23
+ type HttpClientDep = Annotated[httpx.Client, Depends(get_http_client)]
24
+
25
+
26
+ def get_instance_provider(settings: SettingsDep, http: HttpClientDep) -> InstanceProvider:
27
+ return VastInstanceProvider(settings, http, time.sleep)
28
+
29
+
30
+ type InstanceProviderDep = Annotated[InstanceProvider, Depends(get_instance_provider)]
31
+
32
+
33
+ def get_job_access_store(settings: SettingsDep) -> JobAccessStore:
34
+ return JobAccessStore(settings)
35
+
36
+
37
+ type JobAccessStoreDep = Annotated[JobAccessStore, Depends(get_job_access_store)]
38
+
39
+
40
+ def get_artifact_downloader(settings: SettingsDep, access: JobAccessStoreDep) -> ArtifactDownloader:
41
+ return RsyncDownloader(settings, access)
42
+
43
+
44
+ type ArtifactDownloaderDep = Annotated[ArtifactDownloader, Depends(get_artifact_downloader)]
45
+
46
+
47
+ def get_code_uploader(settings: SettingsDep, access: JobAccessStoreDep) -> CodeUploader:
48
+ return RsyncUploader(settings, access)
49
+
50
+
51
+ type CodeUploaderDep = Annotated[CodeUploader, Depends(get_code_uploader)]
52
+
53
+
54
+ def get_job_orchestrator(
55
+ settings: SettingsDep,
56
+ provider: InstanceProviderDep,
57
+ session: DatabaseSessionDep,
58
+ access: JobAccessStoreDep,
59
+ uploader: CodeUploaderDep,
60
+ downloader: ArtifactDownloaderDep,
61
+ ) -> JobOrchestrator:
62
+ return JobOrchestrator(
63
+ settings,
64
+ provider,
65
+ session,
66
+ SettingsSecretSource(settings),
67
+ access,
68
+ WheelBuilder(settings),
69
+ uploader,
70
+ downloader,
71
+ lambda: datetime.now(UTC),
72
+ time.sleep,
73
+ )
74
+
75
+
76
+ type JobOrchestratorDep = Annotated[JobOrchestrator, Depends(get_job_orchestrator)]