Skip to content

Commit

Permalink
Allow to specify max offers shown in run plan
Browse files Browse the repository at this point in the history
  • Loading branch information
r4victor committed Aug 17, 2023
1 parent b47f7c7 commit 6eb18d5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 0 additions & 4 deletions cli/dstack/_internal/backend/base/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
from dstack._internal.core.run import RequestStatus, RunHead, generate_remote_run_name_prefix


def generate_run_name(storage: Storage, backend_type: str, run_name: Optional[str]) -> str:
r


def create_run(storage: Storage, run_name: str) -> str:
if run_name is None:
return _generate_random_run_name(storage)
Expand Down
8 changes: 7 additions & 1 deletion cli/dstack/_internal/cli/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def register(self):
type=str,
dest="profile_name",
)
self._parser.add_argument(
"--max-offers",
help="The maximum number of best offers shown in run plan",
type=int,
default=3,
)
self._parser.add_argument(
"args",
metavar="ARGS",
Expand Down Expand Up @@ -114,7 +120,7 @@ def _command(self, args: Namespace):

run_plan = hub_client.get_run_plan(configurator)
console.print("dstack will execute the following plan:\n")
print_run_plan(configurator, run_plan)
print_run_plan(configurator, run_plan, args.max_offers)
if not args.yes and not Confirm.ask("Continue?"):
console.print("\nExiting...")
exit(0)
Expand Down
8 changes: 5 additions & 3 deletions cli/dstack/_internal/cli/utils/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read_ssh_key_pub(key_path: str) -> str:
return path.with_suffix(path.suffix + ".pub").read_text().strip("\n")


def print_run_plan(configurator: JobConfigurator, run_plan: RunPlan):
def print_run_plan(configurator: JobConfigurator, run_plan: RunPlan, candidates_limit: int = 3):
job_plan = run_plan.job_plans[0]
requirements = job_plan.job.requirements

Expand Down Expand Up @@ -85,6 +85,8 @@ def print_run_plan(configurator: JobConfigurator, run_plan: RunPlan):
candidates.add_column("SPOT")
candidates.add_column("PRICE")

job_plan.candidates = job_plan.candidates[:candidates_limit]

for i, c in enumerate(job_plan.candidates, start=1):
r = c.instance.resources
resources = f"{r.cpus}xCPUs, {r.memory_mib / 1024:g}GB"
Expand All @@ -98,11 +100,11 @@ def print_run_plan(configurator: JobConfigurator, run_plan: RunPlan):
c.region,
c.instance.instance_name,
resources,
"yes" if r.spot else "",
"yes" if r.spot else "no",
f"${c.price:g}",
style=None if i == 1 else "grey58",
)
if len(job_plan.candidates) == 3:
if len(job_plan.candidates) == candidates_limit:
candidates.add_row("", "...", style="grey58")

console.print(props)
Expand Down
2 changes: 1 addition & 1 deletion cli/dstack/_internal/hub/routers/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def get_run_plan(
instance=offer.instance_type,
price=offer.price,
)
for backend, offer in candidates[:3]
for backend, offer in candidates[:50]
],
)
job_plans.append(job_plan)
Expand Down
1 change: 1 addition & 0 deletions docs/docs/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The following arguments are optional:

[//]: # (- `-t TAG`, `--tag TAG` – (Optional) A tag name. Warning, if the tag exists, it will be overridden.)
- `--backend [BACKEND ...]` – (Optional) Backend(s) to consider for provisioning
- `--max-offers MAX_OFFERS` – (Optional) The maximum number of best offers shown in run plan
- `-p PORT`, `--port PORT` – (Optional) Requests port or define mapping (`EXTERNAL_PORT:INTERNAL_PORT`)
- `-e ENV`, `--env ENV` – (Optional) Set environment variable (`NAME=value`)
- `--gpu` – (Optional) Request a GPU for the run. Specify any: name, count, memory (`NAME:COUNT:MEMORY` or `NAME` or `COUNT:MEMORY`, etc...)
Expand Down

0 comments on commit 6eb18d5

Please sign in to comment.