|
2 | 2 | from typing import Self |
3 | 3 | from ocp_resources.config_map import ConfigMap |
4 | 4 | from simple_logger.logger import get_logger |
5 | | - |
6 | 5 | from tests.model_registry.model_catalog.constants import HF_MODELS |
7 | 6 | from tests.model_registry.model_catalog.utils import ( |
8 | 7 | get_hf_catalog_str, |
9 | 8 | ) |
10 | 9 | from tests.model_registry.model_catalog.huggingface.utils import ( |
11 | 10 | assert_huggingface_values_matches_model_catalog_api_values, |
| 11 | + wait_for_huggingface_retrival_match, |
| 12 | + wait_for_hugging_face_model_import, |
12 | 13 | ) |
| 14 | +from kubernetes.dynamic import DynamicClient |
13 | 15 |
|
14 | 16 | LOGGER = get_logger(name=__name__) |
15 | 17 |
|
@@ -54,3 +56,96 @@ def test_huggingface_model_metadata( |
54 | 56 | expected_catalog_values=expected_catalog_values, |
55 | 57 | huggingface_api=huggingface_api, |
56 | 58 | ) |
| 59 | + |
| 60 | + |
| 61 | +class TestHFPatternMatching: |
| 62 | + @pytest.mark.parametrize( |
| 63 | + "updated_catalog_config_map_scope_function, num_models_from_hf_api_with_matching_criteria", |
| 64 | + [ |
| 65 | + pytest.param( |
| 66 | + """ |
| 67 | +catalogs: |
| 68 | + - name: HuggingFace Hub |
| 69 | + id: hf_id |
| 70 | + type: hf |
| 71 | + enabled: true |
| 72 | + includedModels: |
| 73 | + - huggingface-course/* |
| 74 | +""", |
| 75 | + {"org_name": "huggingface-course", "excluded_str": None}, |
| 76 | + id="test_hf_source_wildcard", |
| 77 | + ), |
| 78 | + pytest.param( |
| 79 | + """ |
| 80 | +catalogs: |
| 81 | + - name: HuggingFace Hub |
| 82 | + id: hf_id |
| 83 | + type: hf |
| 84 | + enabled: true |
| 85 | + properties: |
| 86 | + allowedOrganization: "huggingface-course" |
| 87 | + includedModels: |
| 88 | + - '*' |
| 89 | +""", |
| 90 | + {"org_name": "huggingface-course", "excluded_str": None}, |
| 91 | + id="test_hf_source_allowed_org", |
| 92 | + ), |
| 93 | + pytest.param( |
| 94 | + """ |
| 95 | +catalogs: |
| 96 | + - name: HuggingFace Hub |
| 97 | + id: hf_id |
| 98 | + type: hf |
| 99 | + enabled: true |
| 100 | + properties: |
| 101 | + allowedOrganization: "huggingface-course" |
| 102 | + includedModels: |
| 103 | + - '*' |
| 104 | + excludedModels: |
| 105 | + - '*-accelerate' |
| 106 | +""", |
| 107 | + {"org_name": "huggingface-course", "excluded_str": "-accelerate"}, |
| 108 | + id="test_hf_source_allowed_org_exclude", |
| 109 | + ), |
| 110 | + pytest.param( |
| 111 | + """ |
| 112 | +catalogs: |
| 113 | + - name: HuggingFace Hub |
| 114 | + id: hf_id |
| 115 | + type: hf |
| 116 | + enabled: true |
| 117 | + includedModels: |
| 118 | + - 'ibm-granite/granite-4.0-micro*' |
| 119 | +""", |
| 120 | + {"org_name": "ibm-granite", "included_str": "ibm-granite/granite-4.0-micro"}, |
| 121 | + id="test_hf_source_allowed_org_include", |
| 122 | + ), |
| 123 | + ], |
| 124 | + indirect=True, |
| 125 | + ) |
| 126 | + def test_hugging_face_models( |
| 127 | + self: Self, |
| 128 | + admin_client: DynamicClient, |
| 129 | + model_registry_namespace: str, |
| 130 | + updated_catalog_config_map_scope_function: ConfigMap, |
| 131 | + model_catalog_rest_url: list[str], |
| 132 | + model_registry_rest_headers: dict[str, str], |
| 133 | + huggingface_api: bool, |
| 134 | + num_models_from_hf_api_with_matching_criteria: int, |
| 135 | + ): |
| 136 | + """ |
| 137 | + Test that excluded models do not appear in the catalog API response |
| 138 | + """ |
| 139 | + LOGGER.info("Testing HuggingFace model exclusion functionality") |
| 140 | + wait_for_hugging_face_model_import( |
| 141 | + admin_client=admin_client, |
| 142 | + model_registry_namespace=model_registry_namespace, |
| 143 | + hf_id="hf_id", |
| 144 | + expected_num_models_from_hf_api=num_models_from_hf_api_with_matching_criteria, |
| 145 | + ) |
| 146 | + wait_for_huggingface_retrival_match( |
| 147 | + source_id="hf_id", |
| 148 | + model_registry_rest_headers=model_registry_rest_headers, |
| 149 | + model_catalog_rest_url=model_catalog_rest_url, |
| 150 | + expected_num_models_from_hf_api=num_models_from_hf_api_with_matching_criteria, |
| 151 | + ) |
0 commit comments