Scan the HuggingFace hub cache for model snapshots.
(hf_cache: &Path, models: &mut Vec<LocalModel>)
| 239 | |
| 240 | /// Scan the HuggingFace hub cache for model snapshots. |
| 241 | fn scan_hf_cache(hf_cache: &Path, models: &mut Vec<LocalModel>) -> Result<()> { |
| 242 | let entries = match std::fs::read_dir(hf_cache) { |
| 243 | Ok(e) => e, |
| 244 | Err(_) => return Ok(()), |
| 245 | }; |
| 246 | |
| 247 | for entry in entries.flatten() { |
| 248 | let dir_name = entry.file_name().to_string_lossy().to_string(); |
| 249 | // HF cache dirs look like "models--org--model-name" |
| 250 | if !dir_name.starts_with("models--") { |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | let snapshots_dir = entry.path().join("snapshots"); |
| 255 | if !snapshots_dir.exists() { |
| 256 | continue; |
| 257 | } |
| 258 | |
| 259 | // Parse model name from dir: "models--Qwen--Qwen2.5-Coder-1.5B-Instruct" → "evilsocket/Qwen2.5-Coder-1.5B-Instruct" |
| 260 | let model_name = dir_name |
| 261 | .strip_prefix("models--") |
| 262 | .unwrap_or(&dir_name) |
| 263 | .replacen("--", "/", 1); |
| 264 | |
| 265 | // Check each snapshot (usually just one) |
| 266 | let snapshot_entries = match std::fs::read_dir(&snapshots_dir) { |
| 267 | Ok(e) => e, |
| 268 | Err(_) => continue, |
| 269 | }; |
| 270 | |
| 271 | for snap_entry in snapshot_entries.flatten() { |
| 272 | let snap_path = snap_entry.path(); |
| 273 | if !snap_path.is_dir() { |
| 274 | continue; |
| 275 | } |
| 276 | |
| 277 | if let Some((status, size_bytes)) = check_model_dir(&snap_path) { |
| 278 | models.push(LocalModel { |
| 279 | name: model_name.clone(), |
| 280 | path: snap_path, |
| 281 | source: ModelSource::HuggingFaceCache, |
| 282 | status, |
| 283 | size_bytes, |
| 284 | }); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | Ok(()) |
| 290 | } |
| 291 | |
| 292 | /// Scan the Cake cluster cache for worker-received models. |
| 293 | fn scan_cake_cache(cake_cache: &Path, models: &mut Vec<LocalModel>) -> Result<()> { |
no test coverage detected