From dc45da6677bc5efff528708cef4808af6b03be28 Mon Sep 17 00:00:00 2001 From: Bihan Rana Date: Mon, 26 Feb 2024 21:59:35 +0545 Subject: [PATCH] Use cudo provider without credentials (#39) * Add CudoCompute provider Added cudocompute in OFFLINE PROVIDERS Removed dist directory Cudocompute disksize set to None * Fixed Review Issues and Added Integrity Tests for Cudo * Bump checkout action from v3 to v4 for cudo * Adjust Spacing With Pre-Commit for Cudo * Remove cudo-compute python client --------- Co-authored-by: Bihan Rana --- .github/workflows/catalogs.yml | 41 +++++++++++++++------------------- pyproject.toml | 5 +---- src/gpuhunt/providers/cudo.py | 34 +++++++++++++++++----------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/catalogs.yml b/.github/workflows/catalogs.yml index 536ea1f..76224aa 100644 --- a/.github/workflows/catalogs.yml +++ b/.github/workflows/catalogs.yml @@ -63,6 +63,23 @@ jobs: path: azure.csv retention-days: 1 + catalog-cudo: + name: Collect Cudo catalog + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Collect catalog + working-directory: src + run: python -m gpuhunt cudo --output ../cudo.csv + - uses: actions/upload-artifact@v4 + with: + name: catalogs-cudo + path: cudo.csv + retention-days: 1 + catalog-datacrunch: name: Collect DataCrunch catalog runs-on: ubuntu-latest @@ -87,7 +104,6 @@ jobs: path: datacrunch.csv retention-days: 1 - catalog-gcp: name: Collect GCP catalog runs-on: ubuntu-latest @@ -168,37 +184,16 @@ jobs: path: nebius.csv retention-days: 1 - catalog-cudo: - name: Collect Cudo catalog - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: 3.11 - - name: Install dependencies - run: | - pip install pip -U - pip install -e '.[cudo]' - - name: Collect catalog - working-directory: src - run: python -m gpuhunt cudo --output ../cudo.csv - - uses: actions/upload-artifact@v4 - with: - name: catalogs-cudo - path: cudo.csv - retention-days: 1 - test-catalog: name: Test catalogs integrity needs: - catalog-aws - catalog-azure + - catalog-cudo - catalog-datacrunch - catalog-gcp - catalog-lambdalabs - catalog-nebius - - catalog-cudo runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/pyproject.toml b/pyproject.toml index 7a9645f..9d9a35f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,10 +46,7 @@ nebius = [ datacrunch = [ "datacrunch" ] -cudo = [ - "cudo_compute" -] -all = ["gpuhunt[aws,azure,cudo,datacrunch,gcp,nebius]"] +all = ["gpuhunt[aws,azure,datacrunch,gcp,nebius]"] dev = [ "pre-commit", "isort~=5.0", diff --git a/src/gpuhunt/providers/cudo.py b/src/gpuhunt/providers/cudo.py index f937ac0..fd1272f 100644 --- a/src/gpuhunt/providers/cudo.py +++ b/src/gpuhunt/providers/cudo.py @@ -4,7 +4,7 @@ from itertools import chain from typing import List, Optional -from cudo_compute import cudo_api +import requests from gpuhunt import QueryFilter, RawCatalogItem from gpuhunt._internal.constraints import KNOWN_GPUS @@ -13,6 +13,8 @@ CpuMemoryGpu = namedtuple("CpuMemoryGpu", ["cpu", "memory", "gpu"]) logger = logging.getLogger(__name__) +API_URL = "https://rest.compute.cudo.org/v1" + class CudoProvider(AbstractProvider): NAME = "cudo" @@ -42,19 +44,17 @@ def fetch_all_vm_types(self): def get_raw_catalog_list(self, vm_machine_type_list, vcpu, memory, gpu): raw_list = [] - for vm in vm_machine_type_list.host_configs: + for vm in vm_machine_type_list: raw = RawCatalogItem( - instance_name=vm.machine_type, - location=vm.data_center_id, + instance_name=vm["machineType"], + location=vm["dataCenterId"], spot=False, - price=round( - (float(vm.total_price_hr.value) + float(vm.storage_gib_price_hr.value)), 5 - ), + price=round(float(vm["totalPriceHr"]["value"]), 5), cpu=vcpu, memory=memory, gpu_count=gpu, - gpu_name=gpu_name(vm.gpu_model), - gpu_memory=get_memory(gpu_name(vm.gpu_model)), + gpu_name=vm["gpuModel"], + gpu_memory=get_memory(gpu_name(vm["gpuModel"])), disk_size=None, ) raw_list.append(raw) @@ -62,13 +62,21 @@ def get_raw_catalog_list(self, vm_machine_type_list, vcpu, memory, gpu): def fetch_vm_type(self, vcpu, memory_gib, gpu): try: - result = cudo_api.virtual_machines().list_vm_machine_types( - vcpu=vcpu, memory_gib=memory_gib, gpu=gpu - ) + result = self._list_vm_machine_types(vcpu, memory_gib, gpu) return self.get_raw_catalog_list(result, vcpu, memory_gib, gpu) - except Exception as e: + except requests.HTTPError as e: raise VMTypeFetchError(f"Failed to fetch VM type: {e}", vcpu, memory_gib, gpu) + def _list_vm_machine_types(self, vcpu, memory_gib, gpu): + resp = requests.request( + method="GET", + url=f"{API_URL}/vms/machine-types?vcpu={vcpu}&memory_gib={memory_gib}&gpu={gpu}", + ) + if resp.ok: + data = resp.json() + return data["hostConfigs"] + resp.raise_for_status() + class VMTypeFetchError(Exception): def __init__(self, message, vcpu, memory_gib, gpu):