Check whether a cache directory contains valid model data for the given layers. For sharded models, verifies that the cached index's weight_map references all assigned layers and that the shard files containing those layers exist on disk.
(cache_dir: &Path, layers: &[String])
| 766 | /// For sharded models, verifies that the cached index's weight_map references all |
| 767 | /// assigned layers and that the shard files containing those layers exist on disk. |
| 768 | fn has_valid_model_cache(cache_dir: &Path, layers: &[String]) -> bool { |
| 769 | if !cache_dir.join("config.json").exists() { |
| 770 | return false; |
| 771 | } |
| 772 | // Single safetensors file — if it exists, assume it has everything |
| 773 | if cache_dir.join("model.safetensors").exists() { |
| 774 | return true; |
| 775 | } |
| 776 | // Sharded model: need index + shard files for all assigned layers |
| 777 | let index_path = cache_dir.join("model.safetensors.index.json"); |
| 778 | if index_path.exists() { |
| 779 | if let Ok(data) = std::fs::read_to_string(&index_path) { |
| 780 | if let Ok(index) = serde_json::from_str::<serde_json::Value>(&data) { |
| 781 | if let Some(weight_map) = index.get("weight_map").and_then(|v| v.as_object()) { |
| 782 | // For each assigned layer, check that at least one tensor exists |
| 783 | // in the weight_map and its shard file is present on disk. |
| 784 | for layer in layers { |
| 785 | let prefix = format!("{}.", layer); |
| 786 | let has_layer = weight_map.iter().any(|(tensor_name, shard_file)| { |
| 787 | tensor_name.starts_with(&prefix) |
| 788 | && shard_file |
| 789 | .as_str() |
| 790 | .is_some_and(|f| cache_dir.join(f).exists()) |
| 791 | }); |
| 792 | if !has_layer { |
| 793 | log::debug!( |
| 794 | "cache miss: {} not found in {}", |
| 795 | layer, |
| 796 | cache_dir.display() |
| 797 | ); |
| 798 | return false; |
| 799 | } |
| 800 | } |
| 801 | return true; |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | false |
| 807 | } |
| 808 | |
| 809 | // ── Worker setup ──────────────────────────────────────────────────────────── |
| 810 |
no test coverage detected