Skip to content

Commit

Permalink
Fix cudo provider offers too many combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bihan Rana authored and Bihan Rana committed Apr 4, 2024
1 parent 219c952 commit 98df4b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/gpuhunt/providers/cudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get(
self, query_filter: Optional[QueryFilter] = None, balance_resources: bool = True
) -> List[RawCatalogItem]:
offers = self.fetch_offers(query_filter, balance_resources)
offers = get_min_price_for_location_and_instance(offers)
return sorted(offers, key=lambda i: i.price)

def fetch_offers(
Expand Down Expand Up @@ -167,6 +168,19 @@ def get_raw_catalog(machine_type, spec):
return raw


def get_min_price_for_location_and_instance(offers: List[RawCatalogItem]) -> List[RawCatalogItem]:
"""
Returns offers with the minimum price for each unique combination
of location and instance name.
"""
min_price_offers = {}
for offer in offers:
key = (offer.location, offer.instance_name)
if key not in min_price_offers or offer.price < min_price_offers[key].price:
min_price_offers[key] = offer
return list(min_price_offers.values())


def optimize_offers_with_gpu(q: QueryFilter, machine_type, balance_resources):
# Generate ranges for CPU, GPU, and memory based on the specified minimums, maximums, and available resources
cpu_range = get_cpu_range(q.min_cpu, q.max_cpu, machine_type["maxVcpuFree"])
Expand Down

0 comments on commit 98df4b0

Please sign in to comment.