From cf1906830e6369033505aaf0d07691f1af0e4521 Mon Sep 17 00:00:00 2001 From: Bihan Rana Date: Fri, 20 Dec 2024 22:44:15 +0545 Subject: [PATCH] Fix Review Issues For Add Vultr Support --- src/gpuhunt/providers/vultr.py | 176 ++-- src/tests/providers/test_vultr.py | 1528 ++--------------------------- 2 files changed, 183 insertions(+), 1521 deletions(-) diff --git a/src/gpuhunt/providers/vultr.py b/src/gpuhunt/providers/vultr.py index 3cc32a5..dba788e 100644 --- a/src/gpuhunt/providers/vultr.py +++ b/src/gpuhunt/providers/vultr.py @@ -23,45 +23,40 @@ def get( self, query_filter: Optional[QueryFilter] = None, balance_resources: bool = True ) -> list[RawCatalogItem]: offers = fetch_offers() - return sorted(offers, key=lambda i: i.price) if offers is not None else [] + return sorted(offers, key=lambda i: i.price) def fetch_offers() -> Optional[list[RawCatalogItem]]: """Fetch plans with types: 1. Cloud GPU (vcg), 2. Bare Metal (vbm), - 3. and others cpu plans, which includes: - Cloud Compute (vc2), - High Frequency Compute (vhf), - High Performance (vhp), - All optimized Cloud Types (voc)""" - try: - cloud_gpu_plans_response = _make_request("GET", "/plans?type=vcg") - bare_metal_plans_response = _make_request("GET", "/plans-metal") - other_plans_response = _make_request("GET", "/plans?type=all") - combined_response = { - "plans": ( - cloud_gpu_plans_response.json().get("plans", []) - + other_plans_response.json().get("plans", []) - ), - "plans_metal": bare_metal_plans_response.json().get("plans_metal", []), - } - return convert_response_to_raw_catalog_items(combined_response) - except requests.RequestException as e: - logger.error(f"Failed to fetch plans: {str(e)}") - return None + 3. and other CPU plans, including: + Cloud Compute (vc2), + High Frequency Compute (vhf), + High Performance (vhp), + All optimized Cloud Types (voc)""" + bare_metal_plans_response = _make_request("GET", "/plans-metal?per_page=500") + other_plans_response = _make_request("GET", "/plans?type=all&per_page=500") + return convert_response_to_raw_catalog_items(bare_metal_plans_response, other_plans_response) + + +def convert_response_to_raw_catalog_items( + bare_metal_plans_response: Response, other_plans_response: Response +) -> list[RawCatalogItem]: + catalog_items = [] + bare_metal_plans = bare_metal_plans_response.json()["plans_metal"] + other_plans = other_plans_response.json()["plans"] -def convert_response_to_raw_catalog_items(response: dict) -> list[RawCatalogItem]: - catalog_items = [] - plans = response.get("plans", []) + response.get("plans_metal", []) - - for plan in plans: - for location in plan.get("locations", []): - if plan in response.get("plans_metal", []): - catalog_item = get_bare_metal_plans(plan, location) - else: - catalog_item = get_instance_plans(plan, location) + for plan in bare_metal_plans: + for location in plan["locations"]: + catalog_item = get_bare_metal_plans(plan, location) + if catalog_item: + catalog_items.append(catalog_item) + + for plan in other_plans: + for location in plan["locations"]: + catalog_item = get_instance_plans(plan, location) if catalog_item: catalog_items.append(catalog_item) @@ -69,90 +64,103 @@ def convert_response_to_raw_catalog_items(response: dict) -> list[RawCatalogItem def get_bare_metal_plans(plan: dict, location: str) -> Optional[RawCatalogItem]: - gpu_name, gpu_count = extract_gpu_info_from_id(plan.get("id", "")) + gpu_name, gpu_count = extract_gpu_info_from_id(plan["id"]) if gpu_name in EXCLUSION_LIST: logger.info(f"Excluding plan with GPU {gpu_name} as it is not supported.") return None - gpu_memory = get_gpu_memory(gpu_name) * gpu_count if gpu_name else None + gpu_memory = get_gpu_memory(gpu_name) if gpu_name else None gpu_vendor = get_gpu_vendor(gpu_name) return RawCatalogItem( - instance_name=plan.get("id"), + instance_name=plan["id"], location=location, - price=round(plan.get("monthly_cost", 0) / 730, 2), - cpu=plan.get("cpu_count"), - memory=plan.get("ram", 0) / 1024, + price=round(plan["monthly_cost"] / 730, 2), + cpu=plan["cpu_count"], + memory=plan["ram"] / 1024, gpu_count=gpu_count, gpu_name=gpu_name, gpu_memory=gpu_memory, gpu_vendor=gpu_vendor, spot=False, - disk_size=plan.get("disk", 0), + disk_size=plan["disk"], ) def get_instance_plans(plan: dict, location: str) -> Optional[RawCatalogItem]: - plan_type = plan.get("type", "") + plan_type = plan["type"] if plan_type in ["vc2", "vhf", "vhp", "voc"]: return RawCatalogItem( - instance_name=plan.get("id"), + instance_name=plan["id"], location=location, - price=plan.get("hourly_cost", 0), - cpu=plan.get("vcpu_count"), - memory=plan.get("ram", 0) / 1024, + price=plan["hourly_cost"], + cpu=plan["vcpu_count"], + memory=plan["ram"] / 1024, gpu_count=0, gpu_name=None, gpu_memory=None, gpu_vendor=None, spot=False, - disk_size=plan.get("disk", 0), + disk_size=plan["disk"], ) elif plan_type == "vcg": - gpu_name = ( - plan.get("gpu_type", "").split("_")[1] if "_" in plan.get("gpu_type", "") else None - ) + gpu_name = plan["gpu_type"].split("_")[1] if "_" in plan["gpu_type"] else None if gpu_name in EXCLUSION_LIST: logger.info(f"Excluding plan with GPU {gpu_name} as it is not supported.") return None gpu_vendor = get_gpu_vendor(gpu_name) - gpu_memory_gb = plan.get("gpu_vram_gb", 0) + gpu_memory_gb = plan["gpu_vram_gb"] gpu_count = ( - max(1, gpu_memory_gb // get_gpu_memory(gpu_name)) if gpu_name else 0 + max(1, gpu_memory_gb // get_gpu_memory(gpu_name, gpu_memory_gb)) if gpu_name else 0 ) # For fractional GPU, # gpu_count=1 return RawCatalogItem( - instance_name=plan.get("id"), + instance_name=plan["id"], location=location, - price=plan.get("hourly_cost", 0), - cpu=plan.get("vcpu_count"), - memory=plan.get("ram", 0) / 1024, + price=plan["hourly_cost"], + cpu=plan["vcpu_count"], + memory=plan["ram"] / 1024, gpu_count=gpu_count, gpu_name=gpu_name, gpu_memory=gpu_memory_gb, gpu_vendor=gpu_vendor, spot=False, - disk_size=plan.get("disk", 0), + disk_size=plan["disk"], ) -def get_gpu_memory(gpu_name: str) -> float: +# def get_gpu_memory(gpu_name: str) -> float: +# for gpu in KNOWN_NVIDIA_GPUS: +# if gpu.name.upper() == gpu_name: +# return gpu.memory +# for gpu in KNOWN_AMD_GPUS: +# if gpu.name.upper() == gpu_name: +# return gpu.memory +# logger.error(f"GPU {gpu_name} not found in known GPU lists.") +# raise ValueError(f"GPU {gpu_name} not found.") +def get_gpu_memory(gpu_name: str, memory: Optional[int] = None) -> float: + if memory: + for gpu in KNOWN_NVIDIA_GPUS: + if gpu.name == gpu_name.upper() and gpu.memory == memory: + return gpu.memory + for gpu in KNOWN_NVIDIA_GPUS: - if gpu.name.upper() == gpu_name: + if gpu.name == gpu_name.upper(): return gpu.memory + for gpu in KNOWN_AMD_GPUS: - if gpu.name.upper() == gpu_name: + if gpu.name == gpu_name.upper() and (memory is None or gpu.memory == memory): return gpu.memory - logger.error(f"GPU {gpu_name} not found in known GPU lists.") - raise ValueError(f"GPU {gpu_name} not found.") + logger.error(f"GPU {gpu_name} with memory {memory} not found in known GPU lists.") + raise ValueError(f"GPU {gpu_name} with memory {memory} not found.") def get_gpu_vendor(gpu_name: Optional[str]) -> Optional[str]: if gpu_name is None: return None for gpu in KNOWN_NVIDIA_GPUS: - if gpu.name.upper() == gpu_name: + if gpu.name == gpu_name.upper(): return AcceleratorVendor.NVIDIA.value for gpu in KNOWN_AMD_GPUS: - if gpu.name.upper() == gpu_name: + if gpu.name == gpu_name.upper(): return AcceleratorVendor.AMD.value return None @@ -172,34 +180,18 @@ def extract_gpu_info_from_id(id_str: str): def _make_request(method: str, path: str, data: Any = None) -> Response: - try: - response = requests.request( - method=method, - url=API_URL + path, - json=data, - timeout=30, - ) - response.raise_for_status() - return response - - except requests.HTTPError as e: - status_code = e.response.status_code if e.response else None - if status_code == requests.codes.not_found: - logger.exception(f"Resource not found at {API_URL + path}.") - elif status_code == requests.codes.bad_request: - logger.exception( - f"Bad request to {API_URL + path}. Check the request payload or parameters." - ) - elif status_code == requests.codes.forbidden: - logger.exception(f"Access forbidden to {API_URL + path}. Check API permissions.") - elif status_code == requests.codes.unauthorized: - logger.exception( - f"Unauthorized access to {API_URL + path}. Check API key or authentication details." - ) - else: - logger.exception(f"HTTP error {status_code} occurred when accessing {API_URL + path}.") - - raise - except requests.RequestException as e: - logger.exception(f"Request error while accessing {API_URL + path}: {str(e)}") - raise + response = requests.request( + method=method, + url=API_URL + path, + json=data, + timeout=30, + ) + response.raise_for_status() + return response + + +# todo delete +vultr = VultrProvider() +# print(len(vultr.get())) +# print(vultr.get()) +print(get_gpu_memory("A100", 80)) diff --git a/src/tests/providers/test_vultr.py b/src/tests/providers/test_vultr.py index babc95e..be1e6fa 100644 --- a/src/tests/providers/test_vultr.py +++ b/src/tests/providers/test_vultr.py @@ -1,1441 +1,111 @@ -import pytest - import gpuhunt._internal.catalog as internal_catalog from gpuhunt import Catalog -from gpuhunt.providers.vultr import RawCatalogItem, VultrProvider +from gpuhunt.providers.vultr import VultrProvider, fetch_offers -# Sample mock return value -machine_types = [ - RawCatalogItem( - instance_name="vc2-1c-0.5gb-free", - location="sea", - price=0, - cpu=1, - memory=0.5, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=10, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-1c-1gb", - location="ewr", - price=0.007, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-1c-1gb", - location="ewr", - price=0.008, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=32, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-1gb-amd", - location="ewr", - price=0.008, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-1gb-intel", - location="ewr", - price=0.008, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-1c-1gb-sc1", - location="sao", - price=0.01, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-1c-1gb-sc1", - location="sao", - price=0.012, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=32, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-1gb-amd-sc1", - location="sao", - price=0.012, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-1gb-intel-sc1", - location="sao", - price=0.012, - cpu=1, - memory=1.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=25, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-1c-2gb", - location="ewr", - price=0.014, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=55, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-1c-2gb", - location="ewr", - price=0.016, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=64, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-2gb-amd", - location="ewr", - price=0.016, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=50, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-2gb-intel", - location="ewr", - price=0.016, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=50, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-1c-2gb-sc1", - location="sao", - price=0.021, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=55, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-2c-2gb", - location="ewr", - price=0.021, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=65, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-1c-2gb-sc1", - location="sao", - price=0.025, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=64, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-2c-2gb", - location="ewr", - price=0.025, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=80, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-2gb-amd-sc1", - location="sao", - price=0.025, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=50, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-2gb-amd", - location="ewr", - price=0.025, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=60, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-1c-2gb-intel-sc1", - location="sao", - price=0.025, - cpu=1, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=50, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-2gb-intel", - location="ewr", - price=0.025, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=60, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-2c-4gb", - location="ewr", - price=0.027, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=80, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-2c-2gb-sc1", - location="sao", - price=0.031, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=65, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-2c-4gb", - location="ewr", - price=0.033, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=128, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-4gb-amd", - location="ewr", - price=0.033, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=100, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-4gb-intel", - location="ewr", - price=0.033, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=100, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-2c-2gb-sc1", - location="sao", - price=0.037, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=80, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-2gb-amd-sc1", - location="sao", - price=0.037, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=60, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-2gb-intel-sc1", - location="sao", - price=0.037, - cpu=2, - memory=2.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=60, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-2c-4gb-sc1", - location="sao", - price=0.041, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=80, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-2c-4gb-sc1", - location="sao", - price=0.049, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=128, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-4gb-amd-sc1", - location="sao", - price=0.049, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=100, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-2c-4gb-intel-sc1", - location="sao", - price=0.049, - cpu=2, - memory=4.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=100, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-4c-8gb", - location="ewr", - price=0.055, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=160, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-2c-8g-2vram", - location="ewr", - price=0.059, - cpu=2, - memory=8.0, - gpu_count=0, - gpu_name="A16", - gpu_memory=2, - spot=False, - disk_size=50, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vhf-3c-8gb", - location="ewr", - price=0.066, - cpu=3, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=256, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-8gb-amd", - location="ewr", - price=0.066, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=180, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-8gb-intel", - location="ewr", - price=0.066, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=180, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-1c-5g-2vram", - location="ewr", - price=0.075, - cpu=1, - memory=5.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=2, - spot=False, - disk_size=90, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vc2-4c-8gb-sc1", - location="sao", - price=0.082, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=160, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-3c-8gb-sc1", - location="sao", - price=0.099, - cpu=3, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=256, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-8gb-amd-sc1", - location="sao", - price=0.099, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=180, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-12gb-amd", - location="ewr", - price=0.099, - cpu=4, - memory=12.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=260, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-8gb-intel-sc1", - location="sao", - price=0.099, - cpu=4, - memory=8.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=180, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-12gb-intel", - location="ewr", - price=0.099, - cpu=4, - memory=12.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=260, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-6c-16gb", - location="ewr", - price=0.11, - cpu=6, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=320, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-2c-16g-4vram", - location="ewr", - price=0.118, - cpu=2, - memory=16.0, - gpu_count=0, - gpu_name="A16", - gpu_memory=4, - spot=False, - disk_size=80, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a100-1c-6g-4vram", - location="ewr", - price=0.123, - cpu=1, - memory=6.0, - gpu_count=0, - gpu_name="A100", - gpu_memory=4, - spot=False, - disk_size=70, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vhf-4c-16gb", - location="ewr", - price=0.132, - cpu=4, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=384, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-8c-16gb-amd", - location="ewr", - price=0.132, - cpu=8, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=350, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-8c-16gb-intel", - location="ewr", - price=0.132, - cpu=8, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=350, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-2c-10g-4vram", - location="ewr", - price=0.144, - cpu=2, - memory=10.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=4, - spot=False, - disk_size=180, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vhp-4c-12gb-amd-sc1", - location="sao", - price=0.148, - cpu=4, - memory=12.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=260, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-4c-12gb-intel-sc1", - location="sao", - price=0.148, - cpu=4, - memory=12.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=260, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vbm-4c-32gb", - location="ewr", - price=0.16, - cpu=4, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=240, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-6c-16gb-sc1", - location="sao", - price=0.164, - cpu=6, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=320, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-4c-16gb-sc1", - location="sao", - price=0.197, - cpu=4, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=384, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-6c-24gb", - location="ewr", - price=0.197, - cpu=6, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=448, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-8c-16gb-amd-sc1", - location="sao", - price=0.197, - cpu=8, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=350, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-12c-24gb-amd", - location="ewr", - price=0.197, - cpu=12, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=500, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-8c-16gb-intel-sc1", - location="sao", - price=0.197, - cpu=8, - memory=16.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=350, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-12c-24gb-intel", - location="ewr", - price=0.197, - cpu=12, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=500, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-8c-32gb", - location="ewr", - price=0.219, - cpu=8, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=640, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-3c-32g-8vram", - location="ewr", - price=0.236, - cpu=3, - memory=32.0, - gpu_count=0, - gpu_name="A16", - gpu_memory=8, - spot=False, - disk_size=170, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a100-1c-12g-8vram", - location="ewr", - price=0.247, - cpu=1, - memory=12.0, - gpu_count=0, - gpu_name="A100", - gpu_memory=8, - spot=False, - disk_size=140, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-6c-32gb", - location="ewr", - price=0.25, - cpu=6, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=960, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-8c-32gb", - location="ewr", - price=0.263, - cpu=8, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=512, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-4c-20g-8vram", - location="ewr", - price=0.288, - cpu=4, - memory=20.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=8, - spot=False, - disk_size=360, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vhf-6c-24gb-sc1", - location="sao", - price=0.296, - cpu=6, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=448, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-12c-24gb-amd-sc1", - location="sao", - price=0.296, - cpu=12, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=500, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhp-12c-24gb-intel-sc1", - location="sao", - price=0.296, - cpu=12, - memory=24.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=500, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vc2-8c-32gb-sc1", - location="sao", - price=0.329, - cpu=8, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=640, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a100-2c-15g-10vram", - location="ewr", - price=0.342, - cpu=2, - memory=15.0, - gpu_count=0, - gpu_name="A100", - gpu_memory=10, - spot=False, - disk_size=170, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vhf-12c-48gb", - location="ewr", - price=0.351, - cpu=12, - memory=48.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=768, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-8c-32gb-sc1", - location="sao", - price=0.395, - cpu=8, - memory=32.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=512, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-6c-30g-12vram", - location="ewr", - price=0.432, - cpu=6, - memory=30.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=12, - spot=False, - disk_size=550, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vc2-16c-64gb", - location="ewr", - price=0.438, - cpu=16, - memory=64.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1280, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vhf-16c-58gb", - location="ewr", - price=0.438, - cpu=16, - memory=58.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1024, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-6c-64g-16vram", - location="ewr", - price=0.471, - cpu=6, - memory=64.0, - gpu_count=1, - gpu_name="A16", - gpu_memory=16, - spot=False, - disk_size=350, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-8c-132gb", - location="ewr", - price=0.48, - cpu=8, - memory=128.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1920, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vbm-8c-132gb-v2", - location="ewr", - price=0.48, - cpu=8, - memory=128.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1920, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-8c-40g-16vram", - location="lax", - price=0.575, - cpu=8, - memory=40.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=16, - spot=False, - disk_size=740, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a100-3c-30g-20vram", - location="ewr", - price=0.616, - cpu=3, - memory=30.0, - gpu_count=0, - gpu_name="A100", - gpu_memory=20, - spot=False, - disk_size=700, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vc2-16c-64gb-sc1", - location="sao", - price=0.658, - cpu=16, - memory=64.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1280, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a40-12c-60g-24vram", - location="lax", - price=0.856, - cpu=12, - memory=60.0, - gpu_count=0, - gpu_name="A40", - gpu_memory=24, - spot=False, - disk_size=1110, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vc2-24c-96gb", - location="ewr", - price=0.877, - cpu=24, - memory=96.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1600, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-12c-128g-32vram", - location="ewr", - price=0.942, - cpu=12, - memory=128.0, - gpu_count=2, - gpu_name="A16", - gpu_memory=32, - spot=False, - disk_size=700, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-24c-256gb-amd", - location="ewr", - price=0.99, - cpu=24, - memory=256.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=480, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vbm-24c-384gb-amd", - location="sea", - price=1.13, - cpu=24, - memory=384.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=480, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a100-6c-60g-40vram", - location="ewr", - price=1.199, - cpu=6, - memory=60.0, - gpu_count=1, - gpu_name="A100", - gpu_memory=40, - spot=False, - disk_size=1400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vc2-24c-96gb-sc1", - location="sao", - price=1.315, - cpu=24, - memory=96.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=1600, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-l40s-16c-180g-48vram", - location="ewr", - price=1.671, - cpu=16, - memory=180.0, - gpu_count=1, - gpu_name="L40S", - gpu_memory=48, - spot=False, - disk_size=1200, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a40-24c-120g-48vram", - location="lax", - price=1.712, - cpu=24, - memory=120.0, - gpu_count=1, - gpu_name="A40", - gpu_memory=48, - spot=False, - disk_size=1400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a16-24c-256g-64vram", - location="ewr", - price=1.884, - cpu=24, - memory=256.0, - gpu_count=4, - gpu_name="A16", - gpu_memory=64, - spot=False, - disk_size=1200, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-32c-755gb-amd", - location="atl", - price=1.99, - cpu=32, - memory=768.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=480, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a100-12c-120g-80vram", - location="ewr", - price=2.397, - cpu=12, - memory=120.0, - gpu_count=2, - gpu_name="A100", - gpu_memory=80, - spot=False, - disk_size=1400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-l40s-32c-375g-96vram", - location="ewr", - price=3.342, - cpu=32, - memory=375.0, - gpu_count=2, - gpu_name="L40S", - gpu_memory=96, - spot=False, - disk_size=2200, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a16-48c-496g-128vram", - location="ewr", - price=3.767, - cpu=48, - memory=496.0, - gpu_count=8, - gpu_name="A16", - gpu_memory=128, - spot=False, - disk_size=1500, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a100-24c-240g-160vram", - location="ewr", - price=4.795, - cpu=24, - memory=240.0, - gpu_count=4, - gpu_name="A100", - gpu_memory=160, - spot=False, - disk_size=1400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-l40s-64c-750g-192vram", - location="ewr", - price=6.684, - cpu=64, - memory=750.0, - gpu_count=4, - gpu_name="L40S", - gpu_memory=192, - spot=False, - disk_size=2600, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-128c-2048gb-amd", - location="fra", - price=7.53, - cpu=128, - memory=2048.0, - gpu_count=0, - gpu_name=None, - gpu_memory=None, - spot=False, - disk_size=480, - gpu_vendor=None, - ), - RawCatalogItem( - instance_name="vcg-a16-96c-960g-256vram", - location="lhr", - price=7.534, - cpu=96, - memory=960.0, - gpu_count=16, - gpu_name="A16", - gpu_memory=256, - spot=False, - disk_size=1700, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-a100-48c-480g-320vram", - location="ewr", - price=9.589, - cpu=48, - memory=480.0, - gpu_count=8, - gpu_name="A100", - gpu_memory=320, - spot=False, - disk_size=1400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-48c-1024gb-4-a100-gpu", - location="ewr", - price=9.59, - cpu=48, - memory=1024.0, - gpu_count=4, - gpu_name="A100", - gpu_memory=160, - spot=False, - disk_size=450, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vcg-l40s-128c-1500g-384vram", - location="ewr", - price=13.368, - cpu=128, - memory=1500.0, - gpu_count=8, - gpu_name="L40S", - gpu_memory=384, - spot=False, - disk_size=3400, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-256c-2048gb-8-mi300x-gpu", - location="ord", - price=16.13, - cpu=128, - memory=2267.50390625, - gpu_count=8, - gpu_name="MI300X", - gpu_memory=1536, - spot=False, - disk_size=3576, - gpu_vendor="amd", - ), - RawCatalogItem( - instance_name="vbm-64c-2048gb-8-l40-gpu", - location="ewr", - price=16.44, - cpu=64, - memory=2048.0, - gpu_count=8, - gpu_name="L40", - gpu_memory=384, - spot=False, - disk_size=480, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-112c-2048gb-8-a100-gpu", - location="atl", - price=20.62, - cpu=112, - memory=2048.0, - gpu_count=8, - gpu_name="A100", - gpu_memory=320, - spot=False, - disk_size=960, - gpu_vendor="nvidia", - ), - RawCatalogItem( - instance_name="vbm-112c-2048gb-8-h100-gpu", - location="sea", - price=22.02, - cpu=112, - memory=2048.0, - gpu_count=8, - gpu_name="H100", - gpu_memory=640, - spot=False, - disk_size=960, - gpu_vendor="nvidia", - ), -] +bare_metal = { + "plans_metal": [ + { + "id": "vbm-256c-2048gb-8-mi300x-gpu", + "physical_cpus": 2, + "cpu_count": 128, + "cpu_cores": 128, + "cpu_threads": 256, + "cpu_model": "EPYC 9534", + "cpu_mhz": 2450, + "ram": 2321924, + "disk": 3576, + "disk_count": 8, + "bandwidth": 10240, + "monthly_cost": 11773.44, + "hourly_cost": 17.52, + "monthly_cost_preemptible": 9891.84, + "hourly_cost_preemptible": 14.72, + "type": "NVMe", + "locations": ["ord"], + }, + { + "id": "vbm-112c-2048gb-8-h100-gpu", + "physical_cpus": 2, + "cpu_count": 112, + "cpu_cores": 112, + "cpu_threads": 224, + "cpu_model": "Platinum 8480+", + "cpu_mhz": 2000, + "ram": 2097152, + "disk": 960, + "disk_count": 2, + "bandwidth": 15360, + "monthly_cost": 16074.24, + "hourly_cost": 23.92, + "monthly_cost_preemptible": 12364.8, + "hourly_cost_preemptible": 18.4, + "type": "NVMe", + "locations": ["sea"], + }, + ] +} +vm_instances = { + "plans": [ + { + "id": "vcg-a100-1c-6g-4vram", + "vcpu_count": 1, + "ram": 6144, + "disk": 70, + "disk_count": 1, + "bandwidth": 1024, + "monthly_cost": 90, + "hourly_cost": 0.123, + "type": "vcg", + "locations": ["ewr"], + "gpu_vram_gb": 4, + "gpu_type": "NVIDIA_A100", + }, + { + "id": "vcg-a100-12c-120g-80vram", + "vcpu_count": 12, + "ram": 122880, + "disk": 1400, + "disk_count": 1, + "bandwidth": 10240, + "monthly_cost": 1750, + "hourly_cost": 2.397, + "type": "vcg", + "locations": ["ewr"], + "gpu_vram_gb": 80, + "gpu_type": "NVIDIA_A100", + }, + { + "id": "vcg-a100-6c-60g-40vram", + "vcpu_count": 12, + "ram": 61440, + "disk": 1400, + "disk_count": 1, + "bandwidth": 10240, + "monthly_cost": 800, + "hourly_cost": 1.397, + "type": "vcg", + "locations": ["ewr"], + "gpu_vram_gb": 40, + "gpu_type": "NVIDIA_A100", + }, + ] +} -@pytest.fixture -def mock_fetch_offers(mocker): - return mocker.patch("gpuhunt.providers.vultr.fetch_offers", return_value=machine_types) +def test_fetch_offers(requests_mock): + # Mocking the responses for the API endpoints + requests_mock.get("https://api.vultr.com/v2/plans-metal?per_page=500", json=bare_metal) + requests_mock.get("https://api.vultr.com/v2/plans?type=all&per_page=500", json=vm_instances) -def test_vultr_provider_get(mock_fetch_offers): + # Fetch offers and verify results + assert len(fetch_offers()) == 5 catalog = Catalog(balance_resources=False, auto_reload=False) vultr = VultrProvider() internal_catalog.ONLINE_PROVIDERS = ["vultr"] internal_catalog.OFFLINE_PROVIDERS = [] catalog.add_provider(vultr) - query_result = catalog.query(provider=["vultr"], min_gpu_count=2, max_gpu_count=4) - assert len(query_result) >= 1, "No offers found" + assert len(catalog.query(provider=["vultr"], min_gpu_count=1, max_gpu_count=1)) == 3 + assert len(catalog.query(provider=["vultr"], min_gpu_memory=80, max_gpu_count=1)) == 1 + assert len(catalog.query(provider=["vultr"], gpu_vendor="amd")) == 1 + assert len(catalog.query(provider=["vultr"], gpu_name="MI300X")) == 1