Scan the Cake cluster cache for worker-received models.
(cake_cache: &Path, models: &mut Vec<LocalModel>)
| 291 | |
| 292 | /// Scan the Cake cluster cache for worker-received models. |
| 293 | fn scan_cake_cache(cake_cache: &Path, models: &mut Vec<LocalModel>) -> Result<()> { |
| 294 | let entries = match std::fs::read_dir(cake_cache) { |
| 295 | Ok(e) => e, |
| 296 | Err(_) => return Ok(()), |
| 297 | }; |
| 298 | |
| 299 | for entry in entries.flatten() { |
| 300 | let dir = entry.path(); |
| 301 | if !dir.is_dir() { |
| 302 | continue; |
| 303 | } |
| 304 | |
| 305 | let cluster_hash = entry.file_name().to_string_lossy().to_string(); |
| 306 | |
| 307 | if let Some((status, size_bytes)) = check_model_dir(&dir) { |
| 308 | // Try to extract a model name from config.json |
| 309 | let name = read_model_name_from_config(&dir) |
| 310 | .unwrap_or_else(|| format!("cluster:{}", &cluster_hash)); |
| 311 | |
| 312 | models.push(LocalModel { |
| 313 | name, |
| 314 | path: dir, |
| 315 | source: ModelSource::ClusterCache { cluster_hash }, |
| 316 | status, |
| 317 | size_bytes, |
| 318 | }); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | Ok(()) |
| 323 | } |
| 324 | |
| 325 | /// Try to read a model name from config.json (e.g. _name_or_path field). |
| 326 | fn read_model_name_from_config(dir: &Path) -> Option<String> { |
no test coverage detected