Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -522,6 +522,22 @@ pub(crate) fn scan_models(roots: &[PathBuf]) -> Vec<DiscoveredArtifact> {
|
||||
|
||||
let mut singles = Vec::new();
|
||||
let mut shards: BTreeMap<(PathBuf, String), ShardGroup> = BTreeMap::new();
|
||||
// Vision-Projektoren je Ordner (der erste nach Name), dem Modell dort zugeordnet.
|
||||
let mut projektoren: BTreeMap<PathBuf, PathBuf> = BTreeMap::new();
|
||||
for (path, _) in &files {
|
||||
let mmproj = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.is_some_and(|s| s.to_lowercase().starts_with("mmproj"));
|
||||
if mmproj && let Some(dir) = path.parent() {
|
||||
let e = projektoren
|
||||
.entry(dir.to_path_buf())
|
||||
.or_insert_with(|| path.clone());
|
||||
if path < e {
|
||||
*e = path.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (path, size) in files {
|
||||
let Some(stem) = path.file_stem().and_then(|s| s.to_str()) else {
|
||||
@ -544,30 +560,50 @@ pub(crate) fn scan_models(roots: &[PathBuf]) -> Vec<DiscoveredArtifact> {
|
||||
entry.0 = Some(path.clone());
|
||||
}
|
||||
}
|
||||
None => singles.push(DiscoveredArtifact {
|
||||
None => singles.push(mit_kopf(DiscoveredArtifact {
|
||||
name: stem.to_string(),
|
||||
quantization: parse_quantization(stem),
|
||||
path,
|
||||
size_bytes: size,
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
let mut found = singles;
|
||||
for ((_, base), (first, size, parts, expected)) in shards {
|
||||
if let (Some(path), true) = (first, parts == expected) {
|
||||
found.push(DiscoveredArtifact {
|
||||
found.push(mit_kopf(DiscoveredArtifact {
|
||||
quantization: parse_quantization(&base),
|
||||
name: base,
|
||||
path,
|
||||
size_bytes: size,
|
||||
});
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
}
|
||||
for a in &mut found {
|
||||
a.mmproj = a.path.parent().and_then(|d| projektoren.get(d)).cloned();
|
||||
}
|
||||
found.sort_by(|a, b| a.name.cmp(&b.name).then_with(|| a.path.cmp(&b.path)));
|
||||
found
|
||||
}
|
||||
|
||||
/// Liest den GGUF-Kopf; die Quantisierung aus der Datei hat Vorrang vor dem
|
||||
/// Namen (Rückfall: `parse_quantization`). Lesefehler lassen den Kopf leer.
|
||||
fn mit_kopf(mut a: DiscoveredArtifact) -> DiscoveredArtifact {
|
||||
match crate::gguf::kopf_lesen(&a.path) {
|
||||
Ok(kopf) => {
|
||||
if let Some(q) = kopf.quantisierung() {
|
||||
a.quantization = Some(q.to_string());
|
||||
}
|
||||
a.kopf = Some(kopf);
|
||||
}
|
||||
Err(e) => tracing::debug!(pfad = %a.path.display(), fehler = %e, "GGUF-Kopf nicht gelesen"),
|
||||
}
|
||||
a
|
||||
}
|
||||
|
||||
fn collect_gguf(dir: &Path, depth: usize, out: &mut Vec<(PathBuf, u64)>) {
|
||||
if depth > MAX_SCAN_DEPTH {
|
||||
return;
|
||||
@ -826,6 +862,38 @@ mod tests {
|
||||
assert!(found[0].path.ends_with("Big-IQ1_S-00001-of-00002.gguf"));
|
||||
assert_eq!(found[0].quantization.as_deref(), Some("IQ1_S"));
|
||||
assert_eq!(found[1].size_bytes, 10);
|
||||
// Der Vision-Projektor im selben Ordner wird zugeordnet, nicht gelistet.
|
||||
assert!(
|
||||
found[1]
|
||||
.mmproj
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.ends_with("a/mmproj-F16.gguf"))
|
||||
);
|
||||
assert!(found[0].mmproj.is_none());
|
||||
// Keine lesbare Datei: Kopf leer, Quantisierung aus dem Namen.
|
||||
assert!(found[1].kopf.is_none());
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suche_liest_quantisierung_und_werte_aus_der_datei_auch_bei_umbenannter_datei() {
|
||||
let root = std::env::temp_dir().join(format!("nexus-adapter-kopf-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
// Im Namen steht Q8_0, in der Datei Q4_K_M (general.file_type 15).
|
||||
std::fs::write(
|
||||
root.join("umbenannt-Q8_0.gguf"),
|
||||
crate::gguf::testhilfe::standard(),
|
||||
)
|
||||
.unwrap();
|
||||
let found = scan_models(std::slice::from_ref(&root));
|
||||
assert_eq!(found.len(), 1);
|
||||
assert_eq!(found[0].quantization.as_deref(), Some("Q4_K_M"));
|
||||
let kopf = found[0].kopf.as_ref().expect("Kopf gelesen");
|
||||
assert_eq!(
|
||||
(kopf.architektur.as_str(), kopf.kontext, kopf.bloecke),
|
||||
("llama", Some(8192), Some(24))
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user