Skip to content

Commit

Permalink
move to resources_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
romilbhardwaj committed Jul 19, 2024
1 parent a2df6fc commit 4e7b21d
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 107 deletions.
16 changes: 8 additions & 8 deletions sky/clouds/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def make_deploy_resources_variables(

def _get_feasible_launchable_resources(
self, resources: 'resources_lib.Resources'
) -> 'resources_lib.FeasibleResources':
) -> resources_utils.FeasibleResources:
if resources.instance_type is not None:
assert resources.is_launchable(), resources
# Check the instance type is valid in the cloud
Expand All @@ -452,10 +452,10 @@ def _get_feasible_launchable_resources(
region=resources.region,
zone=resources.zone)
if not regions:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
# Treat Resources(AWS, p3.2x, V100) as Resources(AWS, p3.2x).
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

def _make(instance_list):
resource_list = []
Expand All @@ -481,9 +481,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources_lib.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -499,10 +499,10 @@ def _make(instance_list):
zone=resources.zone,
clouds='aws')
if instance_list is None:
return resources_lib.FeasibleResources([], fuzzy_candidate_list,
return resources_utils.FeasibleResources([], fuzzy_candidate_list,
None)
return resources_lib.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
@functools.lru_cache(maxsize=1) # Cache since getting identity is slow.
Expand Down
14 changes: 7 additions & 7 deletions sky/clouds/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,17 @@ def _failover_disk_tier() -> Optional[resources_utils.DiskTier]:

def _get_feasible_launchable_resources(
self,
resources: 'resources.Resources') -> 'resources.FeasibleResources':
resources: 'resources.Resources') -> 'resources_utils.FeasibleResources':
if resources.instance_type is not None:
assert resources.is_launchable(), resources
ok, _ = Azure.check_disk_tier(resources.instance_type,
resources.disk_tier)
if not ok:
return resources.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
# Treat Resources(Azure, Standard_NC4as_T4_v3, T4) as
# Resources(Azure, Standard_NC4as_T4_v3).
resources = resources.copy(accelerators=None)
return resources.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

def _make(instance_list):
resource_list = []
Expand Down Expand Up @@ -418,9 +418,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -436,8 +436,8 @@ def _make(instance_list):
zone=resources.zone,
clouds='azure')
if instance_list is None:
return resources.FeasibleResources([], fuzzy_candidate_list, None)
return resources.FeasibleResources(_make(instance_list),
return resources_utils.FeasibleResources([], fuzzy_candidate_list, None)
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions sky/clouds/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def is_label_valid(cls, label_key: str,
def get_feasible_launchable_resources(
self,
resources: 'resources_lib.Resources',
num_nodes: int = 1) -> 'resources_lib.FeasibleResources':
num_nodes: int = 1) -> 'resources_utils.FeasibleResources':
"""Returns FeasibleResources for the given resources.
Feasible resources refer to an offering respecting the resource
Expand Down Expand Up @@ -376,7 +376,7 @@ def get_feasible_launchable_resources(
# TODO(zhwu): The resources are now silently filtered out. We
# should have some logging telling the user why the resources
# are not considered.
return resources_lib.FeasibleResources(resources_list=[],
return resources_utils.FeasibleResources(resources_list=[],
fuzzy_candidate_list=[],
hint=None)
return self._get_feasible_launchable_resources(resources)
Expand Down
14 changes: 7 additions & 7 deletions sky/clouds/cudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ def make_deploy_resources_variables(

def _get_feasible_launchable_resources(
self, resources: 'resources_lib.Resources'
) -> 'resources_lib.FeasibleResources':
) -> 'resources_utils.FeasibleResources':
if resources.use_spot:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
if resources.instance_type is not None:
assert resources.is_launchable(), resources
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

def _make(instance_list):
resource_list = []
Expand All @@ -244,9 +244,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources_lib.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -262,9 +262,9 @@ def _make(instance_list):
zone=resources.zone,
clouds='cudo')
if instance_list is None:
return resources_lib.FeasibleResources([], fuzzy_candidate_list,
return resources_utils.FeasibleResources([], fuzzy_candidate_list,
None)
return resources_lib.FeasibleResources(_make(instance_list),
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
Expand Down
10 changes: 5 additions & 5 deletions sky/clouds/fluidstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _get_feasible_launchable_resources(
assert resources.is_launchable(), resources
# Accelerators are part of the instance type in Fluidstack Cloud
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

def _make(instance_list):
resource_list = []
Expand Down Expand Up @@ -239,9 +239,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources_lib.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -257,9 +257,9 @@ def _make(instance_list):
zone=resources.zone,
clouds='fluidstack')
if instance_list is None:
return resources_lib.FeasibleResources([], fuzzy_candidate_list,
return resources_utils.FeasibleResources([], fuzzy_candidate_list,
None)
return resources_lib.FeasibleResources(_make(instance_list),
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
Expand Down
24 changes: 12 additions & 12 deletions sky/clouds/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ def make_deploy_resources_variables(

def _get_feasible_launchable_resources(
self,
resources: 'resources.Resources') -> 'resources.FeasibleResources':
resources: 'resources.Resources') -> 'resources_utils.FeasibleResources':
if resources.instance_type is not None:
assert resources.is_launchable(), resources
return resources.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

if resources.accelerators is None:
# Return a default instance type with the given number of vCPUs.
Expand All @@ -538,7 +538,7 @@ def _get_feasible_launchable_resources(
memory=resources.memory,
disk_tier=resources.disk_tier)
if host_vm_type is None:
return resources.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
r = resources.copy(
cloud=GCP(),
Expand All @@ -547,7 +547,7 @@ def _get_feasible_launchable_resources(
cpus=None,
memory=None,
)
return resources.FeasibleResources([r], [], None)
return resources_utils.FeasibleResources([r], [], None)

# Find instance candidates to meet user's requirements
assert len(resources.accelerators.items()
Expand All @@ -569,7 +569,7 @@ def _get_feasible_launchable_resources(
clouds='gcp')

if instance_list is None:
return resources.FeasibleResources([], fuzzy_candidate_list, None)
return resources_utils.FeasibleResources([], fuzzy_candidate_list, None)
assert len(
instance_list
) == 1, f'More than one instance type matched, {instance_list}'
Expand All @@ -584,13 +584,13 @@ def _get_feasible_launchable_resources(
if resources.cpus.endswith('+'):
cpus = float(resources.cpus[:-1])
if cpus > num_cpus_in_tpu_vm:
return resources.FeasibleResources([],
fuzzy_candidate_list,
None)
return resources_utils.FeasibleResources([],
fuzzy_candidate_list,
None)
else:
cpus = float(resources.cpus)
if cpus != num_cpus_in_tpu_vm:
return resources.FeasibleResources([],
return resources_utils.FeasibleResources([],
fuzzy_candidate_list,
None)
# FIXME(woosuk, wei-lin): This leverages the fact that TPU VMs
Expand All @@ -601,13 +601,13 @@ def _get_feasible_launchable_resources(
if resources.memory.endswith('+'):
memory = float(resources.memory[:-1])
if memory > memory_in_tpu_vm:
return resources.FeasibleResources([],
return resources_utils.FeasibleResources([],
fuzzy_candidate_list,
None)
else:
memory = float(resources.memory)
if memory != memory_in_tpu_vm:
return resources.FeasibleResources([],
return resources_utils.FeasibleResources([],
fuzzy_candidate_list,
None)
else:
Expand All @@ -621,7 +621,7 @@ def _get_feasible_launchable_resources(
cpus=None,
memory=None,
)
return resources.FeasibleResources([r], fuzzy_candidate_list, None)
return resources_utils.FeasibleResources([r], fuzzy_candidate_list, None)

@classmethod
def get_accelerators_from_instance_type(
Expand Down
12 changes: 6 additions & 6 deletions sky/clouds/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ def get_default_instance_type(

def _get_feasible_launchable_resources(
self, resources: 'resources_lib.Resources'
) -> 'resources_lib.FeasibleResources':
) -> 'resources_utils.FeasibleResources':
fuzzy_candidate_list: List[str] = []
if resources.instance_type is not None:
assert resources.is_launchable(), resources
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources],
return resources_utils.FeasibleResources([resources],
fuzzy_candidate_list, None)

def _make(instance_list):
Expand All @@ -297,9 +297,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources_lib.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -314,9 +314,9 @@ def _make(instance_list):
zone=resources.zone,
clouds='ibm')
if instance_list is None:
return resources_lib.FeasibleResources([], fuzzy_candidate_list,
return resources_utils.FeasibleResources([], fuzzy_candidate_list,
None)
return resources_lib.FeasibleResources(_make(instance_list),
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions sky/clouds/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ def make_deploy_resources_variables(

def _get_feasible_launchable_resources(
self, resources: 'resources_lib.Resources'
) -> 'resources_lib.FeasibleResources':
) -> 'resources_utils.FeasibleResources':
fuzzy_candidate_list: List[str] = []
if resources.instance_type is not None:
assert resources.is_launchable(), resources
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources],
return resources_utils.FeasibleResources([resources],
fuzzy_candidate_list, None)

def _make(instance_list):
Expand Down Expand Up @@ -400,10 +400,10 @@ def _make(instance_list):
logger.debug(f'Instance type {chosen_instance_type} does '
'not fit in the Kubernetes cluster. '
f'Reason: {reason}')
return resources_lib.FeasibleResources([], [], reason)
return resources_utils.FeasibleResources([], [], reason)

# No fuzzy lists for Kubernetes
return resources_lib.FeasibleResources(_make([chosen_instance_type]),
return resources_utils.FeasibleResources(_make([chosen_instance_type]),
[], None)

@classmethod
Expand Down
12 changes: 6 additions & 6 deletions sky/clouds/lambda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def make_deploy_resources_variables(

def _get_feasible_launchable_resources(
self, resources: 'resources_lib.Resources'
) -> 'resources_lib.FeasibleResources':
) -> 'resources_utils.FeasibleResources':
if resources.instance_type is not None:
assert resources.is_launchable(), resources
# Accelerators are part of the instance type in Lambda Cloud
resources = resources.copy(accelerators=None)
return resources_lib.FeasibleResources([resources], [], None)
return resources_utils.FeasibleResources([resources], [], None)

def _make(instance_list):
resource_list = []
Expand All @@ -209,9 +209,9 @@ def _make(instance_list):
memory=resources.memory,
disk_tier=resources.disk_tier)
if default_instance_type is None:
return resources_lib.FeasibleResources([], [], None)
return resources_utils.FeasibleResources([], [], None)
else:
return resources_lib.FeasibleResources(
return resources_utils.FeasibleResources(
_make([default_instance_type]), [], None)

assert len(accelerators) == 1, resources
Expand All @@ -227,9 +227,9 @@ def _make(instance_list):
zone=resources.zone,
clouds='lambda')
if instance_list is None:
return resources_lib.FeasibleResources([], fuzzy_candidate_list,
return resources_utils.FeasibleResources([], fuzzy_candidate_list,
None)
return resources_lib.FeasibleResources(_make(instance_list),
return resources_utils.FeasibleResources(_make(instance_list),
fuzzy_candidate_list, None)

@classmethod
Expand Down
Loading

0 comments on commit 4e7b21d

Please sign in to comment.