From 98df4b0ce2824fe56e08e912659eeca234fa4a0f Mon Sep 17 00:00:00 2001 From: Bihan Rana Date: Thu, 4 Apr 2024 12:16:13 +0545 Subject: [PATCH] Fix cudo provider offers too many combinations --- src/gpuhunt/providers/cudo.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/gpuhunt/providers/cudo.py b/src/gpuhunt/providers/cudo.py index 9759e1a..34a4415 100644 --- a/src/gpuhunt/providers/cudo.py +++ b/src/gpuhunt/providers/cudo.py @@ -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( @@ -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"])