| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- import json
- import os
- from typing import Optional
- from gpustack.schemas.workers import (
- GPUDeviceStatus,
- MemoryInfo,
- SystemReserved,
- Worker,
- WorkerStatus,
- )
- def macos_metal_1_m1pro_21g(
- reserved=False,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with a M1 Pro GPU device with 21GB of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "macos_metal_1_m1pro_21g.json", reserved=reserved, return_devices=return_device
- )
- if callback:
- callback(worker)
- return worker
- def macos_metal_2_m2_24g(
- reserved=True,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with a M2 GPU device with 24GB (actual allocatable 16GB) of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "macos_metal_2_m2_24g.json", reserved=reserved, return_devices=return_device
- )
- if callback:
- callback(worker)
- return worker
- def macos_metal_3_m2ultra_192g(
- reserved=True,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with a M2 Ultra GPU device with 192GB (actual allocatable 187GB) of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "macos_metal_3_m2ultra_192g.json",
- reserved=reserved,
- return_devices=return_device,
- )
- if callback:
- callback(worker)
- return worker
- def linux_ascend_1_910b_64gx8(
- reserved=False,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "linux_ascend_1_910b_64gx8.json",
- reserved=reserved,
- return_devices=return_device,
- )
- if callback:
- callback(worker)
- return worker
- def linux_ascend_2_910b_64gx8(
- reserved=False,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "linux_ascend_2_910b_64gx8.json",
- reserved=reserved,
- return_devices=return_device,
- )
- if callback:
- callback(worker)
- return worker
- def linux_ascend_3_910b_64gx8(
- reserved=False,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "linux_ascend_3_910b_64gx8.json",
- reserved=reserved,
- return_devices=return_device,
- )
- if callback:
- callback(worker)
- return worker
- def linux_ascend_4_910b_64gx8(
- reserved=False,
- return_device: Optional[int] = None,
- callback=None,
- ):
- """
- Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
- :param reserved: If True, the worker will have reserved system resources.
- :param return_device: The number of devices to return.
- :param callback: A callback function to be executed after loading the worker.
- :return: Worker object with the specified configuration.
- """
- worker = load_from_file(
- "linux_ascend_4_910b_64gx8.json",
- reserved=reserved,
- return_devices=return_device,
- )
- if callback:
- callback(worker)
- return worker
- def linux_nvidia_0_4090_24gx1(reserved=False):
- return load_from_file("linux_nvidia_0_4090_24gx1.json", reserved=reserved)
- def linux_nvidia_1_4090_24gx1(reserved=False):
- return load_from_file("linux_nvidia_1_4090_24gx1.json", reserved=reserved)
- def linux_nvidia_3_4090_24gx1(reserved=True):
- return load_from_file("linux_nvidia_3_4090_24gx1.json", reserved=reserved)
- def linux_nvidia_2_4080_16gx2(reserved=False):
- return load_from_file("linux_nvidia_2_4080_16gx2.json", reserved=reserved)
- def linux_nvidia_4_4080_16gx4(reserved=False):
- return load_from_file("linux_nvidia_4_4080_16gx4.json", reserved=reserved)
- def linux_nvidia_5_a100_80gx2(reserved=True):
- return load_from_file("linux_nvidia_5_A100_80gx2.json", reserved=reserved)
- def linux_nvidia_6_a100_80gx2(reserved=True):
- return load_from_file("linux_nvidia_6_A100_80gx2.json", reserved=reserved)
- def linux_nvidia_7_a100_80gx2(reserved=True):
- return load_from_file("linux_nvidia_7_A100_80gx2.json", reserved=reserved)
- def linux_nvidia_8_3090_24gx8(reserved=True):
- return load_from_file("linux_nvidia_8_3090_24gx8.json", reserved=reserved)
- def linux_nvidia_9_3090_24gx8(reserved=True):
- return load_from_file("linux_nvidia_9_3090_24gx8.json", reserved=reserved)
- def linux_nvidia_10_3090_24gx8(reserved=True):
- return load_from_file("linux_nvidia_10_3090_24gx8.json", reserved=reserved)
- def linux_nvidia_11_V100_32gx2(reserved=True):
- return load_from_file("linux_nvidia_11_V100_32gx2.json", reserved=reserved)
- def linux_nvidia_12_A40_48gx2(reserved=True):
- return load_from_file("linux_nvidia_12_A40_48gx2.json", reserved=reserved)
- def linux_nvidia_13_A100_80gx8(reserved=True):
- return load_from_file("linux_nvidia_13_A100_80gx8.json", reserved=reserved)
- def linux_nvidia_14_A100_40gx2(reserved=True):
- return load_from_file("linux_nvidia_14_A100_40gx2.json", reserved=reserved)
- def linux_nvidia_15_4080_16gx8(reserved=True):
- return load_from_file("linux_nvidia_15_4080_16gx8.json", reserved=reserved)
- def linux_nvidia_16_5000_16gx8(reserved=True):
- return load_from_file("linux_nvidia_16_5000_16gx8.json", reserved=reserved)
- def linux_nvidia_17_4090_24gx8(reserved=True):
- return load_from_file("linux_nvidia_17_4090_24gx8.json", reserved=reserved)
- def linux_nvidia_18_4090_24gx4_4080_16gx4(reserved=True):
- return load_from_file(
- "linux_nvidia_18_4090_24gx4_4080_16gx4.json", reserved=reserved
- )
- def linux_nvidia_19_4090_24gx2(reserved=False):
- return load_from_file("linux_nvidia_19_4090_24gx2.json", reserved=reserved)
- def linux_nvidia_20_3080_12gx8(reserved=False):
- return load_from_file("linux_nvidia_20_3080_12gx8.json", reserved=reserved)
- def linux_nvidia_21_4090_24gx4_3060_12gx4(reserved=False):
- return load_from_file(
- "linux_nvidia_21_4090_24gx4_3060_12gx4.json", reserved=reserved
- )
- def linux_nvidia_22_H100_80gx8(reserved=False):
- return load_from_file("linux_nvidia_22_H100_80gx8.json", reserved=reserved)
- def linux_nvidia_23_H100_80gx8(reserved=False):
- return load_from_file("linux_nvidia_23_H100_80gx8.json", reserved=reserved)
- def linux_nvidia_24_H100_80gx8(reserved=False):
- return load_from_file("linux_nvidia_24_H100_80gx8.json", reserved=reserved)
- def linux_nvidia_25_H100_80gx8(reserved=False):
- return load_from_file("linux_nvidia_25_H100_80gx8.json", reserved=reserved)
- def linux_nvidia_26_H200_141gx8(reserved=False):
- return load_from_file("linux_nvidia_26_H200_141gx8.json", reserved=reserved)
- def linux_rocm_1_7800_16gx1(reserved=True):
- return load_from_file("linux_rocm_1_7800_16gx1.json", reserved=reserved)
- def linux_rocm_2_7800_16gx2(reserved=True):
- return load_from_file("linux_rocm_2_7800_16gx2.json", reserved=reserved)
- def linux_cpu_1(reserved=False):
- return load_from_file("linux_cpu_1.json", reserved=reserved)
- def linux_cpu_2(reserved=False):
- return load_from_file("linux_cpu_2.json", reserved=reserved)
- def linux_cpu_3(reserved=False):
- return load_from_file("linux_cpu_3.json", reserved=reserved)
- def linux_mix_1_nvidia_4080_16gx1_rocm_7800_16gx1(reserved=False):
- return load_from_file(
- "linux_mix_1_nvidia_4080_16gx1_rocm_7800_16gx1.json", reserved=reserved
- )
- def load_from_file(
- file_name, reserved=False, return_devices: Optional[int] = None
- ) -> Worker:
- dir = os.path.dirname(__file__)
- file_path = os.path.join(dir, file_name)
- with open(file_path, 'r') as file:
- dict = json.loads(file.read())
- status_dict = dict.get("status")
- memory = status_dict.get("memory")
- gpu_devices = status_dict.get("gpu_devices")
- status = WorkerStatus(**status_dict)
- status.memory = MemoryInfo(**memory)
- if gpu_devices:
- status.gpu_devices = [GPUDeviceStatus(**device) for device in gpu_devices]
- worker = Worker(**dict)
- worker.status = status
- worker.system_reserved = SystemReserved(ram=0, vram=0)
- if reserved:
- system_reserved_dict = dict.get("system_reserved")
- system_reserved = SystemReserved(
- ram=system_reserved_dict.get("memory")
- or system_reserved_dict.get("ram")
- or 0,
- vram=system_reserved_dict.get("gpu_memory")
- or system_reserved_dict.get("vram")
- or 0,
- )
- worker.system_reserved = system_reserved
- if return_devices is not None:
- worker.status.gpu_devices = worker.status.gpu_devices[
- : max(0, min(return_devices, len(worker.status.gpu_devices)))
- ]
- return worker
|