Query model path with prioritized local checks: 1. Check local ModelScope cache. 2. Check local Hugging Face cache. 3. Try downloading from Hugging Face. 4. Try downloading from ModelScope.
(self, model_name)
| 173 | raise e # Re-raise the caught exception |
| 174 | |
| 175 | def query(self, model_name): |
| 176 | """ |
| 177 | Query model path with prioritized local checks: |
| 178 | 1. Check local ModelScope cache. |
| 179 | 2. Check local Hugging Face cache. |
| 180 | 3. Try downloading from Hugging Face. |
| 181 | 4. Try downloading from ModelScope. |
| 182 | """ |
| 183 | print(f"\n--- Querying model: {model_name} ---") |
| 184 | # Ensure model name is valid in at least one card |
| 185 | is_in_hf = model_name in HuggingFace_MODEL_CARD |
| 186 | is_in_ms = model_name in ModelScope_MODEL_CARD |
| 187 | if not is_in_hf and not is_in_ms: |
| 188 | raise ValueError(f"Model name '{model_name}' not found in either HuggingFace or ModelScope cards.") |
| 189 | |
| 190 | |
| 191 | model_path = None |
| 192 | |
| 193 | # 1. Check local ModelScope cache |
| 194 | if is_in_ms: |
| 195 | try: |
| 196 | print("Step 1: Checking local ModelScope cache...") |
| 197 | model_path = self.query_modelscope_model(model_name, local_only=True) |
| 198 | if model_path: |
| 199 | model_path = model_path +'/' if model_path[-1] !='/' else model_path |
| 200 | print(f"Success: Found in local ModelScope cache: {model_path}") |
| 201 | return model_path |
| 202 | except FileNotFoundError: |
| 203 | print("Info: Not found in local ModelScope cache.") |
| 204 | except ImportError: |
| 205 | print(self.logger("Warning: ModelScope library not available for local check.")) |
| 206 | except Exception as e: |
| 207 | print(self.logger(f"Warning: Error checking local ModelScope cache: {e}")) |
| 208 | else: |
| 209 | print("Step 1: Skipping local ModelScope check (not in ModelScope card).") |
| 210 | |
| 211 | |
| 212 | # 2. Check local Hugging Face cache |
| 213 | if is_in_hf: |
| 214 | try: |
| 215 | print("Step 2: Checking local Hugging Face cache...") |
| 216 | model_path = self.query_huggingface_model(model_name, local_only=True) |
| 217 | if model_path: |
| 218 | model_path = model_path +'/' if model_path[-1] !='/' else model_path |
| 219 | print(f"Success: Found in local Hugging Face cache: {model_path}") |
| 220 | return model_path |
| 221 | except FileNotFoundError: |
| 222 | print("Info: Not found in local Hugging Face cache.") |
| 223 | except ImportError: |
| 224 | print(self.logger("Warning: Hugging Face library not available for local check.")) |
| 225 | except Exception as e: |
| 226 | print(self.logger(f"Warning: Error checking local Hugging Face cache: {e}")) |
| 227 | else: |
| 228 | print("Step 2: Skipping local Hugging Face check (not in HuggingFace card).") |
| 229 | |
| 230 | # If we reach here, the model was not found locally. Try downloading. |
| 231 | print("Info: Model not found in local caches. Attempting downloads...") |
| 232 |
no test coverage detected