mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-30 09:57:57 -04:00
* feat(system): expose raw detected capability for model meta resolution Model meta gallery entries express hardware fallback through candidate ordering rather than a capability map, so they need the undecorated detected capability string without Capability's default/cpu fallback chain. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor(system): drop duplicate capability accessor, cover DetectedCapability ReportedCapability was added with a body identical to the existing DetectedCapability. Keep one accessor and move the specs onto it, since DetectedCapability had no direct coverage of its no-fallback behavior. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(vram): parse IEC binary size suffixes (KiB..PiB) ParseSizeString accepted only SI suffixes, so a "20GiB" floor was rejected outright. Model and VRAM sizes are conventionally quoted in IEC units, and silently reading GiB as GB would understate a floor by about 7%. Purely additive: these inputs previously returned an unknown-suffix error. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): add Candidate type for meta model entries Candidate is one option in a meta entry's ordered variant list. It names a concrete gallery entry and declares when that entry suits the host. EffectiveMinVRAM resolves the VRAM floor, letting an authored min_vram win over a nightly-inferred one. An unparseable floor errors instead of being treated as absent: swallowing a typo would turn a constrained candidate into an unconstrained one and select a too-large variant rather than fail loudly. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): add hardware-aware model variant resolver Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): allow gallery model entries to declare variant candidates A gallery entry with a non-empty candidates list is a meta entry: it names an ordered list of concrete entries and resolves to the first one the host can satisfy, instead of describing model files directly. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): resolve meta model entries to hardware-appropriate variants at install Meta gallery entries carry an ordered candidate list; at install time the first candidate the host satisfies is resolved and its payload installed under the meta's name, so the model keeps a stable name regardless of which variant backs it. The resolution is recorded in the installed gallery config so a reinstall honors a prior pin and operators can see the backing variant. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): key meta pin recall on the installed name and detach resolved entries Six review findings on the meta-entry install path. Pin recall was keyed on the gallery entry name while applyModel writes the record under the install name (req.Name when supplied), so a meta installed under a custom name with a pin lost that pin on reinstall and was silently re-resolved onto a different variant, possibly swapping its backend. Compute the install name with applyModel's own precedence before the recall. ResolveMetaModel returned a shallow struct copy, so the resolved entry's Overrides aliased the gallery entry's map and the install path's in-place mergo merge wrote the caller's request into the shared catalog. Detach Overrides, ConfigFile, AdditionalFiles, URLs and Tags. Not exploitable today only because this path re-unmarshals the gallery per call, which is a property nobody should have to rely on. Also: overlay the meta's name onto the persisted config for meta installs so the gallery file no longer records the variant's name; move the pinned-VRAM warning below the variant validation so a pin naming a nonexistent entry does not warn about VRAM before failing for an unrelated reason; and stop seeding config.URLs in the config_file branch, which duplicated every declared URL. Add seven network-free specs driving InstallModelFromGallery with a meta entry: variant payload wins over the meta's legacy url fallback, the resolution record round-trips to disk, a pin is recorded and honored on reinstall including under a custom install name, and the resolved entry does not alias the gallery's maps. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): deep-copy meta overrides and make two specs functional ResolveMetaModel detached the resolved entry's Overrides and ConfigFile with maps.Clone, which only copies the top level. Gallery overrides are nested in practice (parameters.model is near-universal) and the install path merges the caller's request with mergo.WithOverride, which recurses into nested maps and overwrites them in place, so the gallery entry's own inner maps were still reachable and still got rewritten by the last caller to install. Copy both maps all the way down instead, recursing through the container shapes a YAML decoder produces. ConfigFile is not mutated on the install path today, but it carries the same kind of nested payload and leaving it shallowly cloned would invite the bug back. Also fix two specs that passed whether or not their target fix was present: - "does not write the caller's overrides back into the gallery entry" re-read the catalog from disk, which re-unmarshals fresh structs and so cannot observe in-memory aliasing. It now asserts against the in-memory gallery entry and drives the real mergo merge. - "round-trips the resolution record to disk under the meta's name" asserted a name that is already correct in the config_file branch. It now drives the url branch via a file:// fixture, where the meta-name overlay actually applies. Both were verified red by reverting their fix. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(gallery): lint meta model entry invariants in index.yaml Adds Ginkgo specs that parse the shipped gallery/index.yaml and enforce the invariants that keep meta entries safe: a legacy url fallback equal to the final candidate's url, references only to existing non-meta entries, a min_vram floor on every candidate but the last-resort one, a capability drawn only from the vocabulary the system can report, and descending VRAM floors within a capability group. The capability check is the only compensating control for a typo there. Candidate matching is a case-sensitive exact comparison against SystemState.DetectedCapability(), so an unknown value never matches and falls through silently instead of erroring. The vocabulary therefore mirrors the raw return set of getSystemCapabilities(), which notably excludes "cpu": that is a fallback key inside Capability(capMap) on the meta backend path, never a reported capability. A CPU-only host reports "default". These pass vacuously until the pilot meta entry lands; the guard is intentionally in place before the thing it guards. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(gallery): close coverage gaps in the meta entry lint The ordering invariant grouped candidates by capability and asserted floors descend within a group. A candidate with an EMPTY capability matches every host, so it does not belong in its own group: it dominates every later candidate whose floor is at or above its own, across capability groups. Track a running minimum floor over the unconditional candidates instead, which subsumes the old same-group check for the empty capability. Every spec skipped non-meta entries, so with zero meta entries in the index all five bodies were no-ops. Aligning GalleryModel.IsMeta() with GalleryBackend.IsMeta(), whose semantics are deliberately opposite, would have made all of them pass while checking nothing. Extract each invariant into a helper over a slice of entries returning the violations it finds, and cover those helpers with synthetic fixtures so the logic stays tested at zero meta entries. The index-driven specs are now a thin application of already proven logic. Also assert the index parses non-empty, report every violation in one run rather than aborting on the first, and parse the index once for the suite. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * ci(gallery): add nightly denormalization of meta model candidates Fills the read-only backend, quantization and inferred_min_vram fields on meta gallery candidates and opens a PR, modeled on the existing checksum_checker job. Computing these needs network access, so it happens nightly rather than at install time. An authored min_vram is never modified: a human who measured a real load knows more than a pre-download estimate does. The index is rewritten via yaml.Node rather than a document round-trip. A full round-trip reflows all ~26k lines of gallery/index.yaml, which would bury the computed values and make the nightly PR unreviewable. The rewrite touches only the three derived keys, so authored styling survives and a run that computes nothing leaves the file untouched. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(ci): keep the gallery denormalize diff reviewable and self-healing The nightly denormalization job edits YAML nodes instead of round-tripping structs so its PR stays small enough for a human to review, but the write path undid that: yaml.Marshal re-encoded the node tree at yaml.v3's default 4-space indent and dropped the leading document marker, reflowing roughly 6000 lines around the handful of real changes. Encode through yaml.NewEncoder at the index's authored 2-space indent and restore the header. A write that changes three fields now changes three lines. Stale inferred_min_vram values were also never cleared. Both skip paths (an authored min_vram is present, or the candidate is the last resort) returned before touching the field, so a candidate that gained a floor or became the last resort after a reorder kept an inferred value that EffectiveMinVRAM reported as a real constraint, failing the meta lint with no way for the job to self-heal. Clear the field before both skips. The workflow discarded a whole night's work on any single failure: the program exits 1 when a candidate cannot be estimated, which aborted the job before the PR step, so one unreachable candidate blocked every other refresh indefinitely. Capture the status, open the PR with what was computed, mark the PR body as partial, and fail the run afterwards so the problem still surfaces. Also preserve the index's existing file mode instead of forcing 0644, and drop the redundant //go:build ignore tag, since Go already skips dot directories and the sibling modelslist.go carries no tag. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): add nanbeige4.1-3b meta entry with hardware-resolved variants Adds the first real meta entry to the gallery index. It resolves to the Q8_0 build on hosts with at least 6GiB of VRAM and to the Q4_K_M build everywhere else, installing either payload under the stable name nanbeige4.1-3b. The entry carries a url equal to its final candidate's url. LocalAI releases that predate candidates support parse the index non-strictly and drop the key silently, so without that url they would list the entry and install nothing. A regression spec parses the index the way those releases do and asserts every meta entry stays installable for them. Also teaches core/schema/gallery-model.schema.json about candidates. The schema sets additionalProperties: false at the top level, so an author following CONTRIBUTING.md and adding the yaml-language-server comment would otherwise get a validation error on this entry. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): make candidate entries complete, installable entries Reworks hardware-resolved gallery variants after a design pivot. There is no longer a separate "meta" entry kind. A gallery entry is a normal, complete entry that may additionally carry candidates:, a list of hardware-gated upgrades over itself, and the entry is itself the last-resort candidate. The previous design relied on a bare url: as the fallback for LocalAI releases that predate candidates support. That fallback is empty in practice: none of the 80 gallery/*.yaml files carry a top-level files:, and 1216 of 1281 index entries carry their payload in the index entry itself, so a url alone yields a config template with nothing to download. Since every released LocalAI reads gallery/index.yaml live from master, merging a payload-less entry would have shown every existing user a model that installs to a broken state. Making the entry its own base candidate removes the problem at the root: old clients drop the candidates key and install the entry exactly as they do today. Resolution order is now explicit pin, then capability plus VRAM over the declared upgrades, then the entry itself. The entry ALWAYS installs: when its own min_vram or capability is unmet the installer warns and installs it anyway, because there is nothing below it and refusing would make the gallery behave worse the newer the client is. A pin naming the entry's own name is valid and is how an operator declines an upgrade. IsMeta() becomes HasCandidates(), ResolveMetaModel becomes ResolveVariant, and the persisted meta_name record key becomes entry_name. GalleryBackend.IsMeta() is a separate concept and is untouched. The lint drops the three rules the pivot makes wrong (url equality with the final candidate, no inline payload, unconstrained final candidate) and gains one: the entry's own floor must sit strictly below every candidate's, since a base that outranks a candidate makes that candidate unreachable. The pilot entry is now the existing nanbeige4.1-3b-q4, which gains a 2GiB floor of its own and a single 6GiB upgrade to nanbeige4.1-3b-q8, replacing the separate nanbeige4.1-3b entry added ind0d441bb4. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): select model variants by hardware fit, not authored order Gallery entries could already carry a list of alternatives, but selection was an authored, ordered, first-match policy: every candidate declared a `capability` string and the VRAM floors had to descend in a hand-tuned order. That pushed hardware knowledge onto whoever edits the gallery and made ordering load-bearing, so a reordered list silently changed what users installed. None of it was necessary. SystemState.IsBackendCompatible already derives hardware support from a backend name alone: it knows MLX and metal are Darwin-only, CUDA is NVIDIA-only, ROCm AMD-only, SYCL Intel-only. Selection can read that instead of asking authors to restate it. Authoring is now just a list of names: - name: qwen3.6-27b min_memory: 4GiB variants: - model: qwen3.6-27b-mlx-8bit - model: qwen3.6-27b-gguf-q8 min_memory: 28GiB and all the intelligence moved into the selector. Given a host it drops the variants whose backend cannot run here, drops those whose known memory requirement exceeds what the host has, and takes the LARGEST of what is left, because a bigger footprint is a higher quality quantization of the same model. A variant of unknown size is kept, since nothing proves it does not fit, but it ranks last so a proven fit always beats a guess. An explicit pin still wins outright, and if nothing survives the entry installs its own payload: the base always installs, this never refuses. Available memory is VRAM when a GPU was detected and system RAM otherwise, read through xsysinfo so a cgroup limit is honored and a container gets its own limit rather than the node's RAM. Capability disappears entirely, from the types, the schema and the lint. VRAM and RAM collapse into one `min_memory`, because a model's footprint is roughly the same wherever it lives and one figure is compared against whichever applies. The lint rules about ordering, the capability vocabulary and floor relationships are deleted with the hazards they described; what remains is that every variant names an entry that exists and does not itself declare variants, plus that any memory figure actually parses. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * gallery: size model variants with a live probe, drop the nightly denormalizer Selection needs each variant's size to decide whether it fits and to rank largest-first. That figure was written into the index by a nightly job, which made the gallery carry a derived value that could drift from the entry it was derived from. Derive it at install time instead. pkg/vram already sizes a model without downloading it, and the gallery UI already uses it: a remote GGUF header range-fetch, then an HTTP HEAD for the content length, then any declared size:. It caches its results, so reuse it rather than writing a second probing path. A probe failure must never fail an install, so an unprobeable variant is treated as unknown: it survives the memory filter, because nothing proves it does not fit, and it ranks last, so a known-good fit always beats a guess. If every probe fails, selection still terminates on the base entry. The probe is injected through ResolveEnv rather than called directly, for the same reason the backend compatibility check is: specs pin an exact size, or an exact failure, without reaching the network. With that in place three things are dead weight and go: - The nightly job and the fields it populated. Variant.Backend was redundant because the backend is resolved live from the referenced entry during selection, and Quantization was display-only that nothing read. - min_memory on the base entry. The base always installs and its floor could only warn, so it could not change any outcome. - The lint rules and schema entries for both. min_memory on individual variants stays, as the override for when the probed size is wrong. An authored figure now suppresses the probe entirely rather than merely outranking it, so it costs no round trip. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): expose model variants for selection over API, CLI and MCP A gallery entry may carry `variants:`, alternative builds of the same model. Selection already worked at install time, but nothing could see what an entry offered or ask for a specific build, so the feature was undrivable. Listing: `GET /api/models` now reports `variants` and `auto_variant` for the entries that declare variants. Each variant carries its resolved backend, its measured size and whether it fits this host. `auto_variant` is what installing without a choice would pick right now. The new gallery.DescribeVariants runs the same variantOptions + SelectVariant pass the installer runs, so the reported default cannot drift from what installing actually does, and HostResolveEnv is extracted so both derive the host and share pkg/vram's probe cache from one place. Performance: an entry that declares no variants returns early without touching the probe, so the ~1280 ordinary entries cost exactly what they cost before. Selection: `variant` is accepted on POST /models/apply, as a query param on POST /api/models/install/:id, on the gallery apply file/string request, as `local-ai models install --variant`, and as a parameter on the install_model MCP tool (both the httpapi and inproc clients). Empty means auto-select. An unknown variant name now fails the install naming what was requested. This closes a real hole: an entry declaring no variants short-circuits before selection runs, so a requested variant was previously dropped silently and the install reported success. startup.InstallModels ends in a variadic model list, so install options could not be appended to it; InstallModelsWithOptions is added alongside and InstallModels delegates to it. No caller signature changed. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): drop the redundant variant min_memory field Variant.MinMemory was an authored override for when the live probe misreads a variant's footprint. It duplicated an existing field: probeEntryMemory already passes the entry's declared size: into EstimateModelMultiContext, whose cascade prefers that declared size over its own guesswork. Correcting size: on the referenced entry fixes the figure for every consumer rather than only for variant selection, so min_memory shadowed the right answer. A variant is now nothing but a name. Its effective size is exactly the probe result, and an unknown stays unknown: it survives the filter and ranks last. EffectiveMemory loses its error return along with the field. The authored string was the only thing that could fail to parse, so the error had no remaining source and was propagating dead nil-checks through SelectVariant, DescribeVariants and the pin warning. Selection behaviour is unchanged. The specs covering probe-derived sizing, ranking, filtering, the unknown-size path, pin recall, entry/variant metadata split and deep-copy isolation all survive; the three install specs that needed a definite size now declare it through the referenced entry's own size:, which exercises the documented escape hatch directly. gallery/index.yaml is untouched: no entry ever carried the key. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): rank the entry's own build against its variants Variant selection pulled the declaring entry's own payload, the base, out of the candidate set and consulted it only once every declared variant had been rejected. Two real failures followed. A variant whose size the probe cannot determine deliberately survives the memory filter, because nothing proves it does not fit. As the only survivor it then won outright on any host, however small: a 2GiB machine installed an unmeasured variant in preference to the 4GiB build the entry itself ships, with no warning. 241 of the 1280 current index entries carry no files and no size, which is exactly that shape. "Largest wins" also broke whenever the base was the largest. An author writing a Q8 entry that offers a Q4 downgrade for small hosts, a natural shape that nothing in the lint, schema or docs discourages, had the Q4 installed on every large host instead. Make the base an ordinary participant. It is still exempt from both filters, so selection always terminates on something installable, but it is now ranked against the variants: a proven fit first and largest, then the base, then any variant whose size nothing could measure. Both failures disappear together. The base is probed for its size accordingly, which it was not before, because an unsized base would lose every contest to an unmeasurable variant. FellBackToBase is kept but narrowed to "no declared variant survived", rather than "the base was chosen", since the base now also wins on merit and that is not worth warning about. A recalled variant pin also became a permanent install failure. A pin the caller supplies on this request must stay fatal, but one recalled from ._gallery_<name>.yaml can be invalidated by any later gallery edit, and failing on it turned one rename into a model that could never be reinstalled or upgraded again short of deleting a dotfile the user has never heard of. A stale recalled pin is now dropped with a warning naming it, and selection runs as if it had never been recorded. Also drop the last textual reference to two abandoned designs from the DetectedCapability comment, correct the documented variants JSON example, which showed a memory_bytes of 0 that omitempty makes impossible, and remove an em dash from the install skill. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): budget variant memory from RAM when a GPU reports no VRAM Variant selection read its memory budget from VRAM whenever a GPU capability was detected, and from system RAM only when none was. Apple Silicon satisfies the first branch and fails the premise: arm64 macs report the metal capability unconditionally, without probing anything, while TotalAvailableVRAM has no discrete VRAM pool to find and returns zero. The budget therefore came out as zero on every Mac. Zero drops every variant carrying a known size, so the base build was installed on all of them however much memory the machine had. The feature was inert on the platform, and silently: falling back to the base is a legitimate outcome, so nothing looked wrong. Take VRAM only when it is actually a number, and fall back to RAM otherwise. On a unified-memory host RAM is not an approximation of the budget, it is the budget, since the GPU shares it. A discrete GPU whose VRAM could not be read also lands on RAM, which overstates what the card holds but understates nothing the host has; the previous zero understated both. An unreadable RAM figure still yields zero and still installs the base, so a genuinely unknown host is not talked into a larger download. This is what turned tests-apple red: "installs a fitting variant's payload under the entry's own name" asserts on selection, and the runner resolved to the base because its budget was zero. The added specs pin the branch directly rather than relying on a macOS runner to notice again. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): add a model variant picker to the models gallery PR #10943 shipped the server side: a gallery entry may declare `variants:`, `GET /api/models` attaches `variants` and `auto_variant` to declaring entries, and `POST /api/models/install/:id` accepts a `variant` query parameter. Nothing in the UI consumed any of it, so the feature was not reachable from the browser. This wires it up. modelsApi.install takes an optional second argument and appends an encoded `?variant=` only when one is given, so every existing call site keeps sending exactly the request it sent before. On the models table, an entry that declares variants gets a split button. The primary Install still installs the auto-selected build, because auto is the default and the point of the feature; the chevron opens a menu for a deliberate override. It follows the Backends.jsx precedent: one shared Popover re-anchored per row, rendering .action-menu items, which brings Escape, outside-click and focus return along with it. An entry that declares no variants renders exactly as it did before. A variant that does not fit is dimmed but stays selectable, since the server honors an explicit choice with a warning rather than refusing it. memory_bytes is omitempty on the wire, so an absent key means the size is unknown and never zero. A single helper guards both the menu and the detail row, because formatBytes would otherwise render a falsy value as "0 B", which reads as "needs nothing". The expanded detail row gains a Variants section listing each build's backend, size, whether it fits, which is the entry's own build, and which one auto-selection would pick, built from the existing DetailRow helper and .badge classes. Eight Playwright specs cover the picker, including that plain Install sends no variant parameter and that choosing one sends it. One pre-existing assertion was scoped with .first(): the Variants section legitimately adds more llama-cpp badges to the detail row, which tripped strict mode. UI line coverage 49.42% -> 49.36% against a 40.0 baseline and 0.8pp tolerance; branch coverage rose 72.04% -> 72.66%. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): describe model variants from a companion endpoint Variant description probes each referenced entry's weight files over the network: an HTTP HEAD plus a ranged GET, serial, five seconds per probe with no aggregate deadline. Running it inline in GET /api/models made one listing cost (entries x variants) round trips. The Manage page fetches with items=9999, so at 200 declaring entries that is ~1000 serial probes, minutes of a blocked handler and gigabytes of range traffic for a single page load. Only one entry declares variants today, but the feature exists so that many will. Follow the precedent already set for VRAM estimates. The listing now reports only has_variants, a length check on loaded metadata that touches nothing, and GET /api/models/variants/:id returns the description for one entry, mirroring estimate/:id in route shape, auth and error handling. DescribeVariants itself is unchanged; only its caller moved. The picker fetches lazily at the two points where a user asks to see variants, opening the split-button menu and expanding the detail row, and caches per entry for the page session. An entry declaring no variants issues no request at all. A spec counts real HTTP hits on the weight files, so it goes red if description becomes reachable from the listing path again through any caller. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): filter the model gallery to entries that declare variants The gallery is heading towards showing parent entries and hiding the individual builds they reference, so a user sees one row per model rather than six quantizations of it. Adoption is a single entry today, so defaulting to that would leave a one-row gallery. This ships the migration-phase inverse instead: the default is untouched, and a toggle narrows the list to only the entries that declare variants. It previews the end state and changes nothing until someone asks for it. The filter is server-side, next to term/tag/backend/capability and above the pagination arithmetic. The listing paginates at 9 items, so narrowing on the client would leave totalPages and availableModels describing the unfiltered set and hand the user empty pages. It selects on HasVariants(), which reads already-loaded metadata, so it issues no variant probes. The parameter is named has_variants after the listing field it selects on, and is compared against "true" like the other boolean query params (all_users, save_checkpoint), so has_variants=false reads as absent. With it omitted the response is byte-for-byte what it was before. The control is the shared Toggle component, matching the fitsFilter toggle already on this page: same wrapper class, same icon and label shape, same localStorage persistence. Unlike fitsFilter it resets to page 1 on change, which a server-side filter has to do. Stacking the toggle with a tag or backend filter easily yields nothing while one entry declares variants, so the empty state now names the variants filter as the cause rather than leaving a user to conclude the gallery is broken. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(ui): render gallery model descriptions as Markdown Gallery descriptions are Markdown, but the React UI dumped them raw, so a model whose description opens with an ATX heading showed a literal "# Qwen3.6-27B [](https://chat.qwen.ai)" in the list. Full-description areas now render through renderMarkdown (marked + DOMPurify), matching how Backends.jsx and the Manage detail panels already handle the same content: - Models.jsx expanded detail row - VoiceLibrary.jsx voice detail header The truncated one-line previews must not render block Markdown: a leading "#" would become an <h1> and wreck the row height and rhythm. They get a new stripMarkdown() helper instead, which reduces Markdown to a single line of readable plain text. It is used for the cell text and for the title tooltip, since a tooltip full of "[](url)" is no better than a cell full of it: - Models.jsx gallery table description cell - Manage.jsx model and backend resource-row descriptions stripMarkdown walks marked's lexer output rather than running regexes over the source, so what it strips is by construction what renderMarkdown would have rendered, and it needs no new dependency. Output lands in JSX text nodes, so React escapes it; no new dangerouslySetInnerHTML beyond the two full-description sites, both of which run DOMPurify. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(ui): strip Markdown from the backends table description cell Commitb35d630cffixed this for gallery models but left the Backends admin page with the same asymmetry: its detail panel renders the description through renderMarkdown, while the collapsed table row dumped the raw gallery string into both the cell body and the title tooltip. That is user-visible. 40 of the 949 entries in backend/index.yaml carry Markdown - insightface uses inline code backticks, others use lists and links - and backend descriptions also contain embedded newlines, so the one-line cell showed literal syntax. The cell now runs stripMarkdown over the description once and uses the result for the text and the title, matching Models.jsx and the ResourceRowDesc component in Manage.jsx. The '-' placeholder is preserved, and now also fires when a description reduces to nothing after stripping. The detail panel is untouched and no new dangerouslySetInnerHTML is introduced: stripMarkdown output lands in a JSX text node, so React escapes it. Three Playwright specs cover it: a description with a heading, inline code and a link renders as clean text with no literal syntax and no block element in the cell, the title tooltip carries the same stripped text, and a backend without a description still shows the placeholder. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * ui(models): polish the variant detail view and scope rendered Markdown The gallery detail pane rendered every field through the same two-column label/value row, including the description. Multi-paragraph prose in a value cell ran eight rows tall at the top of the pane on a ~1200px measure, breaking the grid's rhythm exactly where the eye enters. Move it into its own full-width block above the table, capped at a 68ch measure, keeping the label. Rendered Markdown had no scoped typography anywhere in the app, so a description opening with `#` inherited the browser default 2em inside a 13px surface while a `##` further down was indistinguishable from body text. Add a reusable .markdown-body block mapping h1-h6, paragraphs, lists, links, code, blockquotes, images and tables onto the existing type scale, and apply it to every renderMarkdown() consumer: the models detail, the backends detail, both Manage details and the voice library detail. Rebalance the variants list so the name leads. Backend and size drop from badge/secondary weight to muted metadata; the FITS badge goes entirely, since it was true of nearly every row and so said nothing, while the variant that does not fit keeps a warning badge and a dimmed name. AUTO-SELECTED stays marked because it answers what a plain Install produces. Rows share the parent's grid tracks via subgrid so name, backend, size and status line up down the list instead of raggedly following name length. Finally, make each variant row actionable. It looked like a list of choices but was inert text, with per-variant install hidden behind the split-button chevron elsewhere; each row is now a button onto the existing handleInstall(modelId, variant) path, with hover, keyboard focus and a disabled state while an install is in flight. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): collapse the listing to one row per model The listing supported has_variants=true, which narrowed to entries that DECLARE variants. With adoption at three entries that showed three rows, which is useless; it was always a placeholder. Replace it with the view that is actually useful: the deduplicated gallery. Show every entry installable in its own right and nothing twice, which means the parents plus every entry nobody references, and hide only the builds another entry already offers as a variant, since those are reachable through their parent. The parameter is renamed to collapse_variants accordingly: the filter is no longer a predicate on a row's own metadata but a view over the whole gallery. Default stays off, so the response with the parameter absent is unchanged. VariantReferencedIDs never reports an entry that declares variants of its own, so parents are always visible. That guarantees every hidden entry has a visible entry offering it, and no chain can strand a row. Variant resolution already refuses to install such a reference, but the listing has to stay coherent in the presence of a gallery that has one rather than silently swallowing entries. Self-references and dangling references hide nothing. The referenced set is computed over the whole gallery rather than over what the other filters left, so an entry is hidden because a parent offers it and never because of what the user searched for. The pass is over metadata already in memory: it resolves nothing over the network and triggers no variant description or size probe, so the listing's zero-probe contract still holds. The UI toggle keeps its behaviour (persistence, page reset, clear filters) and becomes "One row per model", which says what the user gets. Its localStorage key moves too, since the stored value meant a different filter. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): show the collapsed model listing by default The gallery listing is what a user reaches for to answer "what can I install". Answering that with several rows for the same model, one per build, makes the reader do the deduplication the collapsed view already does, so the collapsed view is the one to land on. The UI now asks for collapse_variants=true unless the toggle says otherwise. The server default is deliberately untouched: a request with the parameter absent still returns the full listing, because other API clients depend on that response and collapsing it under them would be a breaking change. Opting out omits the parameter rather than sending false, so it asks for exactly the listing everyone else gets. The stored preference changes vocabulary from '1'/'0' to 'on'/'off'. The previous build wrote it from an effect that runs on mount, so a stored '0' recorded that the page had been opened rather than that anyone chose the expanded view, and honouring it would pin every earlier visitor to a default they never picked. Only the new vocabulary counts as a choice; a legacy '1' meant the collapsed view and is what the new default gives anyway, so no earlier deliberate choice is lost. Collapsing being the default also changes what the empty state may say about it. An opted-into filter can be named as the cause of an empty result; a default cannot, so the filters keep the top line and the collapsed view drops to a hint below it, shown only once filters are narrowing the set. For the same reason "Clear filters" now restores the collapsed default instead of switching it off, and the toggle alone no longer counts as a filter worth offering to clear. The label stays "One row per model": it describes the view the user is looking at rather than an action, so it reads the same whether it is opted into or out of. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * gallery: group alternative builds of the same weights under variants Sweep the gallery for entries that are alternative builds of the same weights (different quantization, precision, or runtime format) and declare them as variants of a single parent row, so the listing offers one row per model instead of one row per quantization and the installer picks the largest build that this host can actually run. 41 families over 95 entries, turning 54 entries into variants. The parent is the bare-named entry wherever one exists, so nothing changes about what any existing entry installs. Ranking already selects the largest fitting build regardless of which entry is nominally the parent, so the parent only decides the pathological case where nothing fits. For the ten families that have no bare-named entry, the smallest build is the parent, since that is the one that has to install when nothing fits. Grouping was verified against the actual model filenames rather than the entry names alone. Different parameter sizes, languages, finetunes, and products that merely share a name prefix are left as separate rows: the qwen3.6 APEX and pi-tune finetunes, the DFlash and MTP speculative-decoding pairings, English-only versus multilingual Whisper, the QAT versus non-QAT Gemma 4 weights, and the abliterated FLUX build are all distinct models. Six parents define YAML anchors that other entries pull in with a merge key, which would have handed their variants to every merging child. For the two depth-anything anchors that would have made fourteen unrelated entries advertise the base model's builds as their own. All 26 merging children therefore carry an explicit empty variants list, which overrides the merged key and is equivalent to the key being absent. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): rank model variants by host backend preference Variant auto-selection filtered candidates by whether their backend can run on the host, then ranked the survivors by size alone. The backend never influenced the choice beyond that gate, so a Mac offered both an MLX build and a llama.cpp build kept neither filtered and installed whichever was larger, leaving the native accelerated runtime unused. The same held for CUDA against CPU on NVIDIA and ROCm against Vulkan on AMD. Rank by the host's backend preference between the fit tier and size: fit stays a filter, preference decides among the builds the host can equally hold, and size still separates builds on equally preferred runtimes. The preference data stays in one declarative table in pkg/system, now read by a prefix lookup instead of a switch, so adding a capability or reordering one host's runtimes is a one-line edit and the gallery's ranking code carries no per-backend branching. MLX joins the metal rule ahead of metal itself, which is inert for the existing alias-resolution consumer because no alias group holds a candidate named for mlx. An unrecognised backend, an unrecognised capability and an absent preference list all collapse to the previous size-only ordering rather than erroring or dropping candidates. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): rank variants by engine name, not backend build tag Variant auto-selection ranked candidates with SystemState.BackendPreferenceTokens, but that function and the variant ranker speak different vocabularies. BackendPreferenceTokens returns BUILD TAGS ("cuda", "rocm", "sycl", "vulkan", "metal", "cpu"). It exists to match installed backend build directory names like "llama-cpp-cuda-12" during alias resolution in ListSystemBackends. Variant ranking instead matches a gallery entry's `backend:` value, which is an ENGINE NAME: "llama-cpp", "vllm", "vllm-omni", "sglang", "mlx" and the rest. No engine name in gallery/index.yaml contains "cuda", "rocm", "sycl" or "vulkan". preferenceRank matches by substring, so on an NVIDIA host the tokens [cuda, vulkan, cpu] matched neither "llama-cpp" nor "vllm", every candidate scored identically and size alone decided. The NVIDIA, AMD, Intel, darwin-x86 and vulkan rules were all inert. Only metal appeared to work, and only because the token "mlx" happens to equal an engine name. The mismatch does not error, it silently deletes the feature. Separate the two vocabularies. backendBuildTagPreferenceRules keeps the build tags and its original output for every capability, including metal, whose "mlx" token is removed again; its alias-resolution consumer is byte-identical to before. engineNamePreferenceRules is new, holds engine names, and is read by the new EnginePreferenceTokens, which HostResolveEnv wires into the renamed ResolveEnv.EnginePreference. Both tables sit adjacent under one block comment naming each vocabulary and each consumer, and share one lookup helper so their semantics cannot drift. On NVIDIA the order is vLLM, then SGLang, then llama-cpp: vLLM is the throughput engine and a model published with a vLLM build is published that way because that build is the one worth running. AMD and Intel get the same order, since rocm and intel builds of both serving engines ship. Metal prefers mlx over llama-cpp. Vulkan prefers llama-cpp, the only LLM engine with a Vulkan build. darwin-x86 and unknown capabilities are deliberately absent rather than guessed at, degrading to the size-only ordering that predates preference. preferenceRank stays generic and names no engine and no capability, so adding a runtime remains a one-line table edit. Specs pin the NVIDIA and metal rules through the live table and the real HostResolveEnv wiring, so emptying the engine table or wiring the build tag source back in both go red. A regression table asserts BackendPreferenceTokens' original output per capability, and mirrored locks assert neither table carries the other's vocabulary. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs: record that variant selection ranks by engine before size A gallery entry can now declare variants, and selection ranks the builds a host can run by engine preference before size. Nothing told a contributor adding a backend that engineNamePreferenceRules exists, so a new engine would silently rank below every known one and lose to whatever build happened to be larger on hosts where it should have won. Document the step where a backend is added, warn against the sibling backendBuildTagPreferenceRules table (build tags, not engine names: the wrong table matches nothing, scores every candidate equally and disables the preference without erroring), and index it from AGENTS.md. Fix the authoring and user docs, which still claimed the largest surviving build wins. An author grouping builds under one entry has to be able to predict what a user gets, and size alone no longer decides it. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(cli,mcp): describe variant auto-selection as preference before size The CLI flag help and the install_model tool schema both still said auto-selection takes the largest build that runs. Ranking now puts engine preference ahead of size, so on NVIDIA a vLLM build wins over a larger llama.cpp one. An assistant reading the old schema would tell users the wrong thing. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): prefer llama.cpp over GPU serving engines on hosts with no GPU engineNamePreferenceRules had no row for the "default" capability, which getSystemCapabilities() returns both when no GPU is detected and when a GPU is present but under the 4 GiB VRAM floor. A missing row yields an empty preference list, which preferenceRank reads as "score everything equally", collapsing variant selection to size alone. That would be harmless if the hardware filter dropped GPU serving engines on such a host, but it does not. IsBackendCompatible derives support from the engine NAME, and "vllm" and "sglang" contain none of the darwin, cuda, rocm or sycl tokens it keys on, so they fall through to its closing "return true". A vLLM variant therefore survives on a CPU-only box and wins whenever its build is the larger of the two on offer: the machine installs vLLM in preference to llama.cpp. darwin-x86 had the identical hole. It was documented as a deliberate omission because nothing accelerates on an Intel Mac, which is true about acceleration and wrong about consequence: with every engine tied, download size decides. Add rows for both putting llama-cpp first. The GPU engines are enumerated behind it rather than left unmatched: an unmatched engine already ranks below every listed one, so llama.cpp would win either way, but unmatched engines also tie with each other and let size decide among them. Naming them fixes that order. MLX is left off the darwin-x86 row on purpose so it ranks last, since IsBackendCompatible admits darwin-tokened engines on that capability even though MLX needs Apple silicon. Preference orders survivors and never filters, so a model published only as a vLLM build is still installed on a host with no GPU; there is a spec for it. Surveyed every other value getSystemCapabilities() can return. nvidia, amd, intel and vulkan have rows; the l4t and cuda-refined values reach the nvidia row by prefix; "apple" and "" cannot reach the vendor fallthrough because the darwin and no-GPU branches return earlier. default and darwin-x86 were the only live holes. BackendPreferenceTokens and its build-tag table are untouched, and preferenceRank stays generic, naming no engine and no capability. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * gallery: prefer speculative-decoding builds when they fit Rank serving features between engine preference and size, so a host that can hold a DFlash or MTP build of a model's weights installs it instead of the plain build. Both answer faster for the same output, so whenever one survives the filters there is no reason to take the plain build. Precedence is now fit, then engine, then serving feature, then size. Engine outranks the feature deliberately: a serving feature makes the right engine faster, it does not make a wrong engine right, so a plain vLLM build still beats a DFlash llama.cpp build on NVIDIA. Fit outranks both, and a drafter pairing is strictly larger than the plain build, so the existing size filter drops it on a host too small for it before this axis is consulted. The order lives in a third preference table in pkg/system, alongside the build tag and engine name tables. It is the odd one of the three: not keyed by capability, because no hardware prefers a plain build over an equivalent faster one, and matched against whole segments of a gallery ENTRY NAME rather than as a substring of a backend value. Nothing on a gallery entry declares a serving feature, and tags are not a usable substitute: gemma-4-e2b-it:sglang-mtp carries an mtp tag while ornith-1.0-9b-mtp and qwen3.6-27b-nvfp4-mtp carry none. Entry names are author-supplied free text, unlike the closed engine vocabulary, so a short marker can turn up inside an unrelated word and whole segment matching is what keeps smtp-assistant from ranking as an MTP build. The block comment over the tables now documents all three together and states what each is matched against; the ranking code names no feature, so adding one stays a one-line edit to the table.29c49203brejected these entries as serving configurations rather than alternative builds of the same weights. The definition is now "alternative ways to serve the same model", which includes them, so regroup 14 entries under 12 parents. Judged by the files each entry points at: the qwen3.6, qwen3.5, qwen3 and deepseek pairings are the base GGUF plus a drafter, the gemma-4 QAT MTP entries are the same QAT weights at a different quantization plus an MTP drafter, and the two sglang MTP entries describe themselves as the same model served with speculative decoding. Left separate: qwen3.6-27b-mtp-pi-tune, a finetune with its own weights, and every entry whose base model LocalAI does not ship as its own row, which is the whole Qwopus line plus gemmable-4-12b-mtp, mimo-7b-mtp:sglang and qwen3.5-4b-dflash. None of the twelve parents defines a YAML anchor, so no variants key can leak through a merge key and no empty override was needed this time. The index was edited by line insertion only. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test: check env restore errors in capability and variant specs errcheck flagged ten unchecked os.Setenv and os.Unsetenv returns in the specs added while the pre-commit hook was being skipped. Restoring an env var is exactly the place a silent failure leaks state into the next spec, so assert on it rather than suppressing the linter. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): make the mtp tag authoritative for serving-feature ranking Variant auto-selection ranks survivors by fit, then engine, then serving feature, then size. The serving-feature lookup read only whole alphanumeric segments of a variant's entry name, because tags were inconsistent: every dflash entry carried a dflash tag, but only 7 of 20 MTP entries carried an mtp tag. Tag the 13 untagged MTP entries, then teach the lookup to read tags as well as names. A tag is now the authoritative signal and is compared whole and case-insensitively, which is safe precisely because a tag is a deliberate declaration rather than free text: there is no word-inside-a-word failure mode, so the segment splitting the name half needs is unnecessary there. The name check stays as a fallback rather than being replaced. Switching to tags only would have regressed the six already-grouped entries on the day it shipped, and would depend on tagging discipline that does not exist yet. The lookup still names no feature, so adding one remains a one-line edit to servingFeaturePreferenceTokens. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): make a declared tag the sole serving-feature signal Variant auto-selection ranks survivors by fit, then engine, then serving feature, then size. The serving-feature lookup recognised a speculative build by either a declared tag or a whole segment of its entry name. Drop the name half: a tag is now the only signal. A name is author-supplied free text and a naming convention is not a contract, so reading a marker out of one infers a capability nobody declared. The gallery already had the failure in it: the four NVFP4 entries name MTP-bearing weights while setting no option that enables speculative decoding, and being live variants they were winning the feature axis without answering any faster. overrides.options was considered as the replacement and rejected. It carries spec_type:draft-mtp / spec_type:draft-dflash, which is what actually turns the feature on, but that spelling is llama.cpp's config vocabulary: ds4 spells the same feature mtp_path and sglang spells it speculative_algorithm in a referenced config. Keying a cross-backend ranking decision on one backend's option syntax would rank the other backends' builds as plain. Options are the curation-time check instead, and never reach the selection logic. With no fallback left, tag correctness is load bearing, so audit every entry against the rule "tagged when the entry configures that feature, in whatever vocabulary its backend uses". Three entries configure MTP untagged and gain the tag (hy3, glm-5.2, qwythos-9b-claude-mythos-5-1m, all spec_type:draft-mtp with no marker in their names). Four carry the tag while configuring nothing and lose it: qwen3.6-27b-nvfp4-mtp, qwen3.6-35b-a3b-nvfp4-mtp, qwopus3.6-27b-coder-mtp-nvfp4 and qwopus3.6-27b-v2-mtp-nvfp4, whose only option is use_jinja:true. The dflash side was checked independently rather than assumed consistent: all five dflash entries declare spec_type:draft-dflash and all five are tagged, so it needed no edits. Four entries keep a tag that a literal spec_type-only reading would strip, because they configure MTP through a different backend: deepseek-v4-flash-q2-mtp via ds4's mtp_path/mtp_draft, and the three sglang entries via speculative_algorithm in their referenced configs. Stripping those would contradict the reason spec_type was rejected as the signal and would demote four genuinely faster builds to plain. The index was edited by line insertion and deletion only, never round-tripped through a serializer. A resolved-tag diff across all 1272 named entries, taken after merge keys are applied, shows exactly these 7 changing and no entry gaining or losing a tag through an anchor. The two specs that pinned the name fallback are inverted rather than deleted, since a name silently promoting a build is the regression worth guarding. The whole-token guard survives on the tag path, where smtp must still not match mtp. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): make deepseek-v4-flash variant targets installable Clicking install on deepseek-v4-flash failed with "invalid gallery model". The parent entry is fine, but all four entries it was grouped with declared neither url: nor config_file:, and applyModel needs one of the two to have anything to build a config from. They carry urls: (plural), the informational HuggingFace link list, which is a different field. None of the four was ever independently installable, so grouping them routed a previously-working install into a broken entry. Give each the url: the parent already resolves through. virtual.yaml is a no-op base, and applyModel passes overrides to InstallModel separately from the fetched config, so backend: ds4, the parameters and the ssd/mtp options all still land exactly as authored. This is the same pattern the parent and many other GGUF entries in the index already use. Add the lint rule that should have caught this. checkVariantReferences only proved a target exists and is not itself a parent, which is structural validity: an entry can exist, declare no variants, and still be uninstallable. checkVariantTargetsInstallable mirrors applyModel's precondition instead, and names the parent, the target and the missing fields, because whoever hits it is reading a gallery entry and has no reason to know applyModel exists. The two index-driven resolution specs live in their own Ordered container: an Ordered container stops at its first failure, so sharing one with the lint rules let a lint breach skip them silently. Nine further entries gallery-wide have the same defect and are unrelated to variants, so they are broken installs that predate this branch. They are left alone here rather than buried in a regression fix, and widening the rule to cover every entry is deferred with them so the gate can ratchet up in one step instead of needing a skip list. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): install entries with no url or config_file on an empty base applyModel had three branches: fetch a base config from url:, build one from an inline config_file:, or fail with "invalid gallery model". An entry declaring neither is now installed on an empty base config, with overrides: and files: supplying everything. This is what the ~345 entries pointing at gallery/virtual.yaml were already getting. That stub is five lines carrying name, description and license. description and license are overwritten from the gallery entry immediately after the fetch, and the name never reaches disk because InstallModel prefers the install name. Crucially applyModel passes model.Overrides to InstallModel as a separate argument rather than merging it into the fetched config, so nothing an author writes depends on that base existing. The fetch bought a round trip to GitHub and nothing else. That makesf4ef80173the wrong fix, so it is unwound. The four url: lines it added to the deepseek-v4-flash variants are reverted: they are a pointless network fetch now, and the family installs without them. Relaxing the branch would hide a real authoring mistake, so a payload rule replaces the base-config rule. An entry with no url, no config_file, no overrides and no files installs nothing and would leave an empty model directory while reporting success, so it is refused by name. The caller's request counts toward the payload, because its overrides and files are merged into the install exactly as the entry's own are. urls: (plural) is the informational link list and does not count, which is what the four entries that shipped broken had and why they were still uninstallable. checkVariantTargetsInstallable asserted every variant target declares a url: or a config_file:, which is no longer true and would now reject correct authoring. checkEntriesInstallSomething pins what survives instead, and covers every entry rather than only variant targets: the hazard is a half-written stanza and a parent can be one as easily as a target. The old rule was scoped to targets precisely because nine unrelated entries would have failed a gallery-wide version; those nine are valid now, so the deferred ratchet happens here in one step. 1280 entries, zero violations. Those nine (aurore-reveil_koto-small-7b-it, lfm2-1.2b, the six liquidai_lfm2 entries and deepseek-v4-pro-q2-ssd) become installable for free. Each carries overrides: and files:, and one of them is driven through the real install path in a spec. The no-fetch spec is paired rather than bare: an assertion that nothing was fetched proves nothing unless something could have been, so a control runs the same fixture with a url: pointing at a base config that is not there and asserts the install fails. Only then does the identical fixture without the url passing mean the read was skipped. Follow-up, deliberately not here: the ~345 entries still naming virtual.yaml can drop their url:. That is 345 index edits with their own risk, and mixing them in would bury this change. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * ui(models): let search bypass the variant collapse, drop the toggle The models page collapsed the gallery to one row per model by default and offered a toggle to see every individual build. Because the collapse composed with the search term, a build another entry offers as a variant could not be found by typing its name, so the toggle was the only way to reach those builds in the UI. A user who typed a name they knew existed got "no models found", which reads as "that model does not exist". Collapse is for browsing; search is for finding. An explicit search term now bypasses the collapse in the listing handler, so a name lookup returns matching entries whether or not a parent offers them. The term is trimmed once at the top of the handler, so whitespace is neither a search nor a bypass; previously an untrimmed blank term also narrowed the listing to whatever contained a space. Tag and backend deliberately do not bypass: they refine a listing the user is still reading rather than name an entry already known to exist. That makes the toggle redundant, so it goes, along with its i18n strings in all six locales, its localStorage persistence, its participation in "Clear filters" and the empty-state hint telling users to turn it off. The hint was doubly stale: it pointed at a control that no longer exists, and it was untrue exactly when a user has a search term, since searching now sees every build. The page always requests the collapsed listing. The stored preference key is left inert rather than cleaned up: nothing reads it, so a user who had the toggle off simply gets the collapsed view. collapse_variants stays on the API, off by default, because other clients want either view and the UI dropping its control is no reason to remove a working parameter. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): give the models gallery filter form a deliberate structure The filter area had accreted controls into one undifferentiated flow. The "Fits in GPU" toggle and the backend select were direct children of .filter-bar, the same wrapping container as the 18 taxonomy chips, so their position was decided by how many chips happened to wrap at the current width rather than by any layout intent. At narrow widths they were pushed past the right edge of that container's horizontal scroll and became unreachable entirely. Restructure into three bands inside the house .filter-bar-group wrapper that components/FilterBar.jsx already uses on Backends and the System tabs: 1. query scope: search plus the backend select 2. taxonomy: the chip row, alone, free to wrap 3. refinements: fits-in-GPU and context size, under a hairline rule The backend select leads the chips rather than trailing them because picking a backend disables the use cases that backend cannot serve, so it gates the row below it. Fits-in-GPU and context size share a band because they are one control group: the context size is the length the VRAM estimate is computed at, and that estimate is what the fits filter tests against. Chips had no visible keyboard focus indicator. The global focus ring is wrapped in :where(), so it carries the specificity of a bare :focus-visible, ties with .filter-btn and loses on source order, leaving focused chips showing their resting drop shadow. Restate the ring where it outranks both resting and hover. Also: aria-pressed on the chips, a real label association and aria-valuetext on the context slider (it steps over an index, so it announced "2"), disabled chip styling moved off inline styles, a prefers-reduced-motion block for the chip transition, and the hard-coded English "Context:" moved into all seven locales. No behaviour change: same filters, same state, same requests. Page reset on change, localStorage persistence and "Clear filters" verified unchanged. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): let the models recommendations panel fade into the background The "Recommended for your hardware" strip rendered at full height on every visit regardless of how many models were already installed, costing 186px at 1600px wide (287px at 1100px, where its cards wrapped to two rows) and pushing the first gallery row to y=554 / y=703. Make its prominence track how much the user still needs it. The panel now defaults to a one-line summary once anything is installed, and both the collapse choice and the existing dismissal persist: collapsed = explicit user choice, if one exists : installedCount > 0 The preference is three-valued on purpose. A boolean cannot tell "the user expanded it" apart from "the user has never chosen", and those need opposite handling when the installed count later crosses zero: someone who deliberately opened the panel on an empty instance should not have it collapse out from under them when their first model finishes installing. Collapsed keeps the card, icon, title and a suggestion count, so the panel is recovered by clicking what you are already looking at rather than by hunting. Expanded is unchanged, because for a user with nothing installed it was never the problem. Collapsed reclaims 145px at 1600 and 420, and 246px at 1100. Models.jsx gains a statsLoaded flag: stats initializes to installed:0, so reading it before the fetch resolves would render expanded and collapse a frame later, which is exactly the layout shove this removes. The dismissal key moves to the page's localai-models-* convention; the old localai_rec_models_dismissed is still read, never written, so an existing dismissal is honoured rather than resurrected by the rename. Accessibility: the disclosure is a real button whose accessible name is the visible title alone, with state on aria-expanded and aria-controls resolving in both states, because the grid is hidden via the hidden attribute rather than unmounted. That also keeps the four install buttons out of the tab order while collapsed. The app's global focus ring applies; no per-component outline is added, per the warning in App.css. Reveal animates opacity and transform only, never height, and both it and the chevron rotation are disabled under prefers-reduced-motion. Only en had a recommended block, so the other six locales were falling back to English for the whole panel. Translated the complete block rather than adding one orphaned key to files that would still render the title in English. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(downloader): recover from a leftover .partial on non-HTTP URIs An interrupted download leaves a `<file>.partial` behind. The partial handling in DownloadFileWithContext gated resume on `err == nil && uri.LooksLikeHTTPURL()`, so for any URI that is not literally http(s) the branch fell through to `else if !errors.Is(err, os.ErrNotExist)`, which with a nil err is true. The download then failed with an error wrapping nil: failed to check file ".../Ternary-Bonsai-27B-Q2_g64.gguf" existence: <nil> Every gallery file URI uses `huggingface://`, so a single interrupted download made that model permanently uninstallable until someone deleted the partial by hand. The `<nil>` in the message compounded it by pointing debugging at a filesystem failure that never happened. Restructure the handling as an explicit switch over the four real states: partial exists and is resumable, partial exists and is not resumable (discard and restart, as already done for an HTTP server without range support), no partial, and a genuine stat failure. The error branch is now only reachable with a non-nil error, names the path that was actually stat'd, and wraps with %w. Discarding is required for correctness and not merely convenience: the writer opens the partial with O_APPEND, so an un-resumed download would concatenate a fresh body onto stale bytes. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): tell the models gallery's variant rows apart, and let browsing see every build Both variant surfaces rendered name, backend and size. For two builds of one model that is close to no information: a variant exists precisely because the same weights are offered another way, so the backend usually matches and the sizes usually land within a few hundred megabytes. Comparing ternary-bonsai-27b-pq2 against ternary-bonsai-27b-q2-g64 meant reading two names that differ by a suffix nobody has defined anywhere in the UI. Report the quantization and the serving features on VariantView, and derive both server-side from the referenced entry rather than parsing names in the browser, so every client reads the same format out of the same file the installer will hand the backend. Quantization comes from overrides.parameters.model first, falling back to the file list. That order is load bearing: entries routinely ship a vision tower alongside the language model at a different quantization, so reading the file list first reports the mmproj's format. Matching walks `-` and `.` delimited segments right to left; `_` deliberately does not split, because it separates the parts INSIDE a quant token and splitting on it reports Q4 for a Q4_K_M build. A second, looser pass takes a segment's `_`-delimited tail, which catches the gemma-4-E2B_q4_0-it.gguf style; it runs second so a precise match can never lose to a fuzzy one further right in the name. An entry naming no format reports nothing, which is the honest answer for a backend served from a directory of weights. Features are the same tag-against-vocabulary match servingFeatureRank already ranks on, over the same host preference list. A build can therefore never be shown as faster than one selection did not actually reward, nor rewarded without being shown; a spec pins that agreement rather than trusting it. The compact dropdown gets the quantization on its meta line and the bare feature token. The detail row, which has the room, gets the quantization as its own monospaced column so precision lines up down the list, and the feature spelled out, because DFLASH names nothing to a user who has not met it. The referenced entry's description stays out of both: the detail row already renders the parent's prose above the table, and a second block per variant would push a three-variant list past a screen to restate what the columns now say precisely. The collapse toggle comes back.462583f38dropped it once search bypassed the collapse, on the reasoning that nothing was unreachable any more. That holds for finding a build whose name you know and does not hold for browsing: no sequence of actions enumerated the 68 builds the default view hides. Collapse is for browsing and search is for finding, and the toggle was the browsing half. It goes in the refinements band0d4823362established, not back among the taxonomy chips where its position depended on how many chips happened to wrap. It leads that band because it decides how many rows the other two refine over, and because unlike fits-in-GPU it is unconditional: a host with no GPU still browses. The search bypass is untouched and re-checked by a spec in the toggle's default state, since restoring the control must not restore the dead end it replaced. The empty-state hint returns but only without a search term, because a term bypasses the collapse and the hint would otherwise point at a control that cannot change the result. The stored preference reads 'on'/'off' only: an older build wrote '1'/'0' from an effect that ran on mount, so those record that the page was opened, not that anyone chose a view. Also fixes a latent flake it exposed. The collapse_variants spec compared whole response bodies byte for byte, and the listing envelope carries live host telemetry that drifts between two calls milliseconds apart, so it was asserting on the machine's memory pressure. It now compares everything the parameter governs -- the entries, their serialization and the paging -- and is green 25/25 where it was failing about one run in three. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): let the models gallery show a variant's full details The variant list in an entry's expanded detail row says how the builds differ: name, backend, quantization, size, and the auto-selected, base and serving-feature markers. It cannot say what any one of them is. A variant's own description, tags, license, source links and file list are unreachable anywhere in the UI, because while the collapse is on a variant has no gallery row of its own. Give each variant row an info control that reveals its entry, rendered by the same ModelDetail a top-level row gets, so a field added to the detail view appears here too. variantData is withheld from the nested render: a variant may declare variants of its own, and recursing would nest a picker inside a picker two levels deep already. An inline disclosure rather than a modal. The control sits inside a table row that is already expanded, inside a variant list within that; a dialog opened from there stacks a dismissal on a dismissal for a handful of extra fields about the entry the user is already reading, and breaks the page's own expand idiom. The third level is carried by an inset and a left rule instead of another card. The entry is fetched by exact name from the listing, once, on first use. The listing already returns every field the detail view renders, and a search term bypasses the variant collapse server-side, so no new endpoint is needed and neither the listing nor DescribeVariants gains any work. Expanding a row costs nothing; a variant nobody opens costs nothing. A name the listing no longer returns is stated, not blanked: an empty panel reads as a rendering fault rather than as a lookup that came back empty. The control is a sibling of the install button, not a descendant, so asking about a build can never install it. The variant list keeps its content-sized columns via a trailing filler track instead of max-content sizing, so the rows are unchanged while the panel spanning them gets the pane width its file table needs. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): let search respect the collapse instead of switching it off The models listing collapsed to one row per model, and an explicit search term turned that off wholesale. Searching while collapsed therefore answered with the individual builds a parent already offers, which are exactly the rows the view the user asked for has no place for: typing "mtp" returned qwen3.6-27b-nvfp4-mtp, a row that is invisible the moment the box is cleared. The bypass was the right shape of fix for the wrong half of the problem. What a search must not do is answer "no models found" for a build the gallery does hold; that does not require abandoning the grouping the user asked for. So the term is now matched against every entry either way, hidden builds included, and the collapse decides how a match is reported rather than which matches exist. Collapsing stops being a filter that drops rows and becomes a substitution: a match on a build another entry offers is reported as that entry, the one installable in its own right. Nothing becomes unfindable and nothing comes back that the requested view cannot show. Substitution happens after search, tag and backend, so every filter is judged against the build that really carries the name, tag or backend rather than against a parent that merely offers it; the other order would let backend=vllm match a parent whose own backend is something else. The price is that the surfaced row shows the parent's own metadata while the match was on a variant, which is what grouping means, and the alternative is claiming the gallery holds no such build. It happens before the count and the page math, so both describe the rows actually handed out rather than the matches that produced them. A parent already in the result keeps its own position and absorbs its matching variants there, which is what leaves the browsing listing ordered exactly as it was; a parent surfaced only by a variant takes the position of the first variant that surfaced it. Either way it appears once, however many of its builds matched and whether or not it matched itself. Search preserves gallery order rather than scoring, so a surfaced parent has a real position rather than an invented one. VariantParents never reports an entry that declares variants of its own, so a parent is never itself hidden and one hop always lands on a visible row. The handler follows exactly one anyway: refusing the second is what makes a gallery the linter would have rejected terminate rather than loop. The empty-state hint pointing at the toggle goes with it for every server-side filter. Substitution means a match is always reported as some row, so the collapse can no longer be why a term, a chip or a backend came back empty, and naming it there sends the user to a control that cannot change the result. It survives for the fits filter alone, which runs in the browser after the substitution and judges the surfaced entry's own size: there the build that fits really can be filtered out along with a parent that does not. Searching a build's exact name while collapsed now answers with its parent, so the result no longer contains the string the user typed. That is intended, and the row is the one they can act on, but it is a real rough edge: nothing on the row explains the connection. Closing it properly means reporting which variant matched so the UI can say so, which the listing does not do today. ResetGalleryModelCache is added for tests. The model cache is a package global keyed by nothing, so a background refresh one spec triggers can land in the middle of the next and answer it with the previous spec's gallery; the extra specs here made that fail about one run in five. It waits for the in-flight refresh to publish before clearing, since clearing alone only narrows the window. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
1090 lines
43 KiB
Go
1090 lines
43 KiB
Go
package gallery_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/mudler/LocalAI/core/gallery"
|
|
"github.com/mudler/LocalAI/pkg/system"
|
|
)
|
|
|
|
var _ = Describe("VariantOption.EffectiveMemory", func() {
|
|
It("reports no requirement when nothing was probed", func() {
|
|
o := gallery.VariantOption{Variant: gallery.Variant{Model: "x"}}
|
|
size, known := o.EffectiveMemory()
|
|
Expect(known).To(BeFalse())
|
|
Expect(size).To(Equal(uint64(0)))
|
|
})
|
|
|
|
It("uses the probed size", func() {
|
|
o := gallery.VariantOption{Variant: gallery.Variant{Model: "x"}, ProbedMemory: 6 * 1024 * 1024 * 1024}
|
|
size, known := o.EffectiveMemory()
|
|
Expect(known).To(BeTrue())
|
|
Expect(size).To(Equal(uint64(6 * 1024 * 1024 * 1024)))
|
|
})
|
|
|
|
It("treats a failed probe as unknown rather than as a zero requirement", func() {
|
|
// A probe that could not reach the network reports 0. Reading that as
|
|
// "needs nothing" would make an unreachable host look like the perfect
|
|
// fit and hand the user the largest download on offer.
|
|
o := gallery.VariantOption{Variant: gallery.Variant{Model: "x"}, ProbedMemory: 0}
|
|
_, known := o.EffectiveMemory()
|
|
Expect(known).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
var _ = Describe("SelectVariant", func() {
|
|
gib := func(n uint64) uint64 { return n * 1024 * 1024 * 1024 }
|
|
|
|
// Every size here is a probed one, because the probe is now the only source
|
|
// a variant's footprint can come from. A zero stands for the probe having
|
|
// been unable to tell, which is an unknown rather than a zero requirement.
|
|
option := func(model, backend string, probed uint64) gallery.VariantOption {
|
|
return gallery.VariantOption{
|
|
Variant: gallery.Variant{Model: model},
|
|
Backend: backend,
|
|
ProbedMemory: probed,
|
|
}
|
|
}
|
|
|
|
// The base is exempt from every filter, which the fallback specs below pin
|
|
// down, but it is ranked against the variants like any other candidate, so
|
|
// its size is load-bearing.
|
|
base := func(model string, probed uint64) gallery.VariantOption {
|
|
o := option(model, "llama-cpp", probed)
|
|
o.IsBase = true
|
|
return o
|
|
}
|
|
|
|
// linuxNvidia mirrors what SystemState.IsBackendCompatible does on a Linux
|
|
// box with an NVIDIA card: Darwin-only engines are out, everything else runs.
|
|
linuxNvidia := func(backend string) bool {
|
|
return backend != "mlx" && backend != "mlx-vlm"
|
|
}
|
|
|
|
Describe("hardware filtering", func() {
|
|
It("never selects a variant whose backend cannot run on this host", func() {
|
|
// The MLX build is both the largest and the only thing that would
|
|
// otherwise win, so nothing but the backend gate can reject it.
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-8bit", "mlx", gib(24)),
|
|
option("m-gguf-q8", "llama-cpp", gib(12)),
|
|
base("m-gguf-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(80),
|
|
BackendCompatible: linuxNvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q8"))
|
|
})
|
|
|
|
It("selects the same variant on a host whose backend gate does admit it", func() {
|
|
// The mirror image of the spec above, so the rejection is proven to
|
|
// come from the host and not from something intrinsic to the entry.
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-8bit", "mlx", gib(24)),
|
|
option("m-gguf-q8", "llama-cpp", gib(12)),
|
|
base("m-gguf-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(80),
|
|
BackendCompatible: func(string) bool { return true },
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-mlx-8bit"))
|
|
})
|
|
|
|
It("treats every backend as runnable when the host cannot be inspected", func() {
|
|
options := []gallery.VariantOption{option("m-mlx-8bit", "mlx", gib(24)), base("m-gguf-q4", gib(6))}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(80)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-mlx-8bit"))
|
|
})
|
|
})
|
|
|
|
Describe("ranking", func() {
|
|
It("picks the largest variant that fits, not the first authored", func() {
|
|
// Authored smallest-first, so first-match would take m-q4 and any
|
|
// ranking that ignores size would too.
|
|
options := []gallery.VariantOption{
|
|
option("m-q4", "llama-cpp", gib(6)),
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
option("m-f16", "llama-cpp", gib(24)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(16)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
Expect(selection.FellBackToBase).To(BeFalse())
|
|
})
|
|
|
|
It("picks the largest variant regardless of authored order", func() {
|
|
// Same set, authored largest-first. Order must make no difference at
|
|
// all, which is the entire point of dropping ordered first-match.
|
|
options := []gallery.VariantOption{
|
|
option("m-f16", "llama-cpp", gib(24)),
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
option("m-q4", "llama-cpp", gib(6)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(16)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
})
|
|
|
|
It("prefers a known fit over a variant of unknown size", func() {
|
|
// An unknown requirement is a guess. It survives the filter, because
|
|
// nothing proves it does not fit, but it must never displace a
|
|
// variant that is known to fit.
|
|
options := []gallery.VariantOption{
|
|
option("m-unknown", "llama-cpp", 0),
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(16)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
})
|
|
|
|
It("keeps a variant of unknown size rather than dropping it", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-unknown", "llama-cpp", 0),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(4)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
// Surviving is observable through the rejection reasons: a dropped
|
|
// variant is always accounted for there, and this one is not.
|
|
Expect(selection.Reasons).ToNot(ContainElement(ContainSubstring("m-unknown")))
|
|
// It survives, but it does not win: the base is a sized, guaranteed
|
|
// payload and an unmeasurable variant is a guess.
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
Expect(selection.FellBackToBase).To(BeFalse())
|
|
})
|
|
|
|
It("installs the base rather than an unsized variant on a host too small for either", func() {
|
|
// The exact shape 241 of the current index entries have: a referenced
|
|
// entry with no files and no size, whose probe can only answer
|
|
// "unknown". Ranking it above the base would install an unmeasured
|
|
// download on a machine with 2GiB, and would do so silently.
|
|
options := []gallery.VariantOption{
|
|
option("m-unknown", "llama-cpp", 0),
|
|
base("m-base-q4", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(2)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base-q4"))
|
|
Expect(selection.Option.IsBase).To(BeTrue())
|
|
})
|
|
|
|
It("selects the base when the base is the largest option that fits", func() {
|
|
// A Q8 base offering a Q4 downgrade for small hosts is a natural
|
|
// authoring shape. Treating the base as a last resort would install
|
|
// the Q4 on every host large enough for the Q8 and permanently
|
|
// downgrade the user.
|
|
options := []gallery.VariantOption{
|
|
option("m-q4", "llama-cpp", gib(4)),
|
|
base("m-base-q8", gib(8)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(16)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base-q8"))
|
|
// The Q4 survived every filter, so this is the base winning on rank
|
|
// and not the base being fallen back to.
|
|
Expect(selection.FellBackToBase).To(BeFalse())
|
|
Expect(selection.Reasons).To(BeEmpty())
|
|
})
|
|
|
|
It("selects a smaller variant when the base does not fit but the variant does", func() {
|
|
// The mirror of the spec above: the base competes, it does not win by
|
|
// default, so a host that cannot hold it must still take the downgrade
|
|
// the entry offers for exactly that case.
|
|
options := []gallery.VariantOption{
|
|
option("m-q4", "llama-cpp", gib(4)),
|
|
base("m-base-q8", gib(8)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(6)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q4"))
|
|
})
|
|
|
|
It("reports why a probed size that does not fit was rejected", func() {
|
|
// Ranking and filtering both run off the probe, so a rejection has to
|
|
// be traceable back to the figure the probe returned.
|
|
options := []gallery.VariantOption{
|
|
option("m-q4", "llama-cpp", gib(6)),
|
|
option("m-f16", "llama-cpp", gib(24)),
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(16)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("m-f16")))
|
|
})
|
|
|
|
It("admits a variant needing exactly the memory available", func() {
|
|
options := []gallery.VariantOption{option("m-q8", "llama-cpp", gib(12)), base("m-base", gib(2))}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(12)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
})
|
|
})
|
|
|
|
Describe("ranking by host engine preference", func() {
|
|
// These are ENGINE NAMES, exactly what SystemState.EnginePreferenceTokens
|
|
// reports for these hosts and exactly what a gallery entry's `backend:`
|
|
// field holds. Build tags ("cuda", "rocm", "metal") belong to
|
|
// BackendPreferenceTokens and would match no engine name here, which is
|
|
// why every backend below is spelled as a real gallery engine.
|
|
//
|
|
// They are spelled out rather than read from the live machine so the
|
|
// specs pin the intended behaviour on every CI runner.
|
|
darwinMetal := []string{"mlx", "llama-cpp"}
|
|
nvidia := []string{"vllm", "sglang", "llama-cpp"}
|
|
|
|
// A Mac runs both engines, so nothing is filtered here and preference is
|
|
// the only thing that can decide.
|
|
darwinRunsEverything := func(string) bool { return true }
|
|
|
|
It("prefers a vLLM build to a larger llama.cpp build on nvidia", func() {
|
|
// The rule the engine table exists to express, and the one that was
|
|
// silently inert while the ranker was fed build tags: no gallery
|
|
// engine name contains "cuda", so every candidate scored equal and
|
|
// the larger llama.cpp build won. Emptying the nvidia rule in
|
|
// pkg/system fails this spec.
|
|
options := []gallery.VariantOption{
|
|
option("m-vllm-awq", "vllm", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-gguf-q4", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm-awq"))
|
|
})
|
|
|
|
It("takes the larger llama.cpp build on the same nvidia host once preference is unknown", func() {
|
|
// The mirror of the spec above, proving the vLLM win comes from the
|
|
// preference list and not from anything intrinsic to the option set.
|
|
// This is the state the whole feature was stuck in before the two
|
|
// vocabularies were separated.
|
|
options := []gallery.VariantOption{
|
|
option("m-vllm-awq", "vllm", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-gguf-q4", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q8"))
|
|
})
|
|
|
|
It("ranks a vllm-omni build with vllm, since the token is a substring", func() {
|
|
// Substring matching is deliberate: vllm-omni is a vLLM build and
|
|
// must inherit vLLM's rank rather than fall through to unranked.
|
|
options := []gallery.VariantOption{
|
|
option("m-omni", "vllm-omni", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-base", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-omni"))
|
|
})
|
|
|
|
It("prefers an MLX build to a larger llama.cpp build on darwin", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-4bit", "mlx", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-gguf-q4", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
BackendCompatible: darwinRunsEverything,
|
|
EnginePreference: darwinMetal,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-mlx-4bit"))
|
|
})
|
|
|
|
It("takes the larger llama.cpp build on the same darwin host once preference is unknown", func() {
|
|
// The mirror of the spec above, proving the MLX win comes from the
|
|
// preference list and not from anything intrinsic to the option set.
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-4bit", "mlx", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-gguf-q4", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
BackendCompatible: darwinRunsEverything,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q8"))
|
|
})
|
|
|
|
It("still picks the largest fitting build among equally preferred engines", func() {
|
|
// Preference must not flatten size ordering: with one engine in
|
|
// play there is nothing left for it to decide.
|
|
options := []gallery.VariantOption{
|
|
option("m-gguf-q4", "llama-cpp", gib(6)),
|
|
option("m-gguf-q8", "llama-cpp", gib(12)),
|
|
option("m-gguf-f16", "llama-cpp", gib(48)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q8"))
|
|
})
|
|
|
|
It("does not let a preferred engine rescue a build that does not fit", func() {
|
|
// Fit is a filter and preference is only a ranking among survivors.
|
|
// The vLLM build is both preferred and too large, so the llama.cpp
|
|
// build the host can actually hold has to win.
|
|
options := []gallery.VariantOption{
|
|
option("m-vllm-fp16", "vllm", gib(48)),
|
|
option("m-gguf-q4", "llama-cpp", gib(6)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q4"))
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("m-vllm-fp16")))
|
|
})
|
|
|
|
It("orders engines absent from the table by size rather than dropping them", func() {
|
|
// Neither engine appears in the nvidia rule. Nothing is discarded
|
|
// and nothing is arbitrarily favoured; the host falls back to the
|
|
// size-only behaviour it had before preference existed.
|
|
//
|
|
// The base is left unsized so it ranks in the tier below a proven
|
|
// fit. It is a llama.cpp build, which the nvidia rule DOES rank, and
|
|
// letting it compete in the same tier would prove preference works
|
|
// rather than proving unlisted engines degrade to size.
|
|
options := []gallery.VariantOption{
|
|
option("m-diffusers", "diffusers", gib(12)),
|
|
option("m-transformers", "transformers", gib(6)),
|
|
base("m-base", 0),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-diffusers"))
|
|
Expect(selection.Reasons).To(BeEmpty())
|
|
})
|
|
|
|
It("ranks sglang between vllm and llama-cpp on nvidia", func() {
|
|
// A judgement call worth pinning: sglang is a GPU serving engine of
|
|
// the same class as vllm, so it outranks the portable engine, but it
|
|
// sits behind vllm.
|
|
options := []gallery.VariantOption{
|
|
option("m-vllm", "vllm", gib(4)),
|
|
option("m-sglang", "sglang", gib(6)),
|
|
option("m-gguf", "llama-cpp", gib(8)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm"))
|
|
|
|
withoutVLLM := []gallery.VariantOption{
|
|
option("m-sglang", "sglang", gib(6)),
|
|
option("m-gguf", "llama-cpp", gib(8)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
selection, err = gallery.SelectVariant(withoutVLLM, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-sglang"))
|
|
})
|
|
|
|
It("still installs the base when nothing fits, whatever the host prefers", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-8bit", "mlx", gib(48)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-base", gib(64)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(4),
|
|
BackendCompatible: darwinRunsEverything,
|
|
EnginePreference: darwinMetal,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
Expect(selection.Option.IsBase).To(BeTrue())
|
|
Expect(selection.FellBackToBase).To(BeTrue())
|
|
})
|
|
|
|
It("honors a pin for a less preferred backend", func() {
|
|
// A pin is an operator override, so preference must not quietly
|
|
// redirect it any more than the memory filter does.
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx-4bit", "mlx", gib(8)),
|
|
option("m-gguf-q8", "llama-cpp", gib(24)),
|
|
base("m-base", gib(4)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
BackendCompatible: darwinRunsEverything,
|
|
EnginePreference: darwinMetal,
|
|
}, "m-gguf-q8")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf-q8"))
|
|
})
|
|
})
|
|
|
|
Describe("ranking by serving feature", func() {
|
|
// These are SERVING FEATURES, exactly what
|
|
// system.ServingFeaturePreferenceTokens reports, and a third vocabulary
|
|
// after build tags and engine names. They are matched against a
|
|
// variant's declared TAGS and against nothing else.
|
|
//
|
|
// Spelled out rather than read from pkg/system so these specs pin the
|
|
// intended ordering rather than restating whatever the table says.
|
|
features := []string{"dflash", "mtp"}
|
|
nvidia := []string{"vllm", "sglang", "llama-cpp"}
|
|
|
|
// A tag is the whole signal, so every candidate that is meant to carry
|
|
// a feature declares it here. Candidates built with `option` carry no
|
|
// tags and are therefore plain builds no matter what their name says,
|
|
// which several specs below rely on.
|
|
tagged := func(model string, probed uint64, tags ...string) gallery.VariantOption {
|
|
o := option(model, "llama-cpp", probed)
|
|
o.Tags = tags
|
|
return o
|
|
}
|
|
|
|
It("prefers a speculative build to the plain build of the same weights", func() {
|
|
// The rule the feature table exists to express. Both builds fit and
|
|
// both run on the same engine, and the plain build is deliberately
|
|
// the larger one, so without this axis size would take it and the
|
|
// drafter pairing would never be installed. Emptying
|
|
// ServingFeaturePreference fails this spec.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q4", gib(14), "llm", "dflash"),
|
|
tagged("m-q8", gib(20), "llm"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q4"))
|
|
})
|
|
|
|
It("takes the larger plain build once the feature preference is unknown", func() {
|
|
// The mirror of the spec above on the identical option set, proving
|
|
// the DFlash win comes from the feature list rather than from
|
|
// anything intrinsic to the set.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q4", gib(14), "llm", "dflash"),
|
|
tagged("m-q8", gib(20), "llm"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
})
|
|
|
|
It("prefers dflash to mtp", func() {
|
|
// Both are speculative pairings, so only the table's order can
|
|
// separate them, and the MTP build is deliberately the larger one so
|
|
// size cannot be what decides.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-alpha-q8", gib(20), "llm", "mtp"),
|
|
tagged("m-beta-q4", gib(14), "llm", "dflash"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-beta-q4"))
|
|
})
|
|
|
|
It("does not let a preferred feature rescue a build that does not fit", func() {
|
|
// A drafter pairing is strictly larger than the plain build, so this
|
|
// is the ordinary case on a small host rather than a corner one. Fit
|
|
// is a filter; the feature preference only ranks survivors.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-f16", gib(48), "llm", "dflash"),
|
|
tagged("m-q8", gib(12), "llm"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("m-turbo-f16")))
|
|
})
|
|
|
|
It("lets the host engine preference outrank the serving feature", func() {
|
|
// A serving feature makes the right engine faster; it does not make
|
|
// a wrong engine right. On nvidia the plain vLLM build therefore
|
|
// beats a DFlash llama.cpp build even though both fit and the
|
|
// llama.cpp one is larger.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q8", gib(24), "llm", "dflash"),
|
|
option("m-vllm-awq", "vllm", gib(8)),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm-awq"))
|
|
})
|
|
|
|
It("still picks the largest fitting build among equally featured builds", func() {
|
|
// Neither preference key may flatten size ordering: with one engine
|
|
// and one feature in play there is nothing left for them to decide.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q4", gib(8), "llm", "dflash"),
|
|
tagged("m-turbo-q8", gib(14), "llm", "dflash"),
|
|
tagged("m-turbo-f16", gib(48), "llm", "dflash"),
|
|
base("m-q4", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q8"))
|
|
})
|
|
|
|
It("leaves an unfeatured build ranked last rather than dropping it", func() {
|
|
// Ranking never filters. With only plain builds on offer the axis
|
|
// scores them uniformly and selection degrades to size alone.
|
|
options := []gallery.VariantOption{
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
option("m-q4", "llama-cpp", gib(6)),
|
|
base("m-q2", gib(3)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-q8"))
|
|
Expect(selection.Reasons).To(BeEmpty())
|
|
})
|
|
|
|
Describe("reading the declared tags", func() {
|
|
It("prefers a build whose tag declares the feature its name does not", func() {
|
|
// The case tags exist for. "m-turbo-q8" carries MTP heads but
|
|
// spells nothing in its name, which is the shape most of the
|
|
// gallery's MTP entries had before they were tagged. It is also
|
|
// the smaller build, so only the feature axis can lift it.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q8", gib(14), "llm", "gguf", "mtp"),
|
|
tagged("m-plain-q8", gib(20), "llm", "gguf"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q8"))
|
|
})
|
|
|
|
It("does NOT prefer a build that only its name declares, with no tags at all", func() {
|
|
// The inversion of the old name-fallback spec, and the
|
|
// regression this change exists to guard. A name is
|
|
// author-supplied free text and a naming convention is not a
|
|
// contract: "m-nvfp4-mtp" is exactly the shape of the gallery's
|
|
// NVFP4 entries, whose weights carry MTP heads while the entry
|
|
// enables no speculative decoding at all, so ranking it as a
|
|
// speculative build made it win the feature axis without being
|
|
// any faster. With no tag it is a plain build and the larger
|
|
// plain build takes it on size.
|
|
options := []gallery.VariantOption{
|
|
option("m-nvfp4-mtp", "llama-cpp", gib(14)),
|
|
tagged("m-plain-q8", gib(20), "llm", "gguf"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-plain-q8"))
|
|
})
|
|
|
|
It("lets a tagged build beat a larger one whose name says the same feature", func() {
|
|
// The sharper form of the spec above: the name half is not
|
|
// merely unnecessary, it is not consulted. The untagged
|
|
// "m-dflash" would outrank the tagged MTP build on the old
|
|
// name-first ordering, and is the larger build besides, so it
|
|
// wins on either of the two ways the name could still be read.
|
|
options := []gallery.VariantOption{
|
|
option("m-dflash", "llama-cpp", gib(20)),
|
|
tagged("m-turbo-q4", gib(14), "llm", "mtp"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q4"))
|
|
})
|
|
|
|
It("matches a tag regardless of the case it was written in", func() {
|
|
// Gallery tags are author-supplied, so the same declaration
|
|
// arrives in whatever case the author typed. A curator who
|
|
// writes "MTP" has declared the feature just as plainly as one
|
|
// who writes "mtp", and the sole signal must not turn on that.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q8", gib(14), "LLM", "MTP"),
|
|
tagged("m-plain-q8", gib(20), "llm", "gguf"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q8"))
|
|
})
|
|
|
|
It("prefers dflash to mtp when both are declared by tag", func() {
|
|
// The table's order has to survive on the tag path with both
|
|
// features spelled out explicitly, and the MTP build is
|
|
// deliberately the larger one so size cannot be what decides.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-alpha-q8", gib(20), "llm", "mtp"),
|
|
tagged("m-beta-q8", gib(14), "llm", "dflash"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-beta-q8"))
|
|
})
|
|
|
|
It("does not read a feature out of an unrelated tag", func() {
|
|
// Tags are compared whole, so a tag that merely contains a
|
|
// feature token declares nothing. "multimodal" contains no
|
|
// feature; "smtp" does contain "mtp" as a substring and must
|
|
// not count either. The mail model is the larger build, so a
|
|
// false positive would hand it the win.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-mail-q8", gib(24), "llm", "multimodal", "smtp"),
|
|
tagged("m-turbo-q4", gib(14), "llm", "mtp"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-turbo-q4"))
|
|
})
|
|
|
|
It("does not let a tag rescue a build that does not fit", func() {
|
|
// Fit still outranks the feature axis, whichever signal
|
|
// declared it.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-f16", gib(48), "llm", "mtp"),
|
|
tagged("m-plain-q8", gib(12), "llm"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(16),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-plain-q8"))
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("m-turbo-f16")))
|
|
})
|
|
|
|
It("lets the host engine preference outrank a tagged serving feature", func() {
|
|
// Engine beats feature no matter which signal carried the
|
|
// feature: a tag does not make a wrong engine right.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q8", gib(24), "llm", "mtp"),
|
|
option("m-vllm-awq", "vllm", gib(8)),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(64),
|
|
EnginePreference: nvidia,
|
|
ServingFeaturePreference: features,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm-awq"))
|
|
})
|
|
|
|
It("ignores tags entirely when no feature preference is configured", func() {
|
|
// The axis stops discriminating with an empty list, tags or no
|
|
// tags, and selection degrades to size alone as it always did.
|
|
options := []gallery.VariantOption{
|
|
tagged("m-turbo-q8", gib(14), "llm", "mtp"),
|
|
tagged("m-plain-q8", gib(20), "llm"),
|
|
base("m-q4", gib(6)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(32),
|
|
EnginePreference: nvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-plain-q8"))
|
|
})
|
|
})
|
|
})
|
|
|
|
Describe("falling back to the base", func() {
|
|
It("selects the base when nothing else fits", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-q8", "llama-cpp", gib(12)),
|
|
option("m-f16", "llama-cpp", gib(24)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(4)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
Expect(selection.Option.IsBase).To(BeTrue())
|
|
Expect(selection.FellBackToBase).To(BeTrue())
|
|
Expect(selection.Reasons).To(HaveLen(2))
|
|
})
|
|
|
|
It("selects the base even when the base does not fit either", func() {
|
|
// The base is exempt from the memory filter, not merely favoured by
|
|
// it: there is nothing below it, so refusing here would make an entry
|
|
// every older client installs fine uninstallable on newer ones.
|
|
options := []gallery.VariantOption{option("m-q8", "llama-cpp", gib(12)), base("m-base", gib(2))}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: 0}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
Expect(selection.Option.IsBase).To(BeTrue())
|
|
Expect(selection.FellBackToBase).To(BeTrue())
|
|
})
|
|
|
|
It("prefers the base to an unsized variant even when the base itself is unsized", func() {
|
|
// Neither can be shown to fit, so nothing separates them on size. The
|
|
// base is still the payload the entry is guaranteed to install.
|
|
options := []gallery.VariantOption{
|
|
option("m-unknown", "llama-cpp", 0),
|
|
base("m-base", 0),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(8)}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
})
|
|
|
|
It("explains why each variant was rejected", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx", "mlx", gib(8)),
|
|
option("m-f16", "llama-cpp", gib(24)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(4),
|
|
BackendCompatible: linuxNvidia,
|
|
}, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("cannot run on this system")))
|
|
Expect(selection.Reasons).To(ContainElement(ContainSubstring("24.0GiB")))
|
|
})
|
|
|
|
It("errors when the caller supplies no base at all", func() {
|
|
options := []gallery.VariantOption{option("m-f16", "llama-cpp", gib(24))}
|
|
|
|
_, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(4)}, "")
|
|
Expect(err).To(MatchError(gallery.ErrNoVariantMatch))
|
|
})
|
|
})
|
|
|
|
Describe("explicit selection", func() {
|
|
It("honors a pin the hardware would never have chosen", func() {
|
|
options := []gallery.VariantOption{
|
|
option("m-mlx", "mlx", gib(64)),
|
|
base("m-base", gib(2)),
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{
|
|
AvailableMemory: gib(4),
|
|
BackendCompatible: linuxNvidia,
|
|
}, "m-mlx")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-mlx"))
|
|
})
|
|
|
|
It("honors a pin naming the base, declining an upgrade that fits", func() {
|
|
options := []gallery.VariantOption{option("m-f16", "llama-cpp", gib(8)), base("m-base", gib(2))}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(64)}, "m-base")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-base"))
|
|
})
|
|
|
|
It("matches a pin case-insensitively", func() {
|
|
options := []gallery.VariantOption{option("m-f16", "llama-cpp", gib(8)), base("m-base", gib(2))}
|
|
|
|
selection, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(64)}, "M-F16")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-f16"))
|
|
})
|
|
|
|
It("fails loudly when the pin names nothing in the list", func() {
|
|
options := []gallery.VariantOption{option("m-f16", "llama-cpp", gib(8)), base("m-base", gib(2))}
|
|
|
|
_, err := gallery.SelectVariant(options, gallery.ResolveEnv{AvailableMemory: gib(64)}, "m-gone")
|
|
Expect(err).To(MatchError(gallery.ErrPinNotFound))
|
|
Expect(err.Error()).To(ContainSubstring("m-gone"))
|
|
})
|
|
})
|
|
})
|
|
|
|
var _ = Describe("HostResolveEnv engine preference wiring", func() {
|
|
// The specs above feed SelectVariant a hand-written token list, which proves
|
|
// the ranker but not that the host actually reaches the engine table. These
|
|
// drive the REAL table through the REAL wiring, so emptying
|
|
// engineNamePreferenceRules in pkg/system, or reverting this field to
|
|
// BackendPreferenceTokens, fails here.
|
|
var origEnv, origRunFileEnv string
|
|
const capabilityEnv = "LOCALAI_FORCE_META_BACKEND_CAPABILITY"
|
|
const capabilityRunFileEnv = "LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE"
|
|
// What getSystemCapabilities reports for a host with no usable accelerator.
|
|
const noGPUCapability = "default"
|
|
|
|
BeforeEach(func() {
|
|
origEnv = os.Getenv(capabilityEnv)
|
|
origRunFileEnv = os.Getenv(capabilityRunFileEnv)
|
|
})
|
|
|
|
AfterEach(func() {
|
|
if origEnv != "" {
|
|
Expect(os.Setenv(capabilityEnv, origEnv)).To(Succeed())
|
|
} else {
|
|
Expect(os.Unsetenv(capabilityEnv)).To(Succeed())
|
|
}
|
|
if origRunFileEnv != "" {
|
|
Expect(os.Setenv(capabilityRunFileEnv, origRunFileEnv)).To(Succeed())
|
|
} else {
|
|
Expect(os.Unsetenv(capabilityRunFileEnv)).To(Succeed())
|
|
}
|
|
})
|
|
|
|
envFor := func(capability string) gallery.ResolveEnv {
|
|
GinkgoHelper()
|
|
Expect(os.Setenv(capabilityEnv, capability)).To(Succeed())
|
|
return gallery.HostResolveEnv(context.Background(), &system.SystemState{})
|
|
}
|
|
|
|
It("hands the ranker engine names an NVIDIA host's gallery entries can match", func() {
|
|
preference := envFor("nvidia-cuda-12").EnginePreference
|
|
Expect(preference).To(Equal([]string{"vllm", "sglang", "llama-cpp"}))
|
|
})
|
|
|
|
It("installs the vLLM build over a larger llama.cpp one on a real NVIDIA host", func() {
|
|
// End to end on the live table: the exact behaviour that was silently
|
|
// dead while the ranker was fed build tags.
|
|
env := envFor("nvidia-cuda-12")
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-vllm"}, Backend: "vllm", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
{Variant: gallery.Variant{Model: "m-gguf"}, Backend: "llama-cpp", ProbedMemory: 24 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm"))
|
|
})
|
|
|
|
It("installs the MLX build over a larger llama.cpp one on a real darwin host", func() {
|
|
env := envFor("metal")
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
// The real gate rejects mlx off darwin, and this spec is about ranking.
|
|
env.BackendCompatible = func(string) bool { return true }
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-mlx"}, Backend: "mlx", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
{Variant: gallery.Variant{Model: "m-gguf"}, Backend: "llama-cpp", ProbedMemory: 24 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-mlx"))
|
|
})
|
|
|
|
It("installs the llama.cpp build over a larger vLLM one on a host with no GPU", func() {
|
|
// The hole this rule closes. IsBackendCompatible keys on the engine
|
|
// name, and "vllm" carries no darwin/cuda/rocm/sycl token, so a vLLM
|
|
// build is NOT filtered out here. Emptying the default rule in
|
|
// pkg/system puts the larger vLLM build back on a CPU-only box.
|
|
env := envFor(noGPUCapability)
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-vllm"}, Backend: "vllm", ProbedMemory: 24 * 1024 * 1024 * 1024},
|
|
{Variant: gallery.Variant{Model: "m-gguf"}, Backend: "llama-cpp", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf"))
|
|
})
|
|
|
|
It("installs the llama.cpp build over a larger vLLM one on an intel mac", func() {
|
|
env := envFor("darwin-x86")
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-vllm"}, Backend: "vllm", ProbedMemory: 24 * 1024 * 1024 * 1024},
|
|
{Variant: gallery.Variant{Model: "m-gguf"}, Backend: "llama-cpp", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf"))
|
|
})
|
|
|
|
It("still installs a vLLM build on a host with no GPU when it is the only one offered", func() {
|
|
// Preference ORDERS survivors, it never filters them. Demoting vLLM must
|
|
// not make a model published only as a vLLM build uninstallable.
|
|
env := envFor(noGPUCapability)
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-vllm"}, Backend: "vllm", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-vllm"))
|
|
})
|
|
|
|
It("prefers llama.cpp on a GPU host with too little VRAM to serve from", func() {
|
|
// This host has a GPU, yet getSystemCapabilities reports "default"
|
|
// because it is under the 4 GiB floor. Driven through the real detector
|
|
// rather than a forced capability, so that mapping is exercised too.
|
|
if runtime.GOOS == "darwin" {
|
|
Skip("darwin reports metal or darwin-x86 before the VRAM floor is consulted")
|
|
}
|
|
Expect(os.Unsetenv(capabilityEnv)).To(Succeed())
|
|
// A capability run file on the machine would override detection.
|
|
Expect(os.Setenv(capabilityRunFileEnv, filepath.Join(GinkgoT().TempDir(), "absent"))).To(Succeed())
|
|
|
|
state := &system.SystemState{GPUVendor: system.Nvidia, VRAM: 2 * 1024 * 1024 * 1024}
|
|
Expect(state.DetectedCapability()).To(Equal(noGPUCapability))
|
|
|
|
env := gallery.HostResolveEnv(context.Background(), state)
|
|
env.AvailableMemory = 64 * 1024 * 1024 * 1024
|
|
|
|
options := []gallery.VariantOption{
|
|
{Variant: gallery.Variant{Model: "m-vllm"}, Backend: "vllm", ProbedMemory: 24 * 1024 * 1024 * 1024},
|
|
{Variant: gallery.Variant{Model: "m-gguf"}, Backend: "llama-cpp", ProbedMemory: 8 * 1024 * 1024 * 1024},
|
|
}
|
|
|
|
selection, err := gallery.SelectVariant(options, env, "")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(selection.Option.Variant.Model).To(Equal("m-gguf"))
|
|
})
|
|
|
|
It("carries no build tag into the ranker, whatever the host", func() {
|
|
// The wiring-level lock. BackendPreferenceTokens returns build tags for
|
|
// every capability, so if it is ever wired back into this field, one of
|
|
// these tags shows up here.
|
|
for _, capability := range []string{"nvidia-cuda-12", "amd", "intel", "metal", "vulkan", "default"} {
|
|
Expect(envFor(capability).EnginePreference).ToNot(
|
|
ContainElements("cuda", "rocm", "hip", "sycl", "metal", "cpu", "darwin-x86"),
|
|
"capability %q leaked a build tag into the variant ranker", capability)
|
|
}
|
|
})
|
|
})
|