fixtures.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. import json
  2. import os
  3. from typing import Optional
  4. from gpustack.schemas.workers import (
  5. GPUDeviceStatus,
  6. MemoryInfo,
  7. SystemReserved,
  8. Worker,
  9. WorkerStatus,
  10. )
  11. def macos_metal_1_m1pro_21g(
  12. reserved=False,
  13. return_device: Optional[int] = None,
  14. callback=None,
  15. ):
  16. """
  17. Return a worker with a M1 Pro GPU device with 21GB of memory.
  18. :param reserved: If True, the worker will have reserved system resources.
  19. :param return_device: The number of devices to return.
  20. :param callback: A callback function to be executed after loading the worker.
  21. :return: Worker object with the specified configuration.
  22. """
  23. worker = load_from_file(
  24. "macos_metal_1_m1pro_21g.json", reserved=reserved, return_devices=return_device
  25. )
  26. if callback:
  27. callback(worker)
  28. return worker
  29. def macos_metal_2_m2_24g(
  30. reserved=True,
  31. return_device: Optional[int] = None,
  32. callback=None,
  33. ):
  34. """
  35. Return a worker with a M2 GPU device with 24GB (actual allocatable 16GB) of memory.
  36. :param reserved: If True, the worker will have reserved system resources.
  37. :param return_device: The number of devices to return.
  38. :param callback: A callback function to be executed after loading the worker.
  39. :return: Worker object with the specified configuration.
  40. """
  41. worker = load_from_file(
  42. "macos_metal_2_m2_24g.json", reserved=reserved, return_devices=return_device
  43. )
  44. if callback:
  45. callback(worker)
  46. return worker
  47. def macos_metal_3_m2ultra_192g(
  48. reserved=True,
  49. return_device: Optional[int] = None,
  50. callback=None,
  51. ):
  52. """
  53. Return a worker with a M2 Ultra GPU device with 192GB (actual allocatable 187GB) of memory.
  54. :param reserved: If True, the worker will have reserved system resources.
  55. :param return_device: The number of devices to return.
  56. :param callback: A callback function to be executed after loading the worker.
  57. :return: Worker object with the specified configuration.
  58. """
  59. worker = load_from_file(
  60. "macos_metal_3_m2ultra_192g.json",
  61. reserved=reserved,
  62. return_devices=return_device,
  63. )
  64. if callback:
  65. callback(worker)
  66. return worker
  67. def linux_ascend_1_910b_64gx8(
  68. reserved=False,
  69. return_device: Optional[int] = None,
  70. callback=None,
  71. ):
  72. """
  73. Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
  74. :param reserved: If True, the worker will have reserved system resources.
  75. :param return_device: The number of devices to return.
  76. :param callback: A callback function to be executed after loading the worker.
  77. :return: Worker object with the specified configuration.
  78. """
  79. worker = load_from_file(
  80. "linux_ascend_1_910b_64gx8.json",
  81. reserved=reserved,
  82. return_devices=return_device,
  83. )
  84. if callback:
  85. callback(worker)
  86. return worker
  87. def linux_ascend_2_910b_64gx8(
  88. reserved=False,
  89. return_device: Optional[int] = None,
  90. callback=None,
  91. ):
  92. """
  93. Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
  94. :param reserved: If True, the worker will have reserved system resources.
  95. :param return_device: The number of devices to return.
  96. :param callback: A callback function to be executed after loading the worker.
  97. :return: Worker object with the specified configuration.
  98. """
  99. worker = load_from_file(
  100. "linux_ascend_2_910b_64gx8.json",
  101. reserved=reserved,
  102. return_devices=return_device,
  103. )
  104. if callback:
  105. callback(worker)
  106. return worker
  107. def linux_ascend_3_910b_64gx8(
  108. reserved=False,
  109. return_device: Optional[int] = None,
  110. callback=None,
  111. ):
  112. """
  113. Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
  114. :param reserved: If True, the worker will have reserved system resources.
  115. :param return_device: The number of devices to return.
  116. :param callback: A callback function to be executed after loading the worker.
  117. :return: Worker object with the specified configuration.
  118. """
  119. worker = load_from_file(
  120. "linux_ascend_3_910b_64gx8.json",
  121. reserved=reserved,
  122. return_devices=return_device,
  123. )
  124. if callback:
  125. callback(worker)
  126. return worker
  127. def linux_ascend_4_910b_64gx8(
  128. reserved=False,
  129. return_device: Optional[int] = None,
  130. callback=None,
  131. ):
  132. """
  133. Return a worker with 8 Ascend 910B devices, each with 64GB of memory.
  134. :param reserved: If True, the worker will have reserved system resources.
  135. :param return_device: The number of devices to return.
  136. :param callback: A callback function to be executed after loading the worker.
  137. :return: Worker object with the specified configuration.
  138. """
  139. worker = load_from_file(
  140. "linux_ascend_4_910b_64gx8.json",
  141. reserved=reserved,
  142. return_devices=return_device,
  143. )
  144. if callback:
  145. callback(worker)
  146. return worker
  147. def linux_nvidia_0_4090_24gx1(reserved=False):
  148. return load_from_file("linux_nvidia_0_4090_24gx1.json", reserved=reserved)
  149. def linux_nvidia_1_4090_24gx1(reserved=False):
  150. return load_from_file("linux_nvidia_1_4090_24gx1.json", reserved=reserved)
  151. def linux_nvidia_3_4090_24gx1(reserved=True):
  152. return load_from_file("linux_nvidia_3_4090_24gx1.json", reserved=reserved)
  153. def linux_nvidia_2_4080_16gx2(reserved=False):
  154. return load_from_file("linux_nvidia_2_4080_16gx2.json", reserved=reserved)
  155. def linux_nvidia_4_4080_16gx4(reserved=False):
  156. return load_from_file("linux_nvidia_4_4080_16gx4.json", reserved=reserved)
  157. def linux_nvidia_5_a100_80gx2(reserved=True):
  158. return load_from_file("linux_nvidia_5_A100_80gx2.json", reserved=reserved)
  159. def linux_nvidia_6_a100_80gx2(reserved=True):
  160. return load_from_file("linux_nvidia_6_A100_80gx2.json", reserved=reserved)
  161. def linux_nvidia_7_a100_80gx2(reserved=True):
  162. return load_from_file("linux_nvidia_7_A100_80gx2.json", reserved=reserved)
  163. def linux_nvidia_8_3090_24gx8(reserved=True):
  164. return load_from_file("linux_nvidia_8_3090_24gx8.json", reserved=reserved)
  165. def linux_nvidia_9_3090_24gx8(reserved=True):
  166. return load_from_file("linux_nvidia_9_3090_24gx8.json", reserved=reserved)
  167. def linux_nvidia_10_3090_24gx8(reserved=True):
  168. return load_from_file("linux_nvidia_10_3090_24gx8.json", reserved=reserved)
  169. def linux_nvidia_11_V100_32gx2(reserved=True):
  170. return load_from_file("linux_nvidia_11_V100_32gx2.json", reserved=reserved)
  171. def linux_nvidia_12_A40_48gx2(reserved=True):
  172. return load_from_file("linux_nvidia_12_A40_48gx2.json", reserved=reserved)
  173. def linux_nvidia_13_A100_80gx8(reserved=True):
  174. return load_from_file("linux_nvidia_13_A100_80gx8.json", reserved=reserved)
  175. def linux_nvidia_14_A100_40gx2(reserved=True):
  176. return load_from_file("linux_nvidia_14_A100_40gx2.json", reserved=reserved)
  177. def linux_nvidia_15_4080_16gx8(reserved=True):
  178. return load_from_file("linux_nvidia_15_4080_16gx8.json", reserved=reserved)
  179. def linux_nvidia_16_5000_16gx8(reserved=True):
  180. return load_from_file("linux_nvidia_16_5000_16gx8.json", reserved=reserved)
  181. def linux_nvidia_17_4090_24gx8(reserved=True):
  182. return load_from_file("linux_nvidia_17_4090_24gx8.json", reserved=reserved)
  183. def linux_nvidia_18_4090_24gx4_4080_16gx4(reserved=True):
  184. return load_from_file(
  185. "linux_nvidia_18_4090_24gx4_4080_16gx4.json", reserved=reserved
  186. )
  187. def linux_nvidia_19_4090_24gx2(reserved=False):
  188. return load_from_file("linux_nvidia_19_4090_24gx2.json", reserved=reserved)
  189. def linux_nvidia_20_3080_12gx8(reserved=False):
  190. return load_from_file("linux_nvidia_20_3080_12gx8.json", reserved=reserved)
  191. def linux_nvidia_21_4090_24gx4_3060_12gx4(reserved=False):
  192. return load_from_file(
  193. "linux_nvidia_21_4090_24gx4_3060_12gx4.json", reserved=reserved
  194. )
  195. def linux_nvidia_22_H100_80gx8(reserved=False):
  196. return load_from_file("linux_nvidia_22_H100_80gx8.json", reserved=reserved)
  197. def linux_nvidia_23_H100_80gx8(reserved=False):
  198. return load_from_file("linux_nvidia_23_H100_80gx8.json", reserved=reserved)
  199. def linux_nvidia_24_H100_80gx8(reserved=False):
  200. return load_from_file("linux_nvidia_24_H100_80gx8.json", reserved=reserved)
  201. def linux_nvidia_25_H100_80gx8(reserved=False):
  202. return load_from_file("linux_nvidia_25_H100_80gx8.json", reserved=reserved)
  203. def linux_nvidia_26_H200_141gx8(reserved=False):
  204. return load_from_file("linux_nvidia_26_H200_141gx8.json", reserved=reserved)
  205. def linux_rocm_1_7800_16gx1(reserved=True):
  206. return load_from_file("linux_rocm_1_7800_16gx1.json", reserved=reserved)
  207. def linux_rocm_2_7800_16gx2(reserved=True):
  208. return load_from_file("linux_rocm_2_7800_16gx2.json", reserved=reserved)
  209. def linux_cpu_1(reserved=False):
  210. return load_from_file("linux_cpu_1.json", reserved=reserved)
  211. def linux_cpu_2(reserved=False):
  212. return load_from_file("linux_cpu_2.json", reserved=reserved)
  213. def linux_cpu_3(reserved=False):
  214. return load_from_file("linux_cpu_3.json", reserved=reserved)
  215. def linux_mix_1_nvidia_4080_16gx1_rocm_7800_16gx1(reserved=False):
  216. return load_from_file(
  217. "linux_mix_1_nvidia_4080_16gx1_rocm_7800_16gx1.json", reserved=reserved
  218. )
  219. def load_from_file(
  220. file_name, reserved=False, return_devices: Optional[int] = None
  221. ) -> Worker:
  222. dir = os.path.dirname(__file__)
  223. file_path = os.path.join(dir, file_name)
  224. with open(file_path, 'r') as file:
  225. dict = json.loads(file.read())
  226. status_dict = dict.get("status")
  227. memory = status_dict.get("memory")
  228. gpu_devices = status_dict.get("gpu_devices")
  229. status = WorkerStatus(**status_dict)
  230. status.memory = MemoryInfo(**memory)
  231. if gpu_devices:
  232. status.gpu_devices = [GPUDeviceStatus(**device) for device in gpu_devices]
  233. worker = Worker(**dict)
  234. worker.status = status
  235. worker.system_reserved = SystemReserved(ram=0, vram=0)
  236. if reserved:
  237. system_reserved_dict = dict.get("system_reserved")
  238. system_reserved = SystemReserved(
  239. ram=system_reserved_dict.get("memory")
  240. or system_reserved_dict.get("ram")
  241. or 0,
  242. vram=system_reserved_dict.get("gpu_memory")
  243. or system_reserved_dict.get("vram")
  244. or 0,
  245. )
  246. worker.system_reserved = system_reserved
  247. if return_devices is not None:
  248. worker.status.gpu_devices = worker.status.gpu_devices[
  249. : max(0, min(return_devices, len(worker.status.gpu_devices)))
  250. ]
  251. return worker