feat: Quantisierung und Vision-Projektor aus der Datei, Passungsblock mit Abstand, Browserprüfung (#1233, #1234)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -50,6 +50,32 @@ impl GgufKopf {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ist die Datei ein Vision-Projektor? Er heißt `mmproj-…` oder `<Modell>-mmproj-…`.
|
||||
pub fn ist_mmproj(stem: &str) -> bool {
|
||||
stem.to_lowercase().contains("mmproj")
|
||||
}
|
||||
|
||||
/// Wählt aus den Projektoren eines Ordners den passendsten für ein Modell: den mit dem längsten
|
||||
/// gemeinsamen Namensanfang, bei Gleichstand den ersten nach Name.
|
||||
pub fn bester_mmproj<'a>(
|
||||
modell_stem: &str,
|
||||
kandidaten: impl IntoIterator<Item = &'a std::path::PathBuf>,
|
||||
) -> Option<&'a std::path::PathBuf> {
|
||||
let m = modell_stem.to_lowercase();
|
||||
let gemeinsam = |p: &std::path::PathBuf| {
|
||||
let n = p
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
m.chars().zip(n.chars()).take_while(|(a, b)| a == b).count()
|
||||
};
|
||||
let mut alle: Vec<&std::path::PathBuf> = kandidaten.into_iter().collect();
|
||||
alle.sort();
|
||||
// `max_by_key` liefert bei Gleichstand das letzte Element, daher von hinten.
|
||||
alle.into_iter().rev().max_by_key(|p| gemeinsam(p))
|
||||
}
|
||||
|
||||
/// Name der Quantisierung zu `general.file_type` (llama.cpp `llama_ftype`).
|
||||
pub fn dateityp_name(zahl: u32) -> Option<&'static str> {
|
||||
Some(match zahl {
|
||||
@ -544,6 +570,21 @@ mod tests {
|
||||
b.extend(u64::MAX.to_le_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mmproj_erkennung_und_auswahl() {
|
||||
use std::path::PathBuf;
|
||||
assert!(ist_mmproj("mmproj-F16"));
|
||||
assert!(ist_mmproj("gemma-3-12b-it-mmproj-f16"));
|
||||
assert!(!ist_mmproj("gemma-3-12b-it-Q4_K_M"));
|
||||
let a = PathBuf::from("/m/gemma-3-12b-it-mmproj-f16.gguf");
|
||||
let b = PathBuf::from("/m/mmproj-qwen.gguf");
|
||||
let c = PathBuf::from("/m/mmproj-a.gguf");
|
||||
assert_eq!(bester_mmproj("gemma-3-12b-it-Q4_K_M", [&a, &b]), Some(&a));
|
||||
// Kein Namensanfang gemeinsam: der erste nach Name.
|
||||
assert_eq!(bester_mmproj("anders", [&b, &c]), Some(&c));
|
||||
assert_eq!(bester_mmproj("x", std::iter::empty::<&PathBuf>()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ohne_architektur_gibt_es_keinen_kopf() {
|
||||
let b = bauen(&[("general.name", V::S("x"))]);
|
||||
|
||||
@ -27,7 +27,7 @@ mod types;
|
||||
pub mod startparams;
|
||||
|
||||
pub use engine::Engine;
|
||||
pub use llama::{LlamaCppConfig, LlamaCppEngine};
|
||||
pub use llama::{LlamaCppConfig, LlamaCppEngine, parse_quantization};
|
||||
pub use maya::{MayaConfig, MayaEngine};
|
||||
pub use mock::{MockConfig, MockEngine};
|
||||
pub use ollama::{OllamaConfig, OllamaEngine, OllamaMode};
|
||||
|
||||
@ -522,20 +522,18 @@ 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();
|
||||
// Vision-Projektoren je Ordner, dem passendsten Modell dort zugeordnet.
|
||||
let mut projektoren: BTreeMap<PathBuf, Vec<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"));
|
||||
.is_some_and(crate::gguf::ist_mmproj);
|
||||
if mmproj && let Some(dir) = path.parent() {
|
||||
let e = projektoren
|
||||
projektoren
|
||||
.entry(dir.to_path_buf())
|
||||
.or_insert_with(|| path.clone());
|
||||
if path < e {
|
||||
*e = path.clone();
|
||||
}
|
||||
.or_default()
|
||||
.push(path.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +542,7 @@ pub(crate) fn scan_models(roots: &[PathBuf]) -> Vec<DiscoveredArtifact> {
|
||||
continue;
|
||||
};
|
||||
let lower = stem.to_lowercase();
|
||||
if lower.starts_with("mmproj") || lower.contains("vocab") || lower.starts_with("mtp") {
|
||||
if crate::gguf::ist_mmproj(stem) || lower.contains("vocab") || lower.starts_with("mtp") {
|
||||
continue;
|
||||
}
|
||||
match split_shard(stem) {
|
||||
@ -583,7 +581,12 @@ pub(crate) fn scan_models(roots: &[PathBuf]) -> Vec<DiscoveredArtifact> {
|
||||
}
|
||||
}
|
||||
for a in &mut found {
|
||||
a.mmproj = a.path.parent().and_then(|d| projektoren.get(d)).cloned();
|
||||
a.mmproj = a
|
||||
.path
|
||||
.parent()
|
||||
.and_then(|d| projektoren.get(d))
|
||||
.and_then(|liste| crate::gguf::bester_mmproj(&a.name, liste))
|
||||
.cloned();
|
||||
}
|
||||
found.sort_by(|a, b| a.name.cmp(&b.name).then_with(|| a.path.cmp(&b.path)));
|
||||
found
|
||||
@ -634,7 +637,7 @@ fn split_shard(stem: &str) -> Option<(&str, u32, u32)> {
|
||||
|
||||
/// Erkennt die Quantisierung im Dateinamen (zum Beispiel `Q4_K_XL`, `IQ1_S`,
|
||||
/// `BF16`). Liefert `None`, wenn der Name keine erkennbare Angabe enthält.
|
||||
pub(crate) fn parse_quantization(name: &str) -> Option<String> {
|
||||
pub fn parse_quantization(name: &str) -> Option<String> {
|
||||
name.split(['-', '.']).find_map(|token| {
|
||||
let upper = token.to_uppercase();
|
||||
let digit_after = |prefix: &str| {
|
||||
|
||||
Reference in New Issue
Block a user