test_model_sets.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import pytest
  2. from gpustack.routes.model_sets import filter_specs_by_gpu
  3. from gpustack.schemas.gpu_devices import GPUDevice
  4. from gpustack.schemas.model_sets import GPUFilters, ModelSpec
  5. from gpustack.schemas.models import SourceEnum
  6. def make_model_spec(**kwargs):
  7. return ModelSpec(
  8. source=SourceEnum.HUGGING_FACE, huggingface_repo_id="Qwen/Qwen3-0.6B", **kwargs
  9. )
  10. @pytest.mark.parametrize(
  11. "case_name, gpus, model_specs, filtered_specs_expected",
  12. [
  13. (
  14. "filter by gpu vendor",
  15. [
  16. GPUDevice(vendor="nvidia", compute_capability="8.0"),
  17. ],
  18. [
  19. make_model_spec(
  20. mode="standard", gpu_filters=GPUFilters(vendor=["nvidia"])
  21. ),
  22. make_model_spec(
  23. mode="standard", gpu_filters=GPUFilters(vendor=["amd"])
  24. ),
  25. ],
  26. [
  27. make_model_spec(
  28. mode="standard", gpu_filters=GPUFilters(vendor=["nvidia"])
  29. ),
  30. ],
  31. ),
  32. (
  33. "filter by gpu vendor ascend",
  34. [
  35. GPUDevice(vendor="ascend"),
  36. ],
  37. [
  38. make_model_spec(
  39. mode="standard", gpu_filters=GPUFilters(vendor=["nvidia"])
  40. ),
  41. make_model_spec(
  42. mode="standard", gpu_filters=GPUFilters(vendor=["ascend"])
  43. ),
  44. make_model_spec(
  45. mode="throughput", gpu_filters=GPUFilters(vendor=["ascend"])
  46. ),
  47. ],
  48. [
  49. make_model_spec(
  50. mode="throughput", gpu_filters=GPUFilters(vendor=["ascend"])
  51. ),
  52. make_model_spec(
  53. mode="standard", gpu_filters=GPUFilters(vendor=["ascend"])
  54. ),
  55. ],
  56. ),
  57. (
  58. "filter by gpu vendor and compute capability",
  59. [
  60. GPUDevice(vendor="nvidia", compute_capability="7.0"),
  61. ],
  62. [
  63. make_model_spec(
  64. mode="standard",
  65. gpu_filters=GPUFilters(
  66. vendor=["nvidia"], compute_capability=">=7.0"
  67. ),
  68. ),
  69. make_model_spec(
  70. mode="standard",
  71. gpu_filters=GPUFilters(vendor=["amd"], compute_capability=">=7.0"),
  72. ),
  73. make_model_spec(
  74. mode="throughput",
  75. gpu_filters=GPUFilters(
  76. vendor=["nvidia"], compute_capability=">=8.0"
  77. ),
  78. ),
  79. make_model_spec(
  80. mode="latency",
  81. gpu_filters=GPUFilters(
  82. vendor=["nvidia"], compute_capability=">=7.0,<=9.0"
  83. ),
  84. ),
  85. ],
  86. [
  87. make_model_spec(
  88. mode="latency",
  89. gpu_filters=GPUFilters(
  90. vendor=["nvidia"], compute_capability=">=7.0,<=9.0"
  91. ),
  92. ),
  93. make_model_spec(
  94. mode="standard",
  95. gpu_filters=GPUFilters(
  96. vendor=["nvidia"], compute_capability=">=7.0"
  97. ),
  98. ),
  99. ],
  100. ),
  101. (
  102. "filter by gpu vendor and CANN variant",
  103. [
  104. GPUDevice(vendor="ascend", arch_family="Ascend910B2"),
  105. ],
  106. [
  107. make_model_spec(
  108. mode="standard",
  109. gpu_filters=GPUFilters(vendor=["nvidia"]),
  110. ),
  111. make_model_spec(
  112. mode="standard",
  113. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="310p"),
  114. ),
  115. make_model_spec(
  116. mode="standard",
  117. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="910b"),
  118. ),
  119. make_model_spec(
  120. mode="throughput",
  121. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="310p"),
  122. ),
  123. make_model_spec(
  124. mode="latency",
  125. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="910b"),
  126. ),
  127. make_model_spec(
  128. mode="any-ascend",
  129. gpu_filters=GPUFilters(vendor=["ascend"]),
  130. ),
  131. ],
  132. [
  133. make_model_spec(
  134. mode="latency",
  135. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="910b"),
  136. ),
  137. make_model_spec(
  138. mode="standard",
  139. gpu_filters=GPUFilters(vendor=["ascend"], vendor_variant="910b"),
  140. ),
  141. make_model_spec(
  142. mode="any-ascend",
  143. gpu_filters=GPUFilters(vendor=["ascend"]),
  144. ),
  145. ],
  146. ),
  147. (
  148. "no gpu filters",
  149. [
  150. GPUDevice(vendor="amd", compute_capability=None),
  151. ],
  152. [
  153. make_model_spec(mode="standard", gpu_filters=None),
  154. make_model_spec(
  155. mode="throughput", gpu_filters=GPUFilters(vendor=["nvidia"])
  156. ),
  157. ],
  158. [
  159. make_model_spec(mode="standard", gpu_filters=None),
  160. ],
  161. ),
  162. ],
  163. )
  164. def test_filter_specs_by_gpu(
  165. config, case_name, gpus, model_specs, filtered_specs_expected
  166. ):
  167. try:
  168. actual_specs = filter_specs_by_gpu(gpus, model_specs)
  169. assert actual_specs == filtered_specs_expected
  170. except AssertionError as e:
  171. print(f"Test case '{case_name}' failed.")
  172. raise e