Skip to content

Commit 983f5fa

Browse files
sumanthgenzSumanthSumanthMichaelvllconcretevitamin
authored
[Cost tracking] Cost tracking (sky cost-report) for clusters (skypilot-org#1301)
* add cost tracking for clusters that handles launching, re-starting, getting status, stopping and downing clusters, but no auto-stopping * address Romil PR comments * address Zhanghao PR comments * fix nit * address more PR comments * address last wave of PR comments * sky * address fixing argument for requested resources and fixing spot tests for CI * address more PR comments * make tests resources a list to prevent errors * fix tests again * address PR comments, including adding fetchall to fix status one cluster only bug * fix PR comments * change progress bar interference on stop/down * add sky report instead of showing cost on other commands * address cost report PR comments * address more PR comments on sky report * [Core] Port ray 2.0.1 (skypilot-org#1133) * update ray node provider to 2.0.0 update patches Adapt to ray functions in 2.0.0 update azure-cli version for faster installation format [Onprem] Automatically install sky dependencies (skypilot-org#1116) * Remove root user, move ray cluster to admin * Automatically install sky dependencies * Fix admin alignment * Fix PR * Address romil's comments * F * Addressed Romil's comments Add `--retry-until-up`, `--region`, `--zone`, and `--idle-minutes-to-autostop` for interactive nodes (skypilot-org#1207) * Add --retry-until-up flag for interactive nodes * Add --region flag for interactive nodes * Add --idle-minutes-to-autostop flag for interactive nodes * Add --zone flag for interactive nodes * Update help messages * Address nit Add all region option in catalog fetcher and speed up azure fetcher (skypilot-org#1204) * Port changes * format * add t2a exclusion back * fix A100 for GCP * fix aws fetching for p4de.24xlarge * Fill GPUInfo * fix * address part of comments * address comments * add test for A100 * patch GpuInfo * Add generation info * Add capabilities back to azure and fix aws * fix azure catalog * format * lint * remove zone from azure * fix azure * Add analyze for csv * update catalog analysis * format * backward compatible for azure_catalog * yapf * fix GCP catalog * fix A100-80GB * format * increase version number * only keep useful columns for aws * remove capabilities from azure * add az to AWS Revert "Add `--retry-until-up`, `--region`, `--zone`, and `--idle-minutes-to-autostop` for interactive nodes" (skypilot-org#1220) Revert "Add `--retry-until-up`, `--region`, `--zone`, and `--idle-minutes-to-autostop` for interactive nodes (skypilot-org#1207)" This reverts commit f06416d. [Storage] Add `StorageMode` to __init__ (skypilot-org#1223) * Add storage mode to __init__ * fix [Example] Minimal containerized app example (skypilot-org#1212) * Container example * parenthesis * Add explicit StorageMode * lint Fix Mac Version in Setup.py (skypilot-org#1224) Fix mac Reduce iops for aws instances (skypilot-org#1221) * set the default iops to be same as console for AWS * fix Revert "Reduce iops for aws instances" (skypilot-org#1229) Revert "Reduce iops for aws instances (skypilot-org#1221)" This reverts commit 29f1458. update back compat test * parent 06afd93 author Zhanghao Wu <[email protected]> 1665364265 -0700 committer Zhanghao Wu <[email protected]> 1665899898 -0700 parent 06afd93 author Zhanghao Wu <[email protected]> 1665364265 -0700 committer Zhanghao Wu <[email protected]> 1665899681 -0700 Support for autodown Change API to terminate fix flag address comment format Rename terminate to down add smoke test format fix syntax use gcp for autodown test fix smoke test fix smoke test address comments Switch back to terminate Change back to tear down Change to tear down fix comment * Fix rebase issue * address comments * address * fix setup.py * upgrade to 2.0.1 * Fix docs for ray version * Fix example * fix backward compatibility test * Fix onprem job submission * add steps for backward compat test * docs: Remove version from docs html titles. (skypilot-org#1303) Remove version from docs html titles. * Fix unnecessary ssh hanging issue on Ray (skypilot-org#851) * Fix ray hanging ssh issue * Fix * change the order back * Update node status after first attempt * Set `--rename-dir-limit` for gcsfuse to allow dir renames (skypilot-org#1296) Set rename_dir_lim for gcsfuse * Docs: polish `sky.Task` doc strings. (skypilot-org#1302) * WIP * Polish sky.Task doc strings. * docs: expose Task (a subset of methods); hide Dag. * Tweak Task method order; in docs display methods by source order. * CLI docs: tweak order; tweak `spot launch`. * Address comments. * Code block formatting. * [Launch/Backward Compatibility] Fix incorrect Ray YAML issue (skypilot-org#1287) * Fix incorrect Ray YAML issue * yapf * fix * comments * [Storage] add `--implicit-dirs` for gcsfuse (skypilot-org#1312) add --implicit-dirs * Improving README. (skypilot-org#1308) * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Port landing paras to docs index.rst. * [UX] Disable python output buffer by default (skypilot-org#1290) diable python output buffer * [Storage][Filemounts] Set relative dir root to workdir (skypilot-org#1315) Set relative dir root to workdir for file_mounts * Fix Sky Storage Delete more than 256 Items/folders + Bulk Deletion Tests (skypilot-org#1285) * fix * Add romil's suggestions * Add bulk deletion tests * ok * Fix * [Storage] Add lazy unmount flag (skypilot-org#1320) Add lazy unmount flag * [Core] Fix skylet checking (skypilot-org#1325) * Fix skylet checking * exclude grep * [UX] remove stacktrace for pipe and ssh info (skypilot-org#1324) * UX: remove stacktrace for pipe and ssh info * Add comment * Avoid ray output in the logs * format * revert ssh quiet option * [Dependency] Fix colorama dependency issue with awscli (skypilot-org#1323) * Fix colorama dependency issue with awscli * fix ux for storage delete * Add roadmap. (skypilot-org#1317) * Add roadmap. * Update ROADMAP.md * Fix SKY_NODE_RANK environment variable (skypilot-org#1291) * Add flag for retrieving internal node ips * Ensure SKY_NODE_RANK is 0 for head and stable * Clearer comment for get_internal_ips * Handle different num nodes correctly * Address PR comments * Address nits * [Spot] Fix race condition for spot logs (skypilot-org#1329) * Fix race condition for spot logs * fix * fix comment * address comments * add comment * Add TPU Pod to doc (skypilot-org#1318) * add pod to doc * Apply suggestions from code review Co-authored-by: Zongheng Yang <[email protected]> * comments * comments * update bucket note * Apply suggestions from code review Co-authored-by: Zongheng Yang <[email protected]> * update * update * fix * fix * comments * fix Co-authored-by: Zongheng Yang <[email protected]> * [UX] Add environment variable `SKY_NUM_GPUS_PER_NODE` (skypilot-org#1337) * add SKY_NUM_GPUS_PER_NODE * increase multi-node progress timeout * pin torch version * add comment * address comment * fix smoke test * address comments * [Image] Fix blocking by unattended-upgrade (skypilot-org#1347) * Fix blocking by unattended-upgrade * adopt to gcp and azure * [Test/Azure] Fix the torch version in examples for smoke test and change the credential for Azure (skypilot-org#1330) * Upgrade images for three clouds * Fix cuda version * pin cuda version for torch * Fix torch version * fix comments * Fix azure provider * fix credential * revert back to previous azure image * switch back to cuda 11.3 for pytorch due to azure's image * fix torch installation * increase the multi-node timeout * Update sky/clouds/azure.py Co-authored-by: Zongheng Yang <[email protected]> * revert aws image version * pin cu113 for huggingface * Add comment * format * Update sky/clouds/aws.py Co-authored-by: Zongheng Yang <[email protected]> * Update sky/clouds/gcp.py Co-authored-by: Zongheng Yang <[email protected]> * revert gcp image * Fix doc Co-authored-by: Zongheng Yang <[email protected]> * [Docs] Reorganizing docs. (skypilot-org#1316) * Reorganizing docs. * V2. * Reorg + rewording * Address comments * Remove 'convenient' * Update `SKY_NODE_RANK` docs (skypilot-org#1350) * Add tip for node rank to docs * Update formatting * Indent fix. Co-authored-by: Zongheng Yang <[email protected]> * Add `--retry-until-up`, `--region`, `--zone`, and `--idle-minutes-to-autostop` for interactive nodes (v2) (skypilot-org#1297) * Add --region, --zone, --idle-minutes-to-autostop, and --retry-until-up for interactive nodes * Update user_requested_resources * Add --down for interactive nodes and refactor auto{stop,down} edge case * Refactor click options * Revert "Refactor click options" This reverts commit 10a06a9. * Fix TPU Pod (skypilot-org#1358) * fix pod * yapf * Minor fix for yapf warnings (skypilot-org#1362) * [Docs] Clarify Storage mounting details (skypilot-org#1365) * fix incorrect statements * fix incorrect statements * fix incorrect statements * Fix bugs in GCP A100 prices (skypilot-org#1368) * Fix GCP A100 price bugs * yapf * [Custom Image] Support tag for the images and global regions (skypilot-org#1366) * Support image tag for AWS * add gcp image support * address comments * fix * remove pandas warning * Add example for using ubuntu1804 * add ubuntu 1804 in the test * Enforce trying us regions first * format * address comments * address comments * Add docs and rename methods * Add fetch global regions for GCP * Add all regions for Azure * rename and add doc * remvoe accidently added folder * fix service_catalog * remove extra line * Address comments * mkdir for catalog path * increase waiting time in test * fix test recovery * format * [UX/Doc] Add disk size in resource display and a minor fix for the doc (skypilot-org#1371) Minor fix for docs and ux * [Onprem] Support for Different Type of GPUs + Small Bugfix (skypilot-org#1356) * Ok * Great suggestion from Zhanghao * fix * Update tutorial.rst * Pin `torch` in various examples to avoid cuda version issues. (skypilot-org#1378) * tutorial.rst: pin `torch` to avoid version issues. Tested: - Ran on both AWS and GCP. * Fixes two more yamls * [Env] SKYPILOT_JOB_ID for all tasks (skypilot-org#1377) * Add run id for normal job * add example for the run id * fix env_check * fix env_check * fix * address comments * Rename to SKYPILOT_JOB_ID * rename the controller's job id to avoid confusion * rename env variables * fix * [Core] Add support for detach setup (skypilot-org#1379) * Add support for async setup * Fix logging * Add test for async setup * add parens * fix * refactor a bit * Fix status * fix smoke test * rename * fix is_cluster_idle function * format * address comments * fix * Add setup failed * Fix failed setup * Add comment * Add comments * format * fix logs * format * address comments * Minor UX fix: `sky cancel` should not print stacktraces. (skypilot-org#1385) * Minor UX fix: `sky cancel` should not print stacktraces. * Wording fix. * exit 1 * [UX] Disable ssh connection sharing for setup (skypilot-org#1390) * Disable ssh connection sharing for setup * format * remove redundant * fix type hint * Docs: multi-node clarifications, and ssh into workers. (skypilot-org#1363) * Fixes skypilot-org#1338: add docs on logging into workers. * Fixes skypilot-org#1340 and fixes skypilot-org#1339. * Address comments * Reword. * Hint. * Fix Logging for `sky launch` on new machine (skypilot-org#1382) * ok * ok * Ok * ok * Unify methods * ok * fix * [Image] Support passing AMIs for different regions (skypilot-org#1384) * image dict in resources * fix * fix * add tests * add per region example * address comments * Fix checking * fix * fix smoke test * [LocalDockerBackend] Update `is_local_cluster` check for docker backend (skypilot-org#1396) Update is_local_cluster check for LocalDockerBackend * [Setup] unset CUDA_VISIBLE_DEVICES for detach setup (skypilot-org#1404) * unset CUDA_VISIBLE_DEVICES * add env check example * Add setting CUDA_VISIBLE_DEVICES test * fix * Update sky/backends/cloud_vm_ray_backend.py Co-authored-by: Zongheng Yang <[email protected]> * format Co-authored-by: Zongheng Yang <[email protected]> * [Spot] Keep SKYPILOT_JOB_ID the same for the same spot job (skypilot-org#1400) * fix SKYPILOT_JOB_ID * Fix test * fix * format * Add SKYPILOT_JOB_ID to sky spot queue * nit * don't set job_id_env_var for spot controller task * address comments * Revert SKYPILOT_JOB_ID in spot queue * format * Change default value of task.envs to dict * [UX] fix the error for the first time `sky launch` (skypilot-org#1405) * fix ux * test * fix no public cloud * address comments * Fix logging * format * Remove the error type for CLI * yellow * fix * Fix logging * [Spot] Fix spot recovery for multi node (skypilot-org#1411) * Add cluster status check even job is RUNNING for multi-node * Disable autoscaler logs and fix finished when partially preempted * format * Add test * address comments * update * Add time * [Release] Fix pypi description (skypilot-org#1416) * Fix pypi description * fix * format * [Bug fix] head_ip extraction from Ray stdout (skypilot-org#1421) * Fix bug in head_ip extraction from Ray stdout after launching cluster by using regex to exactly match ip. * Remove unneeded comment. * Update sky/backends/cloud_vm_ray_backend.py Co-authored-by: Zhanghao Wu <[email protected]> * Run yapf and pylint Co-authored-by: Zhanghao Wu <[email protected]> * [Global Regions] Add data fetchers into wheel (skypilot-org#1406) * Add data fetchers into wheel * yapf * Fix gcp fetcher * Add check * exclude analyze.py * Link to blog on README and docs. (skypilot-org#1430) * [Spot] Let cancel interrupt the spot job (skypilot-org#1414) * Let cancel interrupt the job * Add test * Fix test * Cancel early * fix test * fix test * Fix exceptions * pass test * increase waiting time * address comments * add job id * remove 'auto' in ray.init * Revert "[Spot] Let cancel interrupt the spot job" (skypilot-org#1432) Revert "[Spot] Let cancel interrupt the spot job (skypilot-org#1414)" This reverts commit 3bbf4aa. * [AWS] Avoid key pair permission issue by using cloud-init for authorized keys (skypilot-org#1427) * Switch to UserData to add public key for AWS * fix * Avoid hardcoding username * Fix backward compatibility test * address comments * address comments * Minor spot logs fix: don't print job id not provided on spot launch. (skypilot-org#1434) Minor spot logs fix: don't print job id not provided. * [Catalog] Remove hardcoded A2 pricing URL & Fix a bug in A2 machine zones (skypilot-org#1426) * Update no 16xA100-40GB zones * [Catalog] Remove GCP A2 price URL & Fix GCP A100 zone issues * Add more type annotations * Minor * yapf * Do not add GCP URL prefix * Minor * Address comments * Address comment1 * Minor * Add comments about the case when a100.empty is True * Assert not duplicated * [Spot] Let cancel interrupt the spot job (skypilot-org#1414) (skypilot-org#1433) * Let cancel interrupt the job * Add test * Fix test * Cancel early * fix test * fix test * Fix exceptions * pass test * increase waiting time * address comments * add job id * remove 'auto' in ray.init * Fix serialization problem * refactor a bit * Fix * Add comments * format * pylint * revert a format change * Add docstr * Move ray.init * replace ray with multiprocess.Process * Add test for setup cancelation * Fix logging * Fix test * lint * Use SIGTERM instead * format * Change exception type * revert to KeyboardInterrupt * remove * Fix test * fix test * fix test * typo * [Usage] Robustify the user hash to avoid empty string (skypilot-org#1442) * Robustify the user hash to avoid empty string * fix * Check valid user hash with hexdecimal * format * fix * Add fallback * Add comment * lint * [Storage] Support multiple files in Storage (skypilot-org#1311) * Set rename_dir_lim for gcsfuse * Add support for list of sources for Storage * fix demo yaml * tests * lint * lint * test * add validation * address zhwu comments * add error on basename conflicts * use gsutil cp -n instead of gsutil rsync * lint * fix name * parallelize gsutil rsync * parallelize aws s3 rsync * lint * address comments * refactor * lint * address comments * update schema * Logging fixes. (skypilot-org#1452) * Logging fixes. * yapf * sys.exit(1) * [Storage] Fix copy monuts for file with s3 bucket url (skypilot-org#1457) * test file download with s3 * fix test * fix storage file mounts * format * remove mkdir for `make_sync_dir_command` * Print errors for GCP timeout. (skypilot-org#1454) * [autostop] Support restarting the autostop timer. (skypilot-org#1458) * [autostop] Support restarting the autostop timer. * Logging * Make each job submission call set_active_time_to_now(). * Fix test and pylint. * Fix comments. * Change tests; some fixes * logging remnant * remnant * [Spot] Make sure the cluster status is not None when showing (skypilot-org#1464) * Make sure the cluster status is not None when showing * Fix another potential issue with NoneType of handle * Add assert * fix * format * Address comments * Address comments * format * format * fix * fix * fix spot cancellation * format * Add a few small warnings to README and CONTRIBUTING. (skypilot-org#1422) * Add a couple small warnings to README and CONTRIBUTING. * Update README.md Co-authored-by: Zongheng Yang <[email protected]> Co-authored-by: Zongheng Yang <[email protected]> * Hotfix for spot TPU pod recovery (skypilot-org#1470) * hotfix * comment * [Spot] Better spot logs (skypilot-org#1412) * Add cluster status check even job is RUNNING for multi-node * Disable autoscaler logs and fix finished when partially preempted * format * Add test * Better spot logging * Add logs * format * address comments * address comments part 2 * Finish the logging early * format * better logging * Address comments * Fix message * Address comments * Improve UX for logs to include SSH name and rank (skypilot-org#1380) * Messy WIP * Fixes two more yamls * Improve log UX and ensure stableness * Remove print statement * Remove task name from logs * Fix name for single-node tasks * Update var names and comments for clarity * Update logic for single and multi-node clusters * Cache stable cluster IP list in ResourceHandle * Properly cache and invalidate stable list * Add back SKYPILOT_NODE_IPS * Update log file name * Refactor backend to use cached stable IP list * Fix spot test * Fix formatting * Refactor ResourceHandle * Fixes for correctness * Remove unneeded num_nodes arg * Fix _gang_schedule_ray_up * Ensure stable IP list is cached * Formatting fixes * Refactor updating stable IPs to be part of handle * Merge max attempts constant * Fix ordering for setting TPU name * Fix bugs and clean up code * Fix backwards compatibility * Fix bug with old autostopped clusters * Fix comment * Fix assertion statement * Update assertion message Co-authored-by: Zhanghao Wu <[email protected]> * Fix linting * Fix retrieving IPs for TPU vm * Add optimization for updating IPs * Linting fix * Update comment Co-authored-by: Zongheng Yang <[email protected]> Co-authored-by: Zhanghao Wu <[email protected]> * add cost tracking for clusters that handles launching, re-starting, getting status, stopping and downing clusters, but no auto-stopping * fix some artifacts from rebase error * handle linting * make it cost-report * address PR changes for approval * last changes * address last changes * move around comments for sort * add cost_report func to init.all list Co-authored-by: Sumanth <[email protected]> Co-authored-by: Sumanth <[email protected]> Co-authored-by: Zhanghao Wu <[email protected]> Co-authored-by: Zongheng Yang <[email protected]> Co-authored-by: Wei-Lin Chiang <[email protected]> Co-authored-by: Romil Bhardwaj <[email protected]> Co-authored-by: Michael Luo <[email protected]> Co-authored-by: Isaac Ong <[email protected]> Co-authored-by: ewzeng <[email protected]> Co-authored-by: Woosuk Kwon <[email protected]> Co-authored-by: Donny Greenberg <[email protected]>
1 parent 05727f8 commit 983f5fa

File tree

9 files changed

+450
-46
lines changed

9 files changed

+450
-46
lines changed

sky/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from sky.skylet.job_lib import JobStatus
2222
from sky.core import (status, start, stop, down, autostop, queue, cancel,
2323
tail_logs, download_logs, job_status, spot_queue,
24-
spot_status, spot_cancel, storage_ls, storage_delete)
24+
spot_status, spot_cancel, storage_ls, storage_delete,
25+
cost_report)
2526

2627
# Aliases.
2728
AWS = clouds.AWS
@@ -61,6 +62,7 @@
6162
'stop',
6263
'down',
6364
'autostop',
65+
'cost_report',
6466
# core APIs Job Management
6567
'queue',
6668
'cancel',

sky/backends/backend_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,7 @@ def _update_cluster_status_no_lock(
18791879
record['status'] = global_user_state.ClusterStatus.UP
18801880
global_user_state.add_or_update_cluster(cluster_name,
18811881
handle,
1882+
requested_resources=None,
18821883
ready=True,
18831884
is_launch=False)
18841885
return record
@@ -1958,6 +1959,7 @@ def _update_cluster_status_no_lock(
19581959
# Adding a new status UNHEALTHY for abnormal status can be a choice.
19591960
global_user_state.add_or_update_cluster(cluster_name,
19601961
handle,
1962+
requested_resources=None,
19611963
ready=False,
19621964
is_launch=False)
19631965
return global_user_state.get_cluster_from_name(cluster_name)

sky/backends/cloud_vm_ray_backend.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import textwrap
1717
import time
1818
import typing
19-
from typing import Dict, List, Optional, Tuple, Union
19+
from typing import Dict, List, Optional, Tuple, Union, Set
2020

2121
import colorama
2222
import filelock
@@ -1060,14 +1060,17 @@ def _try_provision_tpu(self, to_provision: resources_lib.Resources,
10601060
logger.error(stderr)
10611061
raise e
10621062

1063-
def _retry_region_zones(self,
1064-
to_provision: resources_lib.Resources,
1065-
num_nodes: int,
1066-
dryrun: bool,
1067-
stream_logs: bool,
1068-
cluster_name: str,
1069-
cloud_user_identity: Optional[str],
1070-
cluster_exists: bool = False):
1063+
def _retry_region_zones(
1064+
self,
1065+
to_provision: resources_lib.Resources,
1066+
num_nodes: int,
1067+
requested_resources: Set[resources_lib.Resources],
1068+
dryrun: bool,
1069+
stream_logs: bool,
1070+
cluster_name: str,
1071+
cloud_user_identity: str,
1072+
cluster_exists: bool = False,
1073+
):
10711074
"""The provision retry loop."""
10721075
style = colorama.Style
10731076
fore = colorama.Fore
@@ -1150,9 +1153,13 @@ def _retry_region_zones(self,
11501153
global_user_state.ClusterStatus.INIT)
11511154

11521155
# This sets the status to INIT (even for a normal, UP cluster).
1153-
global_user_state.add_or_update_cluster(cluster_name,
1154-
cluster_handle=handle,
1155-
ready=False)
1156+
global_user_state.add_or_update_cluster(
1157+
cluster_name,
1158+
cluster_handle=handle,
1159+
requested_resources=requested_resources,
1160+
ready=False,
1161+
)
1162+
11561163
global_user_state.set_owner_identity_for_cluster(
11571164
cluster_name, cloud_user_identity)
11581165

@@ -1630,6 +1637,7 @@ def provision_with_retries(
16301637
config_dict = self._retry_region_zones(
16311638
to_provision,
16321639
num_nodes,
1640+
requested_resources=task.resources,
16331641
dryrun=dryrun,
16341642
stream_logs=stream_logs,
16351643
cluster_name=cluster_name,
@@ -2204,9 +2212,12 @@ def _provision(self,
22042212
stdout + stderr)
22052213

22062214
with timeline.Event('backend.provision.post_process'):
2207-
global_user_state.add_or_update_cluster(cluster_name,
2208-
handle,
2209-
ready=True)
2215+
global_user_state.add_or_update_cluster(
2216+
cluster_name,
2217+
handle,
2218+
task.resources,
2219+
ready=True,
2220+
)
22102221
usage_lib.messages.usage.update_final_cluster_status(
22112222
global_user_state.ClusterStatus.UP)
22122223
auth_config = common_utils.read_yaml(
@@ -3012,6 +3023,7 @@ def post_teardown_cleanup(self,
30123023
backend_utils.SSHConfigHelper.remove_cluster(handle.cluster_name,
30133024
handle.head_ip,
30143025
auth_config)
3026+
30153027
global_user_state.remove_cluster(handle.cluster_name,
30163028
terminate=terminate)
30173029

sky/backends/local_docker_backend.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ def _provision(self,
153153
self.images[handle] = [image_tag, metadata]
154154
logger.info(f'Image {image_tag} built.')
155155
logger.info('Provisioning complete.')
156-
global_user_state.add_or_update_cluster(cluster_name,
157-
cluster_handle=handle,
158-
ready=False)
156+
global_user_state.add_or_update_cluster(
157+
cluster_name,
158+
cluster_handle=handle,
159+
requested_resources=task.resources,
160+
ready=False)
159161
return handle
160162

161163
def _sync_workdir(self, handle: ResourceHandle, workdir: Path) -> None:
@@ -244,9 +246,11 @@ def _setup(self, handle: ResourceHandle, task: 'task_lib.Task') -> None:
244246
f'-it {container.name} /bin/bash{style.RESET_ALL}.\n'
245247
f'You can debug the image by running: {style.BRIGHT}docker run -it '
246248
f'{image_tag} /bin/bash{style.RESET_ALL}.\n')
247-
global_user_state.add_or_update_cluster(cluster_name,
248-
cluster_handle=handle,
249-
ready=True)
249+
global_user_state.add_or_update_cluster(
250+
cluster_name,
251+
cluster_handle=handle,
252+
requested_resources=task.resources,
253+
ready=True)
250254

251255
def _execute(self, handle: ResourceHandle, task: 'task_lib.Task',
252256
detach_run: bool) -> None:
@@ -309,6 +313,7 @@ def _teardown(self,
309313
container = self.containers[handle]
310314
container.remove(force=True)
311315
cluster_name = handle.get_cluster_name()
316+
312317
global_user_state.remove_cluster(cluster_name, terminate=True)
313318

314319
# --- Utilities ---

sky/cli.py

+45
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,50 @@ def status(all: bool, refresh: bool): # pylint: disable=redefined-builtin
14491449
status_utils.show_local_status_table(local_clusters)
14501450

14511451

1452+
@cli.command()
1453+
@click.option('--all',
1454+
'-a',
1455+
default=False,
1456+
is_flag=True,
1457+
required=False,
1458+
help='Show all information in full.')
1459+
@usage_lib.entrypoint
1460+
def cost_report(all: bool): # pylint: disable=redefined-builtin
1461+
# NOTE(dev): Keep the docstring consistent between the Python API and CLI.
1462+
"""Show cost reports for each cluster.
1463+
1464+
The following fields for each cluster are recorded: cluster name,
1465+
resources, launched time, duration that cluster was up,
1466+
and total cost.
1467+
1468+
The estimated cost column indicates the price for the cluster based on the
1469+
type of resources being used and the duration of use up until the call
1470+
to status. This means if the cluster is UP, successive calls to report
1471+
will show increasing price. The estimated cost is calculated based on
1472+
the local cache of the cluster status, and may not be accurate for
1473+
the cluster with autostop/use_spot set or terminated/stopped
1474+
on the cloud console.
1475+
"""
1476+
1477+
cluster_records = core.cost_report()
1478+
nonreserved_cluster_records = []
1479+
reserved_clusters = dict()
1480+
for cluster_record in cluster_records:
1481+
cluster_name = cluster_record['name']
1482+
if cluster_name in backend_utils.SKY_RESERVED_CLUSTER_NAMES:
1483+
cluster_group_name = backend_utils.SKY_RESERVED_CLUSTER_NAMES[
1484+
cluster_name]
1485+
reserved_clusters[cluster_group_name] = cluster_record
1486+
else:
1487+
nonreserved_cluster_records.append(cluster_record)
1488+
1489+
status_utils.show_cost_report_table(nonreserved_cluster_records, all)
1490+
1491+
for cluster_group_name, cluster_record in reserved_clusters.items():
1492+
status_utils.show_cost_report_table(
1493+
[cluster_record], all, reserved_group_name=cluster_group_name)
1494+
1495+
14521496
@cli.command()
14531497
@click.option('--all-users',
14541498
'-a',
@@ -2340,6 +2384,7 @@ def _down_or_stop(name: str):
23402384
f'{colorama.Style.BRIGHT}sky start {name}'
23412385
f'{colorama.Style.RESET_ALL}')
23422386
success_progress = True
2387+
23432388
progress.stop()
23442389
click.echo(message)
23452390
if success_progress:

sky/core.py

+50
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,56 @@ def status(cluster_names: Optional[Union[str, Sequence[str]]] = None,
102102
cluster_names=cluster_names)
103103

104104

105+
@usage_lib.entrypoint
106+
def cost_report() -> List[Dict[str, Any]]:
107+
# NOTE(dev): Keep the docstring consistent between the Python API and CLI.
108+
"""Get all cluster cost reports, including those that have been downed.
109+
110+
Each returned value has the following fields:
111+
112+
.. code-block:: python
113+
114+
{
115+
'name': (str) cluster name,
116+
'launched_at': (int) timestamp of last launch on this cluster,
117+
'duration': (int) total seconds that cluster was up and running,
118+
'last_use': (str) the last command/entrypoint that affected this
119+
'num_nodes': (int) number of nodes launched for cluster,
120+
'resources': (resources.Resources) type of resource launched,
121+
'cluster_hash': (str) unique hash identifying cluster,
122+
'usage_intervals': (List[Tuple[int, int]]) cluster usage times,
123+
'total_cost': (float) cost given resources and usage intervals,
124+
}
125+
126+
127+
The estimated cost column indicates price for the cluster based on the
128+
type of resources being used and the duration of use up until the call
129+
to status. This means if the cluster is UP, successive calls to report
130+
will show increasing price. The estimated cost is calculated based on
131+
the local cache of the cluster status, and may not be accurate for
132+
the cluster with autostop/use_spot set or terminated/stopped
133+
on the cloud console.
134+
135+
Returns:
136+
A list of dicts, with each dict containing the cost information of a
137+
cluster.
138+
"""
139+
cluster_reports = global_user_state.get_clusters_from_history()
140+
141+
def get_total_cost(cluster_report: dict) -> float:
142+
duration = cluster_report['duration']
143+
launched_nodes = cluster_report['num_nodes']
144+
launched_resources = cluster_report['resources']
145+
146+
cost = (launched_resources.get_cost(duration) * launched_nodes)
147+
return cost
148+
149+
for cluster_report in cluster_reports:
150+
cluster_report['total_cost'] = get_total_cost(cluster_report)
151+
152+
return cluster_reports
153+
154+
105155
def _start(
106156
cluster_name: str,
107157
idle_minutes_to_autostop: Optional[int] = None,

0 commit comments

Comments
 (0)