Skip to main content

weirdnet_model/hw/
sizing.rs

1//! The usable memory budget and which models fit in it.
2
3use crate::ModelSpec;
4use crate::speech::{self, CloneMode, SpeechProfile};
5use serde::{Deserialize, Serialize};
6
7use super::{Accel, GIB, Hardware};
8
9/// What a model is for on a node (its role): `chat`, `embedding`, `transcribe` or `speak` on the
10/// wire.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12#[serde(rename_all = "snake_case")]
13#[non_exhaustive]
14pub enum Purpose {
15    Chat,
16    Embedding,
17    /// Speech to text: audio in (an `input_audio` part), its transcript out, so a soundtrack can
18    /// become text for models that don't take audio. Never picked as a chat model.
19    Transcribe,
20    /// Text to speech: text (or a multi-speaker script) in, audio out, in the voices its
21    /// [`SpeechProfile`] lists ([`CatalogEntry::speech`]). Never picked as a chat model, never
22    /// in a [`plan`]. Since 0.5.5.
23    Speak,
24}
25
26impl Purpose {
27    /// Every purpose, in wire order.
28    pub const ALL: [Purpose; 4] = [Purpose::Chat, Purpose::Embedding, Purpose::Transcribe, Purpose::Speak];
29
30    /// The name on the wire and in settings: `chat`, `embedding`, `transcribe` or `speak`.
31    pub fn as_str(&self) -> &'static str {
32        match self {
33            Purpose::Chat => "chat",
34            Purpose::Embedding => "embedding",
35            Purpose::Transcribe => "transcribe",
36            Purpose::Speak => "speak",
37        }
38    }
39
40    /// The purpose named `name` (as [`as_str`](Self::as_str) writes it), if any.
41    pub fn parse(name: &str) -> Option<Purpose> {
42        Purpose::ALL.into_iter().find(|p| p.as_str() == name)
43    }
44}
45
46impl std::fmt::Display for Purpose {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        f.write_str(self.as_str())
49    }
50}
51
52/// The speech-to-text entry ([`Purpose::Transcribe`]): Voxtral Mini 3B, which llama.cpp runs
53/// with its projector ([`CatalogEntry::projector`]).
54pub const VOXTRAL_MINI_3B: &str = "voxtral-mini-3b";
55
56/// Text-to-speech entries ([`Purpose::Speak`]), one per checkpoint (each mode of Qwen3-TTS is
57/// its own checkpoint, so its own id). Since 0.5.5.
58///
59/// Qwen3-TTS 0.6B CustomVoice: nine preset voices, for vLLM-Omni.
60pub const QWEN3_TTS_0_6B_CUSTOMVOICE: &str = "qwen3-tts-0.6b-customvoice";
61/// Qwen3-TTS 0.6B Base: voice cloning, for vLLM-Omni.
62pub const QWEN3_TTS_0_6B_BASE: &str = "qwen3-tts-0.6b-base";
63/// Qwen3-TTS 1.7B CustomVoice: nine preset voices with style instructions, for vLLM-Omni.
64pub const QWEN3_TTS_1_7B_CUSTOMVOICE: &str = "qwen3-tts-1.7b-customvoice";
65/// Qwen3-TTS 1.7B VoiceDesign: a voice from a description, for vLLM-Omni.
66pub const QWEN3_TTS_1_7B_VOICEDESIGN: &str = "qwen3-tts-1.7b-voicedesign";
67/// Qwen3-TTS 1.7B Base: voice cloning, as ggml-org's GGUF with its projector, for llama.cpp.
68pub const QWEN3_TTS_1_7B_BASE: &str = "qwen3-tts-1.7b-base";
69/// Kokoro 82M: 54 preset voices, as ggml-org's GGUF with its projector, for llama.cpp.
70pub const KOKORO_82M: &str = "kokoro-82m";
71/// VoxCPM2: voice design and cloning, as ggml-org's GGUF with its projector, for llama.cpp.
72pub const VOXCPM2: &str = "voxcpm2";
73/// Fish Audio Drama 3: multi-speaker scripts, as ggml-org's GGUF with its projector, for
74/// llama.cpp. Under the Fish Audio Community License ([`speech::FISH_AUDIO_COMMUNITY`]):
75/// [`CatalogEntry::restricted`], so [`speaker`] never picks it and a download needs the
76/// operator's explicit acceptance ([`Consent::accepting_license`](crate::Consent::accepting_license)).
77pub const FISH_AUDIO_DRAMA_3: &str = "fish-audio-drama-3";
78
79/// Caveling 2 Mini: caveman-so's fine-tune of Inkling 2 Mini (26B mixture of experts, 3.4B
80/// active, text and vision, Apache-2.0) that spends about 43% fewer reasoning tokens, as the
81/// Q4_K_M GGUF with its Q8_0 vision projector ([`CatalogEntry::projector`]) for llama.cpp. Since 0.5.6.
82pub const CAVELING_2_MINI: &str = "caveling-2-mini";
83
84/// Inkling 2 Mini: Thinking Machines' base model of [`CAVELING_2_MINI`] (a looped mixture of
85/// experts, 26B with 3.4B active, text and vision, Apache-2.0), as ggml-org's IQ4_NL GGUF with its
86/// Q8_0 vision projector ([`CatalogEntry::projector`]) for llama.cpp. Since 0.5.7.
87pub const INKLING_2_MINI: &str = "inkling-2-mini";
88/// Qwen3-VL 8B Instruct (Qwen, Apache-2.0): text, images and video, as the Hugging Face checkpoint
89/// (four shards, [`CatalogEntry::files`]) for vLLM. Since 0.5.7.
90pub const QWEN3_VL_8B: &str = "qwen3-vl-8b";
91/// Qwen3.8 27B in NVFP4 (RadixArk's quantization of Qwen's model, Apache-2.0): a dense multimodal
92/// checkpoint (three shards) for vLLM on NVIDIA Blackwell GPUs. Since 0.5.7.
93pub const QWEN3_8_27B_NVFP4: &str = "qwen3.8-27b-nvfp4";
94
95/// Speech-to-text entries ([`Purpose::Transcribe`]) that vLLM serves (the Hugging Face checkpoint,
96/// not a GGUF; install `vllm[audio]`). Since 0.5.6.
97///
98/// Qwen3-ASR 1.7B (Apache-2.0): two safetensors shards ([`CatalogEntry::files`]).
99pub const QWEN3_ASR_1_7B: &str = "qwen3-asr-1.7b";
100/// Whisper large-v3-turbo (MIT), for vLLM. Whisper-style: 30 second windows
101/// ([`WHISPER_CHUNK_SECONDS`](crate::limits::WHISPER_CHUNK_SECONDS)).
102pub const WHISPER_LARGE_V3_TURBO: &str = "whisper-large-v3-turbo";
103/// Cohere Transcribe 03-2026 (Apache-2.0), for vLLM. The Hub repo is gated
104/// ([`CatalogEntry::gated`]: accept its terms and set `HF_TOKEN`) and carries custom code, so
105/// vLLM needs `--trust-remote-code` ([`CatalogEntry::engine_args`]).
106pub const COHERE_TRANSCRIBE_03_2026: &str = "cohere-transcribe-03-2026";
107
108/// The context [`CAVELING_2_MINI`] and [`INKLING_2_MINI`] are sized and launched at (the 262144 an
109/// engine's default plan assumes does not leave room for their KV cache next to the weights on one
110/// node).
111const CAVELING_CONTEXT: u32 = 346_112;
112/// KV cache bytes per token of Inkling 2 Mini and its fine-tune Caveling 2 Mini, at f16. Four of
113/// the 24 layers attend over the whole context (5, 11, 17 and 23), and layers 6 to 17 run three
114/// passes that each keep their own cache, so layers 11 and 17 count three times each: 8 layer
115/// caches x 8 KV heads x (128 + 128) x 2 bytes. From `config.json` (`local_layer_ids`,
116/// `loop_config`) and the GGUF card's note that each pass keeps its own KV.
117const LOOPED_MINI_KV_BYTES: u64 = 8 * 8 * 256 * 2;
118
119/// Bytes of Qwen3-TTS's speech tokenizer (`speech_tokenizer/model.safetensors`, the same file in
120/// every Qwen3-TTS repo), which vLLM-Omni loads next to the checkpoint.
121const QWEN3_TTS_TOKENIZER_BYTES: u64 = 682_293_092;
122/// Where Drama 3's weights come from, for the license check on hand-built specs.
123const DRAMA_3_UPSTREAM: &str = "fishaudio/drama-3";
124
125/// A later shard of a sharded checkpoint: file name, bytes, SHA-256.
126type Shard = (&'static str, u64, &'static str);
127
128/// The shards after the first of a sharded entry (the first is [`CatalogEntry::spec`]), in order.
129fn later_shards(id: &str) -> &'static [Shard] {
130    match id {
131        QWEN3_ASR_1_7B => &[("model-00002-of-00002.safetensors", 478_200_688, "6e0b9d9e09e2e0238e7ef3cc8a484ab387e91b90f1900bedf88bc92d7929ccfc")],
132        QWEN3_VL_8B => &[
133            ("model-00002-of-00004.safetensors", 4_915_962_496, "8be88fb5501e4d5719a6d4cc212e6a13480330e74f3e8c77daa1a68f199106b5"),
134            ("model-00003-of-00004.safetensors", 4_999_831_048, "83de00eafe6e0d57ccd009dbcf71c9974d74df2f016c27afb7e95aafd16b2192"),
135            ("model-00004-of-00004.safetensors", 2_716_270_024, "0a88b98e9f96270973f567e6a2c103ede6ccdf915ca3075e21c755604d0377a5"),
136        ],
137        QWEN3_8_27B_NVFP4 => &[
138            ("model-00002-of-00003.safetensors", 9_985_757_064, "db6146a5464fb0a891181b93c81593f0ca65c602eb14120a1c2b1b09bca11f85"),
139            ("model-00003-of-00003.safetensors", 1_970_287_672, "d3cfb92742e30c8b46564665791dbe0a86ed64cfc02b1275081530793c0c9581"),
140        ],
141        _ => &[],
142    }
143}
144
145/// A catalog model with what it needs in memory.
146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
147pub struct CatalogEntry {
148    pub spec: ModelSpec,
149    pub purpose: Purpose,
150    pub quant: String,
151    /// Total and active parameters, in billions (they differ for mixture-of-experts models).
152    pub params_b: f32,
153    pub active_params_b: f32,
154    /// KV cache bytes per token at f16 (layers x KV heads x head dim x 2 x 2).
155    pub kv_bytes_per_token: u64,
156    /// Context the sizing assumes per slot.
157    pub context: u32,
158}
159
160impl CatalogEntry {
161    pub fn id(&self) -> &str {
162        &self.spec.id
163    }
164
165    /// Weights (and the projector's, for entries that need one, and Qwen3-TTS's speech tokenizer
166    /// for its vLLM-Omni checkpoints) plus KV for `slots` concurrent requests at the entry's
167    /// context, plus 10% for compute buffers.
168    pub fn footprint(&self, slots: u32) -> u64 {
169        let kv = self.kv_bytes_per_token * self.context as u64 * slots as u64;
170        let weights = self.weights_bytes() + self.projector().map_or(0, |p| p.size) + self.companion_bytes();
171        (weights + kv) + (weights + kv) / 10
172    }
173
174    fn companion_bytes(&self) -> u64 {
175        match self.spec.id.as_str() {
176            QWEN3_TTS_0_6B_CUSTOMVOICE | QWEN3_TTS_0_6B_BASE | QWEN3_TTS_1_7B_CUSTOMVOICE | QWEN3_TTS_1_7B_VOICEDESIGN => QWEN3_TTS_TOKENIZER_BYTES,
177            _ => 0,
178        }
179    }
180
181    /// Every weights file of the entry, in order, each a [`ModelSpec`] with its own size and
182    /// SHA-256. An entry with one file (all but the sharded checkpoints) lists just
183    /// [`spec`](Self::spec); a sharded checkpoint such as [`QWEN3_ASR_1_7B`] lists its safetensors
184    /// shards, the first of which is `spec` (what the engine loads the checkpoint from). Every
185    /// shard has the entry's id, so one [`Consent`](crate::Consent) covers them all and
186    /// [`download_parts`](crate::download::download_parts) fetches them together, checking each
187    /// hash. The files that are not weights (config, tokenizer) are not pinned: the engine
188    /// fetches them with the repo, at [`revision`](Self::revision). Since 0.5.6.
189    ///
190    /// ```no_run
191    /// use weirdnet_model::{Consent, ModelStore, download::download_parts, hw};
192    ///
193    /// let asr = hw::find(hw::QWEN3_ASR_1_7B).unwrap();
194    /// assert!(asr.is_sharded());
195    /// for shard in asr.files() {
196    ///     println!("{} {} bytes sha256 {}", shard.file, shard.size, shard.sha256.as_deref().unwrap());
197    /// }
198    /// // After showing the user what will be fetched: one consent, every shard checked.
199    /// let consent = Consent::given(&asr.spec);
200    /// download_parts(&ModelStore::from_env(), &asr.files(), &consent, &mut |_| true)?;
201    /// # Ok::<(), weirdnet_model::Error>(())
202    /// ```
203    pub fn files(&self) -> Vec<ModelSpec> {
204        let mut files = vec![self.spec.clone()];
205        files.extend(later_shards(&self.spec.id).iter().map(|&(file, size, sha256)| ModelSpec {
206            file: file.into(),
207            size,
208            sha256: Some(sha256.into()),
209            ..self.spec.clone()
210        }));
211        files
212    }
213
214    /// Whether the entry's weights are in more than one file ([`files`](Self::files)). Since 0.5.6.
215    pub fn is_sharded(&self) -> bool {
216        !later_shards(&self.spec.id).is_empty()
217    }
218
219    /// Bytes of all the weights files ([`files`](Self::files)): `spec.size` for an entry with one.
220    /// Since 0.5.6.
221    pub fn weights_bytes(&self) -> u64 {
222        self.spec.size + later_shards(&self.spec.id).iter().map(|s| s.1).sum::<u64>()
223    }
224
225    /// The Hugging Face commit the entry's sizes and hashes were read at, for the entries added
226    /// in 0.5.6 and 0.5.7 (an engine pins it, for example vLLM's `--revision`, so what it loads is what the
227    /// hashes describe). `None` for the entries from before, whose hashes pin the file itself.
228    /// Downloads here fetch `main` and check the pinned hashes, so a moved `main` fails the check
229    /// rather than loading other bytes. Since 0.5.6.
230    pub fn revision(&self) -> Option<&'static str> {
231        match self.spec.id.as_str() {
232            CAVELING_2_MINI => Some("ec4b4b4114cf8375abc1cf42d6c41971b778e2ba"),
233            INKLING_2_MINI => Some("0bdc580634ceac4c4d921f452777bf44228de9af"),
234            QWEN3_VL_8B => Some("0c351dd01ed87e9c1b53cbc748cba10e6187ff3b"),
235            QWEN3_8_27B_NVFP4 => Some("319f741cce68d7914884900c138a1fbb70a42f30"),
236            QWEN3_ASR_1_7B => Some("7278e1e70fe206f11671096ffdd38061171dd6e5"),
237            WHISPER_LARGE_V3_TURBO => Some("41f01f3fe87f28c78e2fbf8b568835947dd65ed9"),
238            COHERE_TRANSCRIBE_03_2026 => Some("d552dadc2922ba6f6c1f994f8db904d52dcaf942"),
239            _ => None,
240        }
241    }
242
243    /// Arguments the entry needs on its engine's command line, in addition to the ones an app
244    /// sets for every model: `llama-server` arguments for a GGUF entry ([`is_gguf`](Self::is_gguf);
245    /// `-fa on --jinja` for [`CAVELING_2_MINI`] and [`INKLING_2_MINI`]) and vLLM arguments for a checkpoint
246    /// (`--trust-remote-code` for [`COHERE_TRANSCRIBE_03_2026`], whose repo ships its own modeling
247    /// code). Append them to the launch's extra arguments, after the operator's own, never
248    /// instead of them. Empty for an entry that needs none. Since 0.5.6.
249    ///
250    /// ```
251    /// use weirdnet_model::hw;
252    ///
253    /// let cohere = hw::find(hw::COHERE_TRANSCRIBE_03_2026).unwrap();
254    /// let mut extra_args: Vec<String> = vec!["--max-model-len".into(), "4096".into()]; // the operator's own
255    /// extra_args.extend(cohere.engine_args().iter().map(|a| a.to_string()));
256    /// assert_eq!(extra_args, ["--max-model-len", "4096", "--trust-remote-code"]);
257    /// assert!(cohere.gated() && cohere.revision().is_some());
258    /// ```
259    pub fn engine_args(&self) -> &'static [&'static str] {
260        match self.spec.id.as_str() {
261            CAVELING_2_MINI | INKLING_2_MINI => &["-fa", "on", "--jinja"],
262            COHERE_TRANSCRIBE_03_2026 => &["--trust-remote-code"],
263            _ => &[],
264        }
265    }
266
267    /// The context to launch the entry with when it needs more than an engine's default plan:
268    /// [`CAVELING_2_MINI`] and (since 0.5.7) [`INKLING_2_MINI`] run at 346112 tokens (the same
269    /// figure their footprint is sized at; the 262144 default does not fit next to their weights).
270    /// `None` when the default is right. Since 0.5.6.
271    pub fn launch_context(&self) -> Option<u32> {
272        matches!(self.spec.id.as_str(), CAVELING_2_MINI | INKLING_2_MINI).then_some(CAVELING_CONTEXT)
273    }
274
275    /// The number of layers to offload to the GPU when the entry should not use the default
276    /// (`99` for [`CAVELING_2_MINI`] and [`INKLING_2_MINI`]: all of them). `None` when the default
277    /// is right. Since 0.5.6.
278    pub fn launch_gpu_layers(&self) -> Option<u32> {
279        matches!(self.spec.id.as_str(), CAVELING_2_MINI | INKLING_2_MINI).then_some(99)
280    }
281
282    /// Whether the Hub repo is gated: it needs the terms accepted on the Hub and a token on the
283    /// downloading node (`HF_TOKEN`, [`HfToken`](crate::HfToken)). [`download`](crate::download())
284    /// says so, without a request, when the store has none. [`COHERE_TRANSCRIBE_03_2026`] is.
285    /// Since 0.5.6.
286    pub fn gated(&self) -> bool {
287        self.spec.id == COHERE_TRANSCRIBE_03_2026
288    }
289
290    /// Whether the entry is a GGUF file llama.cpp runs (with its [`projector`](Self::projector)
291    /// when it has one). The others are Hugging Face checkpoints for vLLM-Omni: `spec.repo` is the
292    /// repo the engine serves, and `spec.file`, `size` and `sha256` pin its main weights (the
293    /// engine fetches the rest of the repo). Since 0.5.5.
294    pub fn is_gguf(&self) -> bool {
295        self.spec.file.to_ascii_lowercase().ends_with(".gguf")
296    }
297
298    /// Whether this is a text-to-speech model ([`Purpose::Speak`]). Since 0.5.5.
299    pub fn speaks(&self) -> bool {
300        self.purpose == Purpose::Speak
301    }
302
303    /// The model's license as its card names it (an SPDX id such as `apache-2.0`, or
304    /// [`speech::FISH_AUDIO_COMMUNITY`]), for the entries that record it: the speech-to-text and
305    /// text-to-speech models, [`CAVELING_2_MINI`], and (since 0.5.7)
306    /// [`INKLING_2_MINI`], [`QWEN3_VL_8B`] and [`QWEN3_8_27B_NVFP4`] (`apache-2.0`; `mit` for
307    /// [`WHISPER_LARGE_V3_TURBO`]). `None` for the others. Since 0.5.5.
308    pub fn license(&self) -> Option<&'static str> {
309        match self.spec.id.as_str() {
310            FISH_AUDIO_DRAMA_3 => Some(speech::FISH_AUDIO_COMMUNITY),
311            WHISPER_LARGE_V3_TURBO => Some("mit"),
312            VOXTRAL_MINI_3B
313            | CAVELING_2_MINI
314            | INKLING_2_MINI
315            | QWEN3_VL_8B
316            | QWEN3_8_27B_NVFP4
317            | QWEN3_ASR_1_7B
318            | COHERE_TRANSCRIBE_03_2026
319            | QWEN3_TTS_0_6B_CUSTOMVOICE
320            | QWEN3_TTS_0_6B_BASE
321            | QWEN3_TTS_1_7B_CUSTOMVOICE
322            | QWEN3_TTS_1_7B_VOICEDESIGN
323            | QWEN3_TTS_1_7B_BASE
324            | KOKORO_82M
325            | VOXCPM2 => Some("apache-2.0"),
326            _ => None,
327        }
328    }
329
330    /// Whether the license restricts use ([`speech::restricting_license`]): such an entry is never
331    /// picked by [`speaker`] or a [`plan`], and [`download`](crate::download()) refuses it (and its
332    /// projector) without a [`Consent::accepting_license`](crate::Consent::accepting_license) for
333    /// that license. Since 0.5.5.
334    pub fn restricted(&self) -> bool {
335        speech::restricting_license(self.license()).is_some()
336    }
337
338    /// What a text-to-speech entry does, cited to the model's card and its engine's documentation
339    /// (llama.cpp `docs/multimodal/tts.md` and the llama-server README for GGUF entries; the
340    /// vLLM-Omni speech API for the others), read 2026-11-27. Never measured figures: what an
341    /// engine reports at load goes over it ([`SpeechProfile::or`]). `None` for entries that
342    /// don't speak. Since 0.5.5.
343    ///
344    /// - Qwen3-TTS (24 kHz, ten languages): CustomVoice has nine preset voices (the 1.7B also
345    ///   takes style instructions; the 0.6B doesn't), VoiceDesign designs a voice from a
346    ///   description, Base clones a voice from a clip whose transcript is optional on vLLM-Omni;
347    ///   ggml-org's 1.7B Base projector has the speaker encoder only, so llama.cpp clones from
348    ///   the clip alone.
349    /// - Kokoro (24 kHz): the 54 voices in ggml-org's projector, `af_heart` (the default) first;
350    ///   English from text (`en-us`, `en-gb`), other languages as raw phonemes; speed.
351    /// - VoxCPM2 (48 kHz, 30 languages from the text): voice design, cloning from a clip (its
352    ///   first 30 s; no transcript).
353    /// - Fish Audio Drama 3 (44.1 kHz, 83 languages from the text): scripts of up to 16
354    ///   speakers. ggml-org's projector has no codec encoder, so it does not clone ("Voice
355    ///   cloning is not supported yet", its card). License [`speech::FISH_AUDIO_COMMUNITY`].
356    pub fn speech(&self) -> Option<SpeechProfile> {
357        if !self.speaks() {
358            return None;
359        }
360        let qwen_vllm = || speech::vllm_omni().with_languages(speech::QWEN3_TTS_LANGUAGES).with_sample_rate(24_000);
361        Some(match self.spec.id.as_str() {
362            QWEN3_TTS_0_6B_CUSTOMVOICE => qwen_vllm().with_presets(QWEN3_TTS_SPEAKERS),
363            QWEN3_TTS_1_7B_CUSTOMVOICE => qwen_vllm().with_presets(QWEN3_TTS_SPEAKERS).with_instructions(true),
364            QWEN3_TTS_1_7B_VOICEDESIGN => qwen_vllm().with_design(true),
365            QWEN3_TTS_0_6B_BASE => qwen_vllm().with_clone(CloneMode::AudioAndText),
366            QWEN3_TTS_1_7B_BASE => {
367                speech::llama_server().with_languages(speech::QWEN3_TTS_LANGUAGES).with_sample_rate(24_000).with_clone(CloneMode::Audio)
368            }
369            KOKORO_82M => speech::llama_server()
370                .with_presets(KOKORO_VOICES)
371                .with_languages(speech::KOKORO_LANGUAGES)
372                .with_raw(true)
373                .with_speed(true)
374                .with_sample_rate(24_000),
375            VOXCPM2 => speech::llama_server()
376                .with_design(true)
377                .with_clone(CloneMode::Audio)
378                .with_max_reference_seconds(30)
379                .with_languages(VOXCPM2_LANGUAGES)
380                .with_sample_rate(48_000),
381            FISH_AUDIO_DRAMA_3 => speech::llama_server()
382                .with_script_speakers(16)
383                .with_languages(DRAMA_3_LANGUAGES)
384                .with_sample_rate(44_100)
385                .with_license(speech::FISH_AUDIO_COMMUNITY),
386            _ => return None,
387        })
388    }
389
390    /// Repos whose files fall under this entry's license (its own, and where the weights come
391    /// from), for [`restricted_license`].
392    fn license_repos(&self) -> Vec<&str> {
393        let mut repos = vec![self.spec.repo.as_str()];
394        if self.spec.id == FISH_AUDIO_DRAMA_3 {
395            repos.push(DRAMA_3_UPSTREAM);
396        }
397        repos
398    }
399
400    /// The multimodal projector (llama.cpp `--mmproj`) the entry needs, pinned like the model
401    /// file: the audio encoder for [`VOXTRAL_MINI_3B`], and the audio generator (codec, voices,
402    /// reference encoder) of each GGUF text-to-speech entry, and the vision encoder of
403    /// [`CAVELING_2_MINI`] and [`INKLING_2_MINI`] (Q8_0). `None` for the other text models and the checkpoints vLLM serves.
404    /// Download it with the same consent gate as the model.
405    pub fn projector(&self) -> Option<ModelSpec> {
406        match self.spec.id.as_str() {
407            VOXTRAL_MINI_3B => Some(spec(
408                "voxtral-mini-3b-mmproj",
409                "Voxtral Mini 3B audio encoder (Q8_0)",
410                "ggml-org/Voxtral-Mini-3B-2507-GGUF",
411                "mmproj-Voxtral-Mini-3B-2507-Q8_0.gguf",
412                715_714_080,
413                "4f24c4ef3ce929d02ed9d1cfb050ae9a7365f057c0ddec0d489580982ebe0d02",
414            )),
415            CAVELING_2_MINI => Some(spec(
416                "caveling-2-mini-mmproj",
417                "Caveling 2 Mini vision encoder (Q8_0)",
418                "caveman-so/caveling-2-mini-GGUF",
419                "mmproj-Caveling-2-Mini-Q8_0.gguf",
420                345_911_360,
421                "ff510827b8f496f6e0755a374c74d8aee0ab5186d953e0e3a6d1fb17a98d3e9f",
422            )),
423            INKLING_2_MINI => Some(spec(
424                "inkling-2-mini-mmproj",
425                "Inkling 2 Mini vision encoder (Q8_0)",
426                "ggml-org/Inkling-2-Mini-GGUF",
427                "mmproj-Inkling-2-Mini-Q8_0.gguf",
428                345_910_944,
429                "233287272ec5ac39b4168677aba54a4c024f202410f5629fac1830e1059f8abb",
430            )),
431            QWEN3_TTS_1_7B_BASE => Some(spec(
432                "qwen3-tts-1.7b-base-mmproj",
433                "Qwen3-TTS 1.7B Base speaker encoder and codec (Q8_0)",
434                "ggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF",
435                "mmproj-Qwen3-TTS-12Hz-1.7B-Base-Q8_0.gguf",
436                446_422_912,
437                "6fd65188839bcd6ecc91b277ad471e22a0edfada4699a0fe82f1165c18cfcce2",
438            )),
439            KOKORO_82M => Some(spec(
440                "kokoro-82m-mmproj",
441                "Kokoro 82M decoder and voices (F16)",
442                "ggml-org/Kokoro-82M-GGUF",
443                "mmproj-Kokoro-82M-F16.gguf",
444                208_456_512,
445                "071d20f53b7c5d64b08a24bff5dfb77c2ea0df843a7c6c2356998a735ec6929d",
446            )),
447            VOXCPM2 => Some(spec(
448                "voxcpm2-mmproj",
449                "VoxCPM2 LocDiT and AudioVAE (BF16)",
450                "ggml-org/VoxCPM2-GGUF",
451                "mmproj-VoxCPM2-BF16.gguf",
452                2_007_741_504,
453                "2d0be367461d11e12a8544487491936a8f1d61d70d5313bb25dd50a4693be2ee",
454            )),
455            FISH_AUDIO_DRAMA_3 => Some(spec(
456                "fish-audio-drama-3-mmproj",
457                "Fish Audio Drama 3 codebook tower and codec (BF16)",
458                "ggml-org/drama-3-GGUF",
459                "mmproj-drama-3-BF16.gguf",
460                2_942_644_160,
461                "c29b9c90cf180cf81da39f31f023ba33641d54d7898e5e9be032c4d111ecbced",
462            )),
463            _ => None,
464        }
465    }
466
467    /// Whether this is a speech-to-text model ([`Purpose::Transcribe`]).
468    pub fn transcribes(&self) -> bool {
469        self.purpose == Purpose::Transcribe
470    }
471}
472
473fn spec(id: &str, label: &str, repo: &str, file: &str, size: u64, sha256: &str) -> ModelSpec {
474    ModelSpec { id: id.into(), label: label.into(), repo: repo.into(), file: file.into(), size, sha256: Some(sha256.into()) }
475}
476
477#[allow(clippy::too_many_arguments)]
478fn chat(spec: ModelSpec, quant: &str, params_b: f32, active_params_b: f32, kv_bytes_per_token: u64, context: u32) -> CatalogEntry {
479    CatalogEntry { spec, purpose: Purpose::Chat, quant: quant.into(), params_b, active_params_b, kv_bytes_per_token, context }
480}
481
482#[allow(clippy::too_many_arguments)]
483fn speaker_entry(spec: ModelSpec, quant: &str, params_b: f32, active_params_b: f32, kv_bytes_per_token: u64, context: u32) -> CatalogEntry {
484    CatalogEntry { spec, purpose: Purpose::Speak, quant: quant.into(), params_b, active_params_b, kv_bytes_per_token, context }
485}
486
487/// Qwen3-TTS CustomVoice's preset speakers (its model card, as `config.json` names them).
488const QWEN3_TTS_SPEAKERS: [&str; 9] = ["vivian", "serena", "uncle_fu", "dylan", "eric", "ryan", "aiden", "ono_anna", "sohee"];
489
490/// Kokoro's voices (`VOICES.md`; all 54 are in ggml-org's projector), the default first. The first
491/// letter is the language: American and British English, Spanish, French, Hindi, Italian,
492/// Japanese, Brazilian Portuguese, Mandarin.
493const KOKORO_VOICES: [&str; 54] = [
494    "af_heart",
495    "af_alloy",
496    "af_aoede",
497    "af_bella",
498    "af_jessica",
499    "af_kore",
500    "af_nicole",
501    "af_nova",
502    "af_river",
503    "af_sarah",
504    "af_sky",
505    "am_adam",
506    "am_echo",
507    "am_eric",
508    "am_fenrir",
509    "am_liam",
510    "am_michael",
511    "am_onyx",
512    "am_puck",
513    "am_santa",
514    "bf_alice",
515    "bf_emma",
516    "bf_isabella",
517    "bf_lily",
518    "bm_daniel",
519    "bm_fable",
520    "bm_george",
521    "bm_lewis",
522    "ef_dora",
523    "em_alex",
524    "em_santa",
525    "ff_siwis",
526    "hf_alpha",
527    "hf_beta",
528    "hm_omega",
529    "hm_psi",
530    "if_sara",
531    "im_nicola",
532    "jf_alpha",
533    "jf_gongitsune",
534    "jf_nezumi",
535    "jf_tebukuro",
536    "jm_kumo",
537    "pf_dora",
538    "pm_alex",
539    "pm_santa",
540    "zf_xiaobei",
541    "zf_xiaoni",
542    "zf_xiaoxiao",
543    "zf_xiaoyi",
544    "zm_yunjian",
545    "zm_yunxi",
546    "zm_yunxia",
547    "zm_yunyang",
548];
549
550/// VoxCPM2's 30 languages (its model card's `language` list).
551const VOXCPM2_LANGUAGES: [&str; 30] = [
552    "zh", "en", "ar", "my", "da", "nl", "fi", "fr", "de", "el", "he", "hi", "id", "it", "ja", "km", "ko", "lo", "ms", "no", "pl", "pt", "ru", "es",
553    "sw", "sv", "tl", "th", "tr", "vi",
554];
555
556/// Drama 3's 83 languages (its model card's `language` list).
557const DRAMA_3_LANGUAGES: [&str; 83] = [
558    "zh", "en", "ja", "ko", "es", "pt", "ar", "ru", "fr", "de", "sv", "it", "tr", "no", "nl", "cy", "eu", "ca", "da", "gl", "ta", "hu", "fi", "pl",
559    "et", "hi", "la", "ur", "th", "vi", "jw", "bn", "yo", "sl", "cs", "sw", "nn", "he", "ms", "uk", "id", "kk", "bg", "lv", "my", "tl", "sk", "ne",
560    "fa", "af", "el", "bo", "hr", "ro", "sn", "mi", "yi", "am", "be", "km", "is", "az", "sd", "br", "sq", "ps", "mn", "ht", "ml", "sr", "sa", "te",
561    "ka", "bs", "pa", "lt", "kn", "si", "hy", "mr", "as", "gu", "fo",
562];
563
564/// The tiered catalog: chat models smallest first, then the embedding model, then the
565/// speech-to-text models, then the text-to-speech models. Sizes and SHA-256 from the Hugging Face
566/// API (2026-11-19; Voxtral 2026-11-26; text to speech 2026-11-27; Caveling 2 Mini, Inkling 2 Mini,
567/// Qwen3-VL 8B, Qwen3.8 27B and the vLLM speech-to-text checkpoints 2026-12-02); the Gemma 4 files are `weirdnet-model`'s own pinned
568/// entries.
569pub fn catalog() -> Vec<CatalogEntry> {
570    let gemma = |id: &str| crate::catalog::find(id).expect("weirdnet-model ships Gemma 4");
571    vec![
572        chat(
573            spec(
574                "smollm2-135m",
575                "SmolLM2 135M instruct (Q8_0)",
576                "bartowski/SmolLM2-135M-Instruct-GGUF",
577                "SmolLM2-135M-Instruct-Q8_0.gguf",
578                144_811_360,
579                "5a1395716f7913741cc51d98581b9b1228d80987a9f7d3664106742eb06bba83",
580            ),
581            "Q8_0",
582            0.135,
583            0.135,
584            23_040,
585            8192,
586        ),
587        chat(gemma(crate::catalog::GEMMA_4_E2B), "Q4_0", 5.1, 2.0, 32_768, 8192),
588        chat(gemma(crate::catalog::GEMMA_4_E4B), "Q4_0", 8.0, 4.0, 65_536, 8192),
589        chat(
590            spec(
591                "qwen3-8b",
592                "Qwen3 8B (Q4_K_M)",
593                "unsloth/Qwen3-8B-GGUF",
594                "Qwen3-8B-Q4_K_M.gguf",
595                5_027_784_512,
596                "120307ba529eb2439d6c430d94104dabd578497bc7bfe7e322b5d9933b449bd4",
597            ),
598            "Q4_K_M",
599            8.2,
600            8.2,
601            147_456,
602            8192,
603        ),
604        chat(
605            spec(
606                "qwen3-14b",
607                "Qwen3 14B (Q4_K_M)",
608                "unsloth/Qwen3-14B-GGUF",
609                "Qwen3-14B-Q4_K_M.gguf",
610                9_001_753_984,
611                "5eaa0870bd81ed3b58a630a271234cfa604e43ffb3a19cd68e54a80dd9d52a66",
612            ),
613            "Q4_K_M",
614            14.8,
615            14.8,
616            163_840,
617            8192,
618        ),
619        chat(
620            spec(
621                "gpt-oss-20b",
622                "gpt-oss 20B (MXFP4)",
623                "ggml-org/gpt-oss-20b-GGUF",
624                "gpt-oss-20b-MXFP4.gguf",
625                12_109_566_624,
626                "27cd6c432c7672cb812a92f611cf3ba7bbc35928262bb1e1253ff4ee6ae35901",
627            ),
628            "MXFP4",
629            21.0,
630            3.6,
631            49_152,
632            8192,
633        ),
634        // Caveling 2 Mini (caveman-so, Apache-2.0): Inkling 2 Mini with its attention layers
635        // fine-tuned, 26B with 3.4B active. Only 4 of its 24 layers attend over the whole context,
636        // and three of the passes of its looped core keep a cache each (LOOPED_MINI_KV_BYTES, from
637        // the repo's `config.json`; the other 20 layers slide a 1024-token window, a fixed amount
638        // per slot that the figure leaves out).
639        // Sized at the context it runs at (CAVELING_CONTEXT), with its vision projector. The
640        // Q4_K_M file is the one pinned: the repo also holds an NVFP4 file, a draft model
641        // (`dspark-`) for speculative decoding and an `imatrix.gguf`, none of them a chat model
642        // to pull by default.
643        chat(
644            spec(
645                CAVELING_2_MINI,
646                "Caveling 2 Mini (Q4_K_M)",
647                "caveman-so/caveling-2-mini-GGUF",
648                "Caveling-2-Mini-Q4_K_M.gguf",
649                18_398_579_616,
650                "aab63d16dac44b32f57d53aa1982e9f18f130b88b992c10539f24feee87cd254",
651            ),
652            "Q4_K_M",
653            26.0,
654            3.4,
655            LOOPED_MINI_KV_BYTES,
656            CAVELING_CONTEXT,
657        ),
658        // Inkling 2 Mini (Thinking Machines, Apache-2.0): the model Caveling 2 Mini is fine-tuned
659        // from, and the same shape (26B, 3.4B active, looped core, vision). ggml-org's GGUF repo
660        // has BF16, Q8_0, NVFP4 and IQ4_NL files and an imatrix: the IQ4_NL file is the one pinned
661        // (17.6 GB, what the nodes run; its card lists a KL divergence of 0.0095 against BF16).
662        // Sized and launched like Caveling.
663        chat(
664            spec(
665                INKLING_2_MINI,
666                "Inkling 2 Mini (IQ4_NL)",
667                "ggml-org/Inkling-2-Mini-GGUF",
668                "Inkling-2-Mini-IQ4_NL.gguf",
669                17_627_940_768,
670                "cbdf3fa9dc50a4124977980f37da4f1fa764b0cfe800d275cd43d26ce2a81af4",
671            ),
672            "IQ4_NL",
673            26.0,
674            3.4,
675            LOOPED_MINI_KV_BYTES,
676            CAVELING_CONTEXT,
677        ),
678        chat(
679            spec(
680                "qwen3-30b-a3b",
681                "Qwen3 30B-A3B (Q4_K_M)",
682                "unsloth/Qwen3-30B-A3B-GGUF",
683                "Qwen3-30B-A3B-Q4_K_M.gguf",
684                18_556_686_912,
685                "9f1a24700a339b09c06009b729b5c809e0b64c213b8af5b711b3dbdfd0c5ba48",
686            ),
687            "Q4_K_M",
688            30.5,
689            3.3,
690            98_304,
691            8192,
692        ),
693        chat(
694            spec(
695                "qwen3-32b",
696                "Qwen3 32B (Q4_K_M)",
697                "unsloth/Qwen3-32B-GGUF",
698                "Qwen3-32B-Q4_K_M.gguf",
699                19_762_150_048,
700                "8df67573b2c23484e02ec7af295e39bed7ee774f3771d5fda2978265b59370e7",
701            ),
702            "Q4_K_M",
703            32.8,
704            32.8,
705            262_144,
706            8192,
707        ),
708        // Chat checkpoints for vLLM (Hugging Face repos, not GGUF files: `is_gguf` is false, so a
709        // plan never picks them). Sizes, SHA-256 and the commit from the Hugging Face API,
710        // 2026-12-02; the commits are the snapshots the Ymir nodes run.
711        //
712        // Qwen3-VL 8B Instruct (Qwen, Apache-2.0): 8.77B parameters (the shards' bytes at 2 bytes
713        // each), 36 layers x 8 KV heads x (128 + 128) x 2 bytes, from `config.json`. Four shards.
714        // Sized at 32768 tokens.
715        chat(
716            spec(
717                QWEN3_VL_8B,
718                "Qwen3-VL 8B Instruct (BF16, vLLM)",
719                "Qwen/Qwen3-VL-8B-Instruct",
720                "model-00001-of-00004.safetensors",
721                4_902_275_944,
722                "d5d0aef0eb170fc7453a296c43c0849a56f510555d3588e4fd662bb35490aefa",
723            ),
724            "BF16",
725            8.77,
726            8.77,
727            36 * 8 * 256 * 2,
728            32_768,
729        ),
730        // Qwen3.8 27B NVFP4 (RadixArk's quantization of Qwen3.8-27B for NVIDIA Blackwell, Apache-2.0;
731        // its card names SGLang, Ymir serves it on vLLM): dense, 27B. One layer in four attends over
732        // the whole context (`full_attention_interval` 4 of 64 layers, 4 KV heads x (256 + 256) x
733        // 2 bytes), the rest keep a fixed-size state. Three shards. Sized at 131072 tokens.
734        chat(
735            spec(
736                QWEN3_8_27B_NVFP4,
737                "Qwen3.8 27B (NVFP4, vLLM, Blackwell)",
738                "RadixArk/Qwen3.8-27B-NVFP4",
739                "model-00001-of-00003.safetensors",
740                9_965_652_544,
741                "fbcdb5ba1cdda462b5f38592d071e772c4d398afea61a0aa9188b32d1a239a79",
742            ),
743            "NVFP4",
744            27.0,
745            27.0,
746            16 * 4 * 512 * 2,
747            131_072,
748        ),
749        CatalogEntry {
750            spec: spec(
751                "qwen3-embedding-0.6b",
752                "Qwen3 Embedding 0.6B (Q8_0)",
753                "Qwen/Qwen3-Embedding-0.6B-GGUF",
754                "Qwen3-Embedding-0.6B-Q8_0.gguf",
755                639_150_592,
756                "06507c7b42688469c4e7298b0a1e16deff06caf291cf0a5b278c308249c3e439",
757            ),
758            purpose: Purpose::Embedding,
759            quant: "Q8_0".into(),
760            params_b: 0.6,
761            active_params_b: 0.6,
762            kv_bytes_per_token: 114_688,
763            context: 2048,
764        },
765        // Mistral's Voxtral Mini 3B (Apache-2.0): a Whisper-style audio encoder in front of a 3B
766        // decoder, transcription in eight languages; 30 seconds of audio cost 187 tokens in
767        // llama.cpp, so 16K of context holds about 20 minutes with its transcript.
768        CatalogEntry {
769            spec: spec(
770                VOXTRAL_MINI_3B,
771                "Voxtral Mini 3B speech to text (Q4_K_M)",
772                "ggml-org/Voxtral-Mini-3B-2507-GGUF",
773                "Voxtral-Mini-3B-2507-Q4_K_M.gguf",
774                2_473_001_920,
775                "4705be8ec22ca23d12632f4b4a3691faa95917d90a06d3cf3c3ec0e91958f1a8",
776            ),
777            purpose: Purpose::Transcribe,
778            quant: "Q4_K_M".into(),
779            params_b: 4.7,
780            active_params_b: 4.7,
781            kv_bytes_per_token: 122_880,
782            context: 16_384,
783        },
784        // Speech to text on vLLM (checkpoints from the Hub, `vllm[audio]`; sizes, SHA-256 and the
785        // commit from the Hugging Face API, 2026-12-02). The context each is sized at is an
786        // assumption for the budget, like the speech entries'.
787        //
788        // Qwen3-ASR 1.7B (Apache-2.0): 2.35B parameters with its audio encoder; the 28-layer
789        // decoder keeps 8 KV heads x (128 + 128), from its `config.json`. Two shards.
790        CatalogEntry {
791            spec: spec(
792                QWEN3_ASR_1_7B,
793                "Qwen3-ASR 1.7B speech to text (BF16, vLLM)",
794                "Qwen/Qwen3-ASR-1.7B",
795                "model-00001-of-00002.safetensors",
796                4_220_320_824,
797                "a4cd1f1a04d90b757dc7f7dd26254e69a013b19e80efe590a83c6a3bde8608d6",
798            ),
799            purpose: Purpose::Transcribe,
800            quant: "BF16".into(),
801            params_b: 2.35,
802            active_params_b: 2.35,
803            kv_bytes_per_token: 28 * 8 * 256 * 2,
804            context: 8192,
805        },
806        // Whisper large-v3-turbo (OpenAI, MIT): 0.81B parameters, a 4-layer decoder of 20 heads x
807        // 64 (self-attention 4 x 20 x (64 + 64) x 2 bytes per token). Its cross-attention keeps
808        // 1500 encoder positions of the same size per request, counted as 1500 more positions
809        // on top of the 448 it decodes.
810        CatalogEntry {
811            spec: spec(
812                WHISPER_LARGE_V3_TURBO,
813                "Whisper large-v3-turbo speech to text (FP16, vLLM)",
814                "openai/whisper-large-v3-turbo",
815                "model.safetensors",
816                1_617_824_864,
817                "542566a422ae4f3fd23f1ba11add198fca01bbf82e66e6a2857b3f608b1eb9d1",
818            ),
819            purpose: Purpose::Transcribe,
820            quant: "F16".into(),
821            params_b: 0.81,
822            active_params_b: 0.81,
823            kv_bytes_per_token: 4 * 20 * 128 * 2,
824            context: 448 + 1500,
825        },
826        // Cohere Transcribe 03-2026 (Apache-2.0; the repo is gated): 2.07B parameters, a
827        // Conformer encoder and a "lightweight" Transformer decoder whose dimensions are in
828        // the gated `config.json`, which this entry was not built from: its KV cost is
829        // sized like Qwen3-ASR's decoder (an upper bound for a lightweight one).
830        CatalogEntry {
831            spec: spec(
832                COHERE_TRANSCRIBE_03_2026,
833                "Cohere Transcribe 03-2026 speech to text (BF16, vLLM, gated)",
834                "CohereLabs/cohere-transcribe-03-2026",
835                "model.safetensors",
836                4_131_862_976,
837                "987bd3e141c7bfdb5a78f5db11397ee7737308357e6cc0a3f36a4979b158137a",
838            ),
839            purpose: Purpose::Transcribe,
840            quant: "BF16".into(),
841            params_b: 2.07,
842            active_params_b: 2.07,
843            kv_bytes_per_token: 28 * 8 * 256 * 2,
844            context: 4096,
845        },
846        // Text to speech (Apache-2.0 unless noted). KV per token from each config or GGUF header
847        // (layers x KV heads x (key + value dim) x 2 bytes). Speech runs one utterance at a
848        // time, and the context these entries are sized at (4096: a prompt plus minutes of
849        // audio frames; Drama 3's documented cap in llama.cpp) is an assumption for the budget,
850        // not a limit the model reports.
851        //
852        // Qwen3-TTS (Qwen, 12.5 Hz codec): 28 layers x 8 KV heads x (128 + 128) for both sizes.
853        // ggml-org converted only the 1.7B Base checkpoint; the others are the Qwen repos that
854        // vLLM-Omni serves (BF16 safetensors, plus the shared speech tokenizer).
855        speaker_entry(
856            spec(
857                QWEN3_TTS_0_6B_CUSTOMVOICE,
858                "Qwen3-TTS 0.6B CustomVoice (BF16, vLLM-Omni)",
859                "Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice",
860                "model.safetensors",
861                1_811_626_576,
862                "bc3c7e785eb961179c25450d1acff03f839e0002f2f3a5aeb67b5735c0fa2adb",
863            ),
864            "BF16",
865            0.6,
866            0.6,
867            114_688,
868            4096,
869        ),
870        speaker_entry(
871            spec(
872                QWEN3_TTS_0_6B_BASE,
873                "Qwen3-TTS 0.6B Base, voice cloning (BF16, vLLM-Omni)",
874                "Qwen/Qwen3-TTS-12Hz-0.6B-Base",
875                "model.safetensors",
876                1_829_344_272,
877                "180b3b10eb1c9f1b4db7806d5475bae3071c0243c299d49926bab1da3b6946f6",
878            ),
879            "BF16",
880            0.6,
881            0.6,
882            114_688,
883            4096,
884        ),
885        speaker_entry(
886            spec(
887                QWEN3_TTS_1_7B_CUSTOMVOICE,
888                "Qwen3-TTS 1.7B CustomVoice (BF16, vLLM-Omni)",
889                "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice",
890                "model.safetensors",
891                3_833_402_552,
892                "38b1d5971bdbd982b561cccec982669a53b0537c3cf5e9bd4778ed07bb2f5137",
893            ),
894            "BF16",
895            1.7,
896            1.7,
897            114_688,
898            4096,
899        ),
900        speaker_entry(
901            spec(
902                QWEN3_TTS_1_7B_VOICEDESIGN,
903                "Qwen3-TTS 1.7B VoiceDesign (BF16, vLLM-Omni)",
904                "Qwen/Qwen3-TTS-12Hz-1.7B-VoiceDesign",
905                "model.safetensors",
906                3_833_402_552,
907                "391e8db219f292c515297cdceeb43e4eae67cdde35fa57e79a6a8a532fca0522",
908            ),
909            "BF16",
910            1.7,
911            1.7,
912            114_688,
913            4096,
914        ),
915        speaker_entry(
916            spec(
917                QWEN3_TTS_1_7B_BASE,
918                "Qwen3-TTS 1.7B Base, voice cloning (Q8_0)",
919                "ggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF",
920                "Qwen3-TTS-12Hz-1.7B-Base-Q8_0.gguf",
921                1_847_874_400,
922                "ac7931aeb2e7aad1a6ed6602d353a5679c9d096b18ce8204ac730a8408d572e1",
923            ),
924            "Q8_0",
925            1.7,
926            1.7,
927            114_688,
928            4096,
929        ),
930        // Kokoro 82M (hexgrad): not autoregressive; 12 layers x 12 heads x (64 + 64) over its
931        // 512-phoneme context.
932        speaker_entry(
933            spec(
934                KOKORO_82M,
935                "Kokoro 82M (F32)",
936                "ggml-org/Kokoro-82M-GGUF",
937                "Kokoro-82M-F32.gguf",
938                61_774_240,
939                "be19298184f1a2577eb20e4689f1e2b315cbf474c39e113f192991fef3c85c6e",
940            ),
941            "F32",
942            0.082,
943            0.082,
944            36_864,
945            512,
946        ),
947        // VoxCPM2 (OpenBMB, 2B): MiniCPM4 backbone, 28 layers x 2 KV heads x (128 + 128), plus
948        // the projector's residual LM (12 layers x 2 x (64 + 64)), which keeps one context per
949        // utterance.
950        speaker_entry(
951            spec(
952                VOXCPM2,
953                "VoxCPM2, voice design and cloning (Q8_0)",
954                "ggml-org/VoxCPM2-GGUF",
955                "VoxCPM2-Q8_0.gguf",
956                1_565_764_064,
957                "b09cd3afab454f23922632fd474aa0d5d667e128e8bf36e81e77ec7e71fac64b",
958            ),
959            "Q8_0",
960            2.0,
961            2.0,
962            28_672 + 6_144,
963            4096,
964        ),
965        // Fish Audio Drama 3 (Fish Audio Community License): Qwen3.5-MoE, 35B with 3B active;
966        // 10 of its 40 layers attend (the rest are recurrent), 2 KV heads x (256 + 256), plus
967        // the projector's codebook tower (13 layers x 2 x (128 + 128)), which keeps the whole
968        // sequence, prompt and frames, in its 4096 positions.
969        speaker_entry(
970            spec(
971                FISH_AUDIO_DRAMA_3,
972                "Fish Audio Drama 3, multi-speaker (Q4_K_M)",
973                "ggml-org/drama-3-GGUF",
974                "drama-3-Q4_K_M.gguf",
975                20_556_053_760,
976                "5b727d669a7a555713403b7f6d744402dafd6fd37154f0fe834a5310548a8b34",
977            ),
978            "Q4_K_M",
979            35.0,
980            3.0,
981            20_480 + 13_312,
982            4096,
983        ),
984    ]
985}
986
987/// The catalog entries for `purpose`, in catalog order.
988pub fn by_purpose(purpose: Purpose) -> Vec<CatalogEntry> {
989    catalog().into_iter().filter(|e| e.purpose == purpose).collect()
990}
991
992/// The speech-to-text model ([`Purpose::Transcribe`]) that fits `budget` with one request at
993/// a time, projector included, if any: the largest GGUF entry (llama.cpp runs it, and
994/// [`download`](crate::download()) fetches it), as [`speaker`] does; the checkpoints vLLM serves
995/// (0.5.6) are for an app that runs vLLM and picks one itself ([`by_purpose`]). [`plan`] never
996/// proposes one: transcription is optional, so an app adds it when it wants soundtracks turned
997/// into text.
998pub fn transcriber(budget: &Budget) -> Option<CatalogEntry> {
999    by_purpose(Purpose::Transcribe)
1000        .into_iter()
1001        .filter(|e| e.is_gguf() && e.footprint(1) <= budget.usable_bytes)
1002        .max_by(|a, b| a.params_b.total_cmp(&b.params_b))
1003}
1004
1005/// A text-to-speech model ([`Purpose::Speak`]) that fits `budget` with one request at a time,
1006/// projector included: the largest GGUF entry (llama.cpp runs it, and [`download`](crate::download())
1007/// fetches it) whose license doesn't restrict use, if any. [`plan`] never proposes one: speech
1008/// is optional, so an app adds it when it wants text read aloud. Since 0.5.5.
1009pub fn speaker(budget: &Budget) -> Option<CatalogEntry> {
1010    by_purpose(Purpose::Speak)
1011        .into_iter()
1012        .filter(|e| e.is_gguf() && !e.restricted() && e.footprint(1) <= budget.usable_bytes)
1013        .max_by(|a, b| a.params_b.total_cmp(&b.params_b))
1014}
1015
1016/// The license that restricts downloading `spec`, if any: the license of a restricted catalog
1017/// entry ([`CatalogEntry::restricted`]) whose model or projector `spec` is (by id), or whose repo
1018/// (or the repo its weights come from) `spec` downloads from. [`download`](crate::download())
1019/// refuses such a file without [`Consent::accepting_license`](crate::Consent::accepting_license).
1020/// Since 0.5.5.
1021pub fn restricted_license(spec: &ModelSpec) -> Option<&'static str> {
1022    catalog()
1023        .into_iter()
1024        .filter(CatalogEntry::restricted)
1025        .find(|e| {
1026            e.spec.id == spec.id
1027                || e.projector().is_some_and(|p| p.id == spec.id)
1028                || e.license_repos().iter().any(|r| r.eq_ignore_ascii_case(&spec.repo))
1029        })
1030        .and_then(|e| e.license())
1031}
1032
1033/// Whether downloading `spec` needs a token: it is the file of a gated catalog entry
1034/// ([`CatalogEntry::gated`]) by id, or comes from its repo. [`download`](crate::download())
1035/// refuses such a file, before any request, when the store has no token. Since 0.5.6.
1036pub fn gated(spec: &ModelSpec) -> bool {
1037    catalog().iter().filter(|e| e.gated()).any(|e| e.spec.id == spec.id || e.spec.repo.eq_ignore_ascii_case(&spec.repo))
1038}
1039
1040/// The catalog entry with this id.
1041pub fn find(id: &str) -> Option<CatalogEntry> {
1042    catalog().into_iter().find(|e| e.spec.id == id)
1043}
1044
1045/// How much memory models may use on this node.
1046#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1047pub struct Budget {
1048    /// VRAM of the first GPU, or system memory on unified and CPU-only machines.
1049    pub pool_bytes: u64,
1050    /// Kept for the OS (unified and CPU-only only).
1051    pub reserve_bytes: u64,
1052    pub usable_bytes: u64,
1053}
1054
1055/// 85% of VRAM, or 85% of unified memory after the OS reserve (default: an eighth of RAM, at least
1056/// 4 GiB). `memory_budget` overrides the result; `reserve` overrides the reserve.
1057pub fn budget(hw: &Hardware, memory_budget: Option<u64>, reserve: Option<u64>) -> Budget {
1058    let unified = hw.unified();
1059    let pool_bytes = if unified { hw.ram_bytes } else { hw.gpus.first().map(|g| g.memory_bytes).unwrap_or(hw.ram_bytes) };
1060    let reserve_bytes = if unified { reserve.unwrap_or_else(|| (hw.ram_bytes / 8).max(4 * GIB)) } else { 0 };
1061    let usable = pool_bytes.saturating_sub(reserve_bytes) / 100 * 85;
1062    Budget { pool_bytes, reserve_bytes, usable_bytes: memory_budget.unwrap_or(usable) }
1063}
1064
1065/// What setup proposes for this node.
1066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1067pub struct Plan {
1068    pub budget: Budget,
1069    pub main: Option<CatalogEntry>,
1070    pub standin: Option<CatalogEntry>,
1071    pub embedding: Option<CatalogEntry>,
1072    /// Concurrent requests each chat model is sized for.
1073    pub slots: u32,
1074    pub notes: Vec<String>,
1075}
1076
1077/// Picks the largest chat model (a GGUF file; the vLLM checkpoints are for an app that runs vLLM and picks one itself) that fits with its KV budget, a Gemma 4 stand-in and the embedding
1078/// model. CPU-only machines only get models with at most 4B active parameters, so answers stay
1079/// usable.
1080pub fn plan(hw: &Hardware, budget: Budget) -> Plan {
1081    let slots = 2;
1082    let cpu_only = hw.accel() == Accel::Cpu;
1083    let mut notes = Vec::new();
1084    let all = catalog();
1085    let fits = |e: &&CatalogEntry| e.footprint(slots) <= budget.usable_bytes;
1086    let main = all
1087        .iter()
1088        .filter(|e| e.purpose == Purpose::Chat && e.is_gguf() && e.spec.id != "smollm2-135m")
1089        .filter(|e| !cpu_only || e.active_params_b <= 4.0)
1090        .filter(fits)
1091        .max_by(|a, b| a.params_b.total_cmp(&b.params_b))
1092        .cloned();
1093    if cpu_only {
1094        notes.push("CPU only: limited to models with at most 4B active parameters".into());
1095    }
1096    if main.is_none() {
1097        notes.push("no catalog chat model fits this budget; add a smaller GGUF model".into());
1098    }
1099    let standin_id = if budget.usable_bytes >= 16 * GIB { crate::catalog::GEMMA_4_E4B } else { crate::catalog::GEMMA_4_E2B };
1100    let standin = all.iter().find(|e| e.spec.id == standin_id).filter(fits).filter(|e| main.as_ref().is_none_or(|m| m.spec.id != e.spec.id)).cloned();
1101    let embedding = all.iter().find(|e| e.purpose == Purpose::Embedding).filter(|e| e.footprint(1) <= budget.usable_bytes).cloned();
1102    Plan { budget, main, standin, embedding, slots, notes }
1103}
1104
1105#[cfg(test)]
1106mod tests {
1107    use super::*;
1108    use crate::hw::{Gpu, parse_nvidia_smi};
1109
1110    fn box_with(gpus: Vec<Gpu>, ram_gib: u64) -> Hardware {
1111        Hardware { os: "linux".into(), arch: "x86_64".into(), cpu_threads: 16, ram_bytes: ram_gib * GIB, gpus }
1112    }
1113
1114    #[test]
1115    fn rtx_3060_gets_an_8b() {
1116        let hw = box_with(parse_nvidia_smi("NVIDIA GeForce RTX 3060, 12288, 8.6, 615.78.08", 62 * GIB), 62);
1117        let b = budget(&hw, None, None);
1118        assert_eq!(b.pool_bytes, 12 * GIB);
1119        let p = plan(&hw, b);
1120        assert_eq!(p.main.unwrap().id(), "qwen3-8b");
1121        assert_eq!(p.standin.unwrap().id(), "gemma-4-e2b");
1122        assert!(p.embedding.is_some());
1123    }
1124
1125    #[test]
1126    fn spark_gets_a_big_model() {
1127        let hw = box_with(parse_nvidia_smi("NVIDIA GB10, [N/A], 12.1, 580.95.05", 128 * GIB), 128);
1128        let b = budget(&hw, None, None);
1129        assert_eq!(b.reserve_bytes, 16 * GIB);
1130        let p = plan(&hw, b);
1131        assert_eq!(p.main.unwrap().id(), "qwen3-32b");
1132        assert_eq!(p.standin.unwrap().id(), "gemma-4-e4b");
1133    }
1134
1135    #[test]
1136    fn cpu_box_prefers_few_active_params() {
1137        let hw = box_with(Vec::new(), 62);
1138        let p = plan(&hw, budget(&hw, None, None));
1139        assert_eq!(p.main.unwrap().id(), "qwen3-30b-a3b");
1140    }
1141
1142    #[test]
1143    fn tiny_box_gets_no_main() {
1144        let hw = box_with(Vec::new(), 4);
1145        let p = plan(&hw, budget(&hw, Some(GIB), None));
1146        assert!(p.main.is_none());
1147        assert!(!p.notes.is_empty());
1148    }
1149
1150    #[test]
1151    fn override_budget() {
1152        let hw = box_with(Vec::new(), 64);
1153        assert_eq!(budget(&hw, Some(10 * GIB), None).usable_bytes, 10 * GIB);
1154        assert_eq!(budget(&hw, None, Some(14 * GIB)).reserve_bytes, 14 * GIB);
1155    }
1156
1157    #[test]
1158    fn transcribe_is_a_purpose_of_its_own() {
1159        assert_eq!(serde_json::to_string(&Purpose::Transcribe).unwrap(), "\"transcribe\"");
1160        for p in Purpose::ALL {
1161            assert_eq!(serde_json::from_str::<Purpose>(&format!("\"{p}\"")).unwrap(), p);
1162            assert_eq!(Purpose::parse(p.as_str()), Some(p));
1163        }
1164        assert_eq!(Purpose::parse("speech"), None);
1165        // Stored entries from before the variant still read.
1166        assert_eq!(serde_json::from_str::<Purpose>("\"chat\"").unwrap(), Purpose::Chat);
1167    }
1168
1169    #[test]
1170    fn the_catalog_has_a_pinned_speech_to_text_model() {
1171        let stt: Vec<_> = by_purpose(Purpose::Transcribe).into_iter().filter(CatalogEntry::is_gguf).collect();
1172        assert_eq!(stt.len(), 1);
1173        let v = &stt[0];
1174        assert_eq!((v.id(), v.quant.as_str(), v.context), (VOXTRAL_MINI_3B, "Q4_K_M", 16_384));
1175        assert!(v.transcribes());
1176        assert_eq!(find(VOXTRAL_MINI_3B).as_ref(), Some(v));
1177        assert_eq!(v.spec.repo, "ggml-org/Voxtral-Mini-3B-2507-GGUF");
1178        assert_eq!(v.spec.sha256.as_deref().map(str::len), Some(64));
1179        let p = v.projector().expect("Voxtral needs its audio encoder");
1180        assert_eq!((p.repo.as_str(), p.file.as_str(), p.size), (v.spec.repo.as_str(), "mmproj-Voxtral-Mini-3B-2507-Q8_0.gguf", 715_714_080));
1181        assert!(p.sha256.as_deref().is_some_and(|h| h.len() == 64 && h.chars().all(|c| c.is_ascii_hexdigit())));
1182        assert_ne!(p.file, v.spec.file);
1183        // 30 layers x 8 KV heads x (128 + 128) x 2 bytes.
1184        assert_eq!(v.kv_bytes_per_token, 30 * 8 * 256 * 2);
1185        // The projector counts in the footprint; text models have none.
1186        let without = (v.spec.size + v.kv_bytes_per_token * 16_384) * 11 / 10;
1187        assert!(v.footprint(1) > without);
1188        assert!(
1189            catalog()
1190                .iter()
1191                .filter(|e| !e.transcribes() && !e.speaks() && !matches!(e.id(), CAVELING_2_MINI | INKLING_2_MINI))
1192                .all(|e| e.projector().is_none())
1193        );
1194        // Catalog ids stay unique.
1195        let mut ids: Vec<_> = catalog().iter().map(|e| e.id().to_string()).collect();
1196        ids.sort();
1197        ids.dedup();
1198        assert_eq!(ids.len(), catalog().len());
1199    }
1200
1201    #[test]
1202    fn plans_never_pick_the_transcriber_and_it_fits_on_its_own() {
1203        for (gpus, ram) in [(parse_nvidia_smi("NVIDIA GeForce RTX 3060, 12288, 8.6, 615.78.08", 62 * GIB), 62), (Vec::new(), 62), (Vec::new(), 8)] {
1204            let hw = box_with(gpus, ram);
1205            let p = plan(&hw, budget(&hw, None, None));
1206            for e in [&p.main, &p.standin, &p.embedding].into_iter().flatten() {
1207                assert!(!e.transcribes() && !e.speaks(), "{} in a plan", e.id());
1208            }
1209        }
1210        let hw = box_with(Vec::new(), 62);
1211        assert_eq!(transcriber(&budget(&hw, None, None)).map(|e| e.spec.id), Some(VOXTRAL_MINI_3B.into()));
1212        assert_eq!(transcriber(&budget(&hw, Some(GIB), None)), None, "too small a budget");
1213        assert!(by_purpose(Purpose::Embedding).iter().all(|e| e.purpose == Purpose::Embedding));
1214    }
1215
1216    #[test]
1217    fn speak_is_a_purpose_of_its_own() {
1218        assert_eq!(serde_json::to_string(&Purpose::Speak).unwrap(), "\"speak\"");
1219        assert_eq!(Purpose::parse("speak"), Some(Purpose::Speak));
1220        assert_eq!(Purpose::Speak.to_string(), "speak");
1221        assert_eq!(Purpose::parse("tts"), None);
1222    }
1223
1224    #[test]
1225    fn the_catalog_has_cited_speech_models() {
1226        let ids: Vec<_> = by_purpose(Purpose::Speak).iter().map(|e| e.id().to_string()).collect();
1227        assert_eq!(
1228            ids,
1229            [
1230                QWEN3_TTS_0_6B_CUSTOMVOICE,
1231                QWEN3_TTS_0_6B_BASE,
1232                QWEN3_TTS_1_7B_CUSTOMVOICE,
1233                QWEN3_TTS_1_7B_VOICEDESIGN,
1234                QWEN3_TTS_1_7B_BASE,
1235                KOKORO_82M,
1236                VOXCPM2,
1237                FISH_AUDIO_DRAMA_3
1238            ]
1239        );
1240        let hex = |h: &Option<String>| h.as_deref().is_some_and(|h| h.len() == 64 && h.chars().all(|c| c.is_ascii_hexdigit()));
1241        for e in by_purpose(Purpose::Speak) {
1242            assert!(e.speaks() && !e.transcribes());
1243            assert!(hex(&e.spec.sha256), "{} pinned", e.id());
1244            let s = e.speech().unwrap_or_else(|| panic!("{} has a profile", e.id()));
1245            assert!(s.sample_rate.is_some() && !s.formats.is_empty() && s.languages.is_some(), "{}", e.id());
1246            assert!(e.license().is_some());
1247            if e.is_gguf() {
1248                let p = e.projector().unwrap_or_else(|| panic!("{} needs its projector", e.id()));
1249                assert!(hex(&p.sha256) && p.file.starts_with("mmproj-") && p.repo == e.spec.repo);
1250                assert_eq!(s.formats, [crate::speech::AudioFormat::Wav, crate::speech::AudioFormat::Pcm16], "llama-server's formats");
1251                assert!(e.footprint(1) > (e.spec.size + p.size) * 11 / 10);
1252            } else {
1253                assert!(e.projector().is_none());
1254                assert!(e.spec.repo.starts_with("Qwen/") && e.spec.file == "model.safetensors");
1255                assert!(e.footprint(1) > (e.spec.size + QWEN3_TTS_TOKENIZER_BYTES) * 11 / 10, "the speech tokenizer counts");
1256                assert!(s.formats.len() == 5 && s.speed, "vLLM-Omni's formats and speed");
1257            }
1258        }
1259        // Each Qwen3-TTS checkpoint does one thing.
1260        let q = |id| find(id).unwrap().speech().unwrap();
1261        assert_eq!(q(QWEN3_TTS_1_7B_CUSTOMVOICE).presets.as_ref().map(Vec::len), Some(9));
1262        assert!(q(QWEN3_TTS_1_7B_CUSTOMVOICE).instructions && !q(QWEN3_TTS_0_6B_CUSTOMVOICE).instructions);
1263        assert!(q(QWEN3_TTS_1_7B_VOICEDESIGN).design && q(QWEN3_TTS_1_7B_VOICEDESIGN).clone.is_none());
1264        assert_eq!(q(QWEN3_TTS_0_6B_BASE).clone, Some(CloneMode::AudioAndText));
1265        assert_eq!(q(QWEN3_TTS_1_7B_BASE).clone, Some(CloneMode::Audio), "ggml-org's projector has the speaker encoder only");
1266        let k = q(KOKORO_82M);
1267        assert_eq!((k.presets.as_ref().map(Vec::len), k.presets.as_ref().and_then(|p| p.first()).map(String::as_str)), (Some(54), Some("af_heart")));
1268        assert!(k.raw && k.speed);
1269        assert!(q(VOXCPM2).design && q(VOXCPM2).clone == Some(CloneMode::Audio));
1270        assert_eq!(q(VOXCPM2).languages.map(|l| l.len()), Some(30));
1271        let d = q(FISH_AUDIO_DRAMA_3);
1272        assert_eq!((d.script_speakers, d.clone, d.sample_rate), (Some(16), None, Some(44_100)));
1273        assert_eq!(d.languages.map(|l| l.len()), Some(83));
1274        // Only Drama 3 is restricted, and its profile names the license.
1275        let drama = find(FISH_AUDIO_DRAMA_3).unwrap();
1276        assert!(drama.restricted() && drama.license() == Some(crate::speech::FISH_AUDIO_COMMUNITY));
1277        assert_eq!(d.license.as_deref(), Some(crate::speech::FISH_AUDIO_COMMUNITY));
1278        assert_eq!(catalog().iter().filter(|e| e.restricted()).count(), 1);
1279        assert!(catalog().iter().filter(|e| !e.speaks()).all(|e| e.speech().is_none()));
1280    }
1281
1282    #[test]
1283    fn a_speaker_that_fits_and_never_a_restricted_one() {
1284        let b = |usable_bytes| Budget { pool_bytes: usable_bytes, reserve_bytes: 0, usable_bytes };
1285        assert_eq!(speaker(&b(128 * GIB)).map(|e| e.spec.id), Some(VOXCPM2.into()), "never Drama 3, however big");
1286        assert_eq!(speaker(&b(GIB * 7 / 2)).map(|e| e.spec.id), Some(QWEN3_TTS_1_7B_BASE.into()));
1287        assert_eq!(speaker(&b(GIB)).map(|e| e.spec.id), Some(KOKORO_82M.into()));
1288        assert_eq!(speaker(&b(100 << 20)), None);
1289        assert!(by_purpose(Purpose::Speak).iter().all(|e| e.footprint(1) > 0));
1290    }
1291
1292    #[test]
1293    fn downloads_under_a_restricted_license() {
1294        let drama = find(FISH_AUDIO_DRAMA_3).unwrap();
1295        let lic = Some(crate::speech::FISH_AUDIO_COMMUNITY);
1296        assert_eq!(restricted_license(&drama.spec), lic);
1297        assert_eq!(restricted_license(&drama.projector().unwrap()), lic);
1298        // A hand-built spec from the same repos, under any id.
1299        let mut other = drama.spec.clone();
1300        other.id = "my-drama".into();
1301        other.file = "drama-3-Q8_0.gguf".into();
1302        assert_eq!(restricted_license(&other), lic);
1303        other.repo = "FishAudio/Drama-3".into();
1304        assert_eq!(restricted_license(&other), lic);
1305        for e in catalog().iter().filter(|e| e.spec.id != FISH_AUDIO_DRAMA_3) {
1306            assert_eq!(restricted_license(&e.spec), None, "{}", e.id());
1307        }
1308    }
1309
1310    fn is_sha256(h: &Option<String>) -> bool {
1311        h.as_deref().is_some_and(|h| h.len() == 64 && h.chars().all(|c| c.is_ascii_hexdigit() && !c.is_ascii_uppercase()))
1312    }
1313
1314    #[test]
1315    fn caveling_is_a_pinned_chat_model_with_a_vision_projector() {
1316        let e = find(CAVELING_2_MINI).expect("in the catalog");
1317        assert_eq!((e.purpose, e.quant.as_str(), e.params_b, e.active_params_b), (Purpose::Chat, "Q4_K_M", 26.0, 3.4));
1318        assert!(e.is_gguf() && !e.speaks() && !e.transcribes() && !e.restricted() && !e.gated() && !e.is_sharded());
1319        assert_eq!(e.spec.repo, "caveman-so/caveling-2-mini-GGUF");
1320        // The Q4_K_M file, never the repo's NVFP4 file, its draft model or its importance matrix.
1321        assert_eq!((e.spec.file.as_str(), e.spec.size), ("Caveling-2-Mini-Q4_K_M.gguf", 18_398_579_616));
1322        assert!(!e.spec.file.to_ascii_lowercase().contains("dspark") && !e.spec.file.starts_with("imatrix"));
1323        assert!(is_sha256(&e.spec.sha256));
1324        let p = e.projector().expect("vision encoder");
1325        assert_eq!((p.repo.as_str(), p.file.as_str(), p.size), (e.spec.repo.as_str(), "mmproj-Caveling-2-Mini-Q8_0.gguf", 345_911_360));
1326        assert!(is_sha256(&p.sha256));
1327        assert_eq!(e.license(), Some("apache-2.0"));
1328        assert_eq!(e.revision(), Some("ec4b4b4114cf8375abc1cf42d6c41971b778e2ba"));
1329        // llama-server's own arguments, the context and layers it runs with.
1330        assert_eq!(e.engine_args(), ["-fa", "on", "--jinja"]);
1331        assert_eq!((e.launch_context(), e.launch_gpu_layers()), (Some(346_112), Some(99)));
1332        assert_eq!(e.context, 346_112);
1333        // 4 full-attention layers, two of them in the looped core (three passes, a cache each):
1334        // 8 layer caches x 8 KV heads x (128 + 128) x 2 bytes, over the whole context.
1335        assert_eq!(e.kv_bytes_per_token, 8 * 8 * 256 * 2);
1336        let kv = e.kv_bytes_per_token * 346_112;
1337        let want = (e.spec.size + p.size + kv) * 11 / 10;
1338        assert!(e.footprint(1).abs_diff(want) < 16, "{} vs {want}", e.footprint(1));
1339        // The entries from before carry no launch values.
1340        let gemma = find(crate::catalog::GEMMA_4_E4B).unwrap();
1341        assert!(
1342            gemma.engine_args().is_empty() && gemma.launch_context().is_none() && gemma.launch_gpu_layers().is_none() && gemma.revision().is_none()
1343        );
1344    }
1345
1346    #[test]
1347    fn caveling_never_changes_what_a_plan_picks() {
1348        // Not on a CPU box with plenty of memory, nor on a big GPU: a bigger model fits first.
1349        for (gpus, ram) in [(Vec::new(), 62), (Vec::new(), 256), (parse_nvidia_smi("NVIDIA GB10, [N/A], 12.1, 580.95.05", 128 * GIB), 128)] {
1350            let hw = box_with(gpus, ram);
1351            let p = plan(&hw, budget(&hw, None, None));
1352            assert_ne!(p.main.unwrap().id(), CAVELING_2_MINI);
1353        }
1354    }
1355
1356    #[test]
1357    fn inkling_is_the_pinned_iq4_nl_file_with_the_same_launch_values_as_caveling() {
1358        let e = find(INKLING_2_MINI).expect("in the catalog");
1359        let c = find(CAVELING_2_MINI).unwrap();
1360        assert_eq!((e.purpose, e.quant.as_str(), e.params_b, e.active_params_b), (Purpose::Chat, "IQ4_NL", 26.0, 3.4));
1361        assert!(e.is_gguf() && !e.speaks() && !e.transcribes() && !e.restricted() && !e.gated() && !e.is_sharded());
1362        assert_eq!(e.spec.repo, "ggml-org/Inkling-2-Mini-GGUF");
1363        // The IQ4_NL file the nodes run, not the repo's BF16, Q8_0 or NVFP4 file nor its importance matrix.
1364        assert_eq!((e.spec.file.as_str(), e.spec.size), ("Inkling-2-Mini-IQ4_NL.gguf", 17_627_940_768));
1365        assert_eq!(e.spec.sha256.as_deref(), Some("cbdf3fa9dc50a4124977980f37da4f1fa764b0cfe800d275cd43d26ce2a81af4"));
1366        let p = e.projector().expect("vision encoder");
1367        assert_eq!((p.repo.as_str(), p.file.as_str(), p.size), (e.spec.repo.as_str(), "mmproj-Inkling-2-Mini-Q8_0.gguf", 345_910_944));
1368        assert_eq!(p.sha256.as_deref(), Some("233287272ec5ac39b4168677aba54a4c024f202410f5629fac1830e1059f8abb"));
1369        assert_eq!(e.license(), Some("apache-2.0"));
1370        assert_eq!(e.revision(), Some("0bdc580634ceac4c4d921f452777bf44228de9af"));
1371        assert_eq!(e.engine_args(), ["-fa", "on", "--jinja"]);
1372        assert_eq!((e.launch_context(), e.launch_gpu_layers()), (Some(346_112), Some(99)));
1373        // The fine-tune has the base model's shape, so the same cache per token and context.
1374        assert_eq!((e.kv_bytes_per_token, e.context), (c.kv_bytes_per_token, c.context));
1375        assert_eq!(e.engine_args(), c.engine_args());
1376        let want = (e.spec.size + p.size + e.kv_bytes_per_token * 346_112) * 11 / 10;
1377        assert!(e.footprint(1).abs_diff(want) < 16);
1378        assert_ne!(e.spec.id, "inkling-2-mini-training");
1379        assert!(catalog().iter().all(|o| !o.id().contains("training")));
1380    }
1381
1382    #[test]
1383    fn the_vllm_chat_checkpoints_are_pinned_and_never_in_a_plan() {
1384        let want = [
1385            (
1386                QWEN3_VL_8B,
1387                "Qwen/Qwen3-VL-8B-Instruct",
1388                "BF16",
1389                4,
1390                4_902_275_944 + 4_915_962_496 + 4_999_831_048 + 2_716_270_024,
1391                "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b",
1392            ),
1393            (
1394                QWEN3_8_27B_NVFP4,
1395                "RadixArk/Qwen3.8-27B-NVFP4",
1396                "NVFP4",
1397                3,
1398                9_965_652_544 + 9_985_757_064 + 1_970_287_672,
1399                "319f741cce68d7914884900c138a1fbb70a42f30",
1400            ),
1401        ];
1402        for (id, repo, quant, shards, bytes, rev) in want {
1403            let e = find(id).unwrap_or_else(|| panic!("{id} in the catalog"));
1404            assert_eq!(
1405                (e.purpose, e.is_gguf(), e.spec.repo.as_str(), e.quant.as_str(), e.license()),
1406                (Purpose::Chat, false, repo, quant, Some("apache-2.0")),
1407                "{id}"
1408            );
1409            assert!(!e.restricted() && !e.gated() && e.projector().is_none() && e.engine_args().is_empty(), "{id}");
1410            assert_eq!((e.files().len(), e.weights_bytes(), e.revision()), (shards, bytes, Some(rev)), "{id}");
1411            assert!(e.files().iter().all(|f| is_sha256(&f.sha256) && f.id == id && f.repo == repo), "{id}");
1412            assert_eq!(e.files()[0], e.spec, "{id}: the first file is the spec");
1413            let kv = e.kv_bytes_per_token * e.context as u64;
1414            assert!(e.footprint(1).abs_diff((bytes + kv) * 11 / 10) < 16, "{id}");
1415        }
1416        assert_eq!(find(QWEN3_VL_8B).unwrap().kv_bytes_per_token, 36 * 8 * 256 * 2);
1417        assert_eq!(find(QWEN3_8_27B_NVFP4).unwrap().kv_bytes_per_token, 16 * 4 * 512 * 2);
1418        // Every shard of every sharded entry has its own hash.
1419        for id in [QWEN3_VL_8B, QWEN3_8_27B_NVFP4] {
1420            let hashes: Vec<_> = find(id).unwrap().files().into_iter().map(|f| f.sha256).collect();
1421            let mut unique = hashes.clone();
1422            unique.sort();
1423            unique.dedup();
1424            assert_eq!(unique.len(), hashes.len(), "{id}");
1425        }
1426        // llama.cpp cannot run them: a plan never picks one, whatever the memory.
1427        for (gpus, ram) in [(Vec::new(), 62), (Vec::new(), 512), (parse_nvidia_smi("NVIDIA GB10, [N/A], 12.1, 580.95.05", 128 * GIB), 128)] {
1428            let hw = box_with(gpus, ram);
1429            let p = plan(&hw, budget(&hw, None, None));
1430            for e in [&p.main, &p.standin, &p.embedding].into_iter().flatten() {
1431                assert!(e.is_gguf(), "{} in a plan", e.id());
1432            }
1433        }
1434    }
1435
1436    #[test]
1437    fn the_vllm_transcribers_are_pinned_from_the_hub() {
1438        let want = [
1439            (QWEN3_ASR_1_7B, "Qwen/Qwen3-ASR-1.7B", "apache-2.0", 2, 4_220_320_824 + 478_200_688, "7278e1e70fe206f11671096ffdd38061171dd6e5"),
1440            (WHISPER_LARGE_V3_TURBO, "openai/whisper-large-v3-turbo", "mit", 1, 1_617_824_864, "41f01f3fe87f28c78e2fbf8b568835947dd65ed9"),
1441            (
1442                COHERE_TRANSCRIBE_03_2026,
1443                "CohereLabs/cohere-transcribe-03-2026",
1444                "apache-2.0",
1445                1,
1446                4_131_862_976,
1447                "d552dadc2922ba6f6c1f994f8db904d52dcaf942",
1448            ),
1449        ];
1450        for (id, repo, license, shards, bytes, rev) in want {
1451            let e = find(id).unwrap_or_else(|| panic!("{id} in the catalog"));
1452            assert_eq!((e.purpose, e.is_gguf(), e.spec.repo.as_str(), e.license()), (Purpose::Transcribe, false, repo, Some(license)), "{id}");
1453            assert!(e.transcribes() && !e.restricted() && e.projector().is_none(), "{id}");
1454            assert_eq!((e.files().len(), e.weights_bytes(), e.revision()), (shards, bytes, Some(rev)), "{id}");
1455            assert!(e.files().iter().all(|f| is_sha256(&f.sha256) && f.id == id && f.repo == repo), "{id}");
1456            assert_eq!(e.files()[0], e.spec, "{id}: the first file is the spec");
1457            // Weights and KV, plus 10% for buffers.
1458            let kv = e.kv_bytes_per_token * e.context as u64;
1459            assert!(e.footprint(1).abs_diff((bytes + kv) * 11 / 10) < 16, "{id}");
1460        }
1461    }
1462
1463    #[test]
1464    fn a_sharded_entry_lists_every_shard_with_its_own_hash() {
1465        let e = find(QWEN3_ASR_1_7B).unwrap();
1466        assert!(e.is_sharded());
1467        let files = e.files();
1468        let names: Vec<_> = files.iter().map(|f| f.file.as_str()).collect();
1469        assert_eq!(names, ["model-00001-of-00002.safetensors", "model-00002-of-00002.safetensors"]);
1470        assert_eq!(files[0].sha256.as_deref(), Some("a4cd1f1a04d90b757dc7f7dd26254e69a013b19e80efe590a83c6a3bde8608d6"));
1471        assert_eq!(files[1].sha256.as_deref(), Some("6e0b9d9e09e2e0238e7ef3cc8a484ab387e91b90f1900bedf88bc92d7929ccfc"));
1472        assert_ne!(files[0].sha256, files[1].sha256);
1473        assert_eq!(files.iter().map(|f| f.size).sum::<u64>(), e.weights_bytes());
1474        assert_eq!(files[1].size, 478_200_688);
1475        // One consent covers every shard (the id is the entry's), and the store keeps them apart.
1476        let consent = crate::Consent::given(&e.spec);
1477        let store = crate::ModelStore::new(std::path::Path::new("/nonexistent-store"));
1478        for f in &files {
1479            assert_eq!(f.id, e.spec.id);
1480            assert_eq!(crate::Consent::given(f), consent);
1481        }
1482        assert_ne!(store.path(&files[0]), store.path(&files[1]));
1483        // Every other entry is one file, and weights_bytes is the spec's size.
1484        for o in catalog().iter().filter(|o| !matches!(o.id(), QWEN3_ASR_1_7B | QWEN3_VL_8B | QWEN3_8_27B_NVFP4)) {
1485            assert!(!o.is_sharded(), "{}", o.id());
1486            assert_eq!(o.files(), vec![o.spec.clone()], "{}", o.id());
1487            assert_eq!(o.weights_bytes(), o.spec.size, "{}", o.id());
1488        }
1489    }
1490
1491    #[test]
1492    fn engine_args_are_separate_per_entry() {
1493        let args = |id| find(id).unwrap().engine_args();
1494        assert_eq!(args(COHERE_TRANSCRIBE_03_2026), ["--trust-remote-code"]);
1495        assert!(args(QWEN3_ASR_1_7B).is_empty() && args(WHISPER_LARGE_V3_TURBO).is_empty() && args(VOXTRAL_MINI_3B).is_empty());
1496        let with: Vec<_> = catalog().into_iter().filter(|e| !e.engine_args().is_empty()).map(|e| e.id().to_string()).collect();
1497        assert_eq!(with, [CAVELING_2_MINI, INKLING_2_MINI, COHERE_TRANSCRIBE_03_2026]);
1498    }
1499
1500    #[test]
1501    fn only_cohere_is_gated_and_nothing_here_is_restricted() {
1502        let gated_ids: Vec<_> = catalog().into_iter().filter(|e| e.gated()).map(|e| e.id().to_string()).collect();
1503        assert_eq!(gated_ids, [COHERE_TRANSCRIBE_03_2026]);
1504        let cohere = find(COHERE_TRANSCRIBE_03_2026).unwrap();
1505        assert!(gated(&cohere.spec));
1506        let other_file = ModelSpec { id: "x".into(), file: "tokenizer.model".into(), ..cohere.spec.clone() };
1507        assert!(gated(&other_file), "another file of the gated repo");
1508        assert!(!gated(&find(WHISPER_LARGE_V3_TURBO).unwrap().spec));
1509        for id in [CAVELING_2_MINI, INKLING_2_MINI, QWEN3_VL_8B, QWEN3_8_27B_NVFP4, QWEN3_ASR_1_7B, WHISPER_LARGE_V3_TURBO, COHERE_TRANSCRIBE_03_2026]
1510        {
1511            assert!(!find(id).unwrap().restricted(), "{id}");
1512            assert_eq!(restricted_license(&find(id).unwrap().spec), None, "{id}");
1513        }
1514    }
1515
1516    #[test]
1517    fn the_transcriber_stays_a_gguf_llama_cpp_runs() {
1518        for gib in [4, 8, 16, 62, 256] {
1519            let hw = box_with(Vec::new(), gib);
1520            let t = transcriber(&budget(&hw, None, None));
1521            if let Some(t) = t {
1522                assert!(t.is_gguf() && t.id() == VOXTRAL_MINI_3B, "{gib} GiB: {}", t.id());
1523            }
1524        }
1525        // A budget that holds Whisper but not Voxtral gets none: llama.cpp cannot run it.
1526        let small = find(VOXTRAL_MINI_3B).unwrap().footprint(1) - 1;
1527        let budget = Budget { pool_bytes: small, reserve_bytes: 0, usable_bytes: small };
1528        assert!(find(WHISPER_LARGE_V3_TURBO).unwrap().footprint(1) <= small);
1529        assert_eq!(transcriber(&budget), None);
1530        assert_eq!(by_purpose(Purpose::Transcribe).len(), 4);
1531    }
1532}