Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI] Now show-gpus shows the combined price for GCP GPU instance #2946

Merged
merged 17 commits into from
Jan 11, 2024
5 changes: 0 additions & 5 deletions sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3543,11 +3543,6 @@ def _output():
yield 'to show available accelerators.'
return

if cloud is None or cloud.lower() == 'gcp':
yield '*NOTE*: for most GCP accelerators, '
yield 'INSTANCE_TYPE == (attachable) means '
yield 'the host VM\'s cost is not included.\n\n'

import pandas as pd # pylint: disable=import-outside-toplevel
for i, (gpu, items) in enumerate(result.items()):
accelerator_table_headers = [
Expand Down
40 changes: 23 additions & 17 deletions sky/clouds/service_catalog/gcp_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,34 +385,41 @@ def list_accelerators(
new_results[acc_name] = acc_info
results = new_results

# Unlike other GPUs that can be attached to different sizes of N1 VMs,
# A100 GPUs can only be attached to fixed-size A2 VMs,
# and L4 GPUs can only be attached to G2 VMs.
# Thus, we can show their exact cost including the host VM prices.

acc_infos: List[common.InstanceTypeInfo] = sum(
[results.get(a, []) for a in _ACC_INSTANCE_TYPE_DICTS], [])
if not acc_infos:
return results
# Figure out which instance type to use.
infos_with_instance_type: List[common.InstanceTypeInfo] = sum(
results.values(), [])

new_infos = defaultdict(list)
for info in acc_infos:
assert pd.isna(info.instance_type) and pd.isna(info.memory), acc_infos
vm_types = _ACC_INSTANCE_TYPE_DICTS[info.accelerator_name][
info.accelerator_count]
for info in infos_with_instance_type:
assert pd.isna(info.instance_type) and pd.isna(info.memory), info
#TPU-VM prices are shown here, so we don't ned to attach a VM to it.
if info.accelerator_name.startswith('tpu'):
new_infos[info.accelerator_name].append(
info._replace(instance_type='TPU-VM'))
continue
vm_types, _ = get_instance_type_for_accelerator(info.accelerator_name,
info.accelerator_count,
region=region_filter)
# The acc name & count in `info` are retrieved from the table so we
# could definitely find a column in the original table
# Additionally the way get_instance_type_for_accelerator works
# we will always get either a specialized instance type
# or a default instance type. So we can safely assume that
# vm_types is not None.
assert vm_types is not None
for vm_type in vm_types:
df = _df[_df['InstanceType'] == vm_type]
cpu_count = df['vCPUs'].iloc[0]
memory = df['MemoryGiB'].iloc[0]
vm_price = common.get_hourly_cost_impl(_df,
vm_type,
use_spot=False,
region=None,
region=region_filter,
zone=None)
vm_spot_price = common.get_hourly_cost_impl(_df,
vm_type,
use_spot=True,
region=None,
region=region_filter,
zone=None)
new_infos[info.accelerator_name].append(
info._replace(
Expand All @@ -423,8 +430,7 @@ def list_accelerators(
price=info.price + vm_price,
spot_price=info.spot_price + vm_spot_price,
))
results.update(new_infos)
return results
return new_infos


def get_region_zones_for_accelerators(
Expand Down