From baef3ed9a1e81c4b620f6923857b1c080bffec5b Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Fri, 9 Oct 2026 19:28:54 +0200 Subject: [PATCH] ui: Models Manager Follow-up Improvements (#30228) * common : read a GGUF's trained context from its metadata common_get_gguf_n_ctx_train opens only the file's metadata (no_alloc, like common_get_decision_type) and reads .context_length, so a caller can learn the trained context without loading the model. It accepts both u32 and u64 values and returns 0 when the file is missing, unreadable, invalid, or reports no context length. Assisted-by: pi:zai-org/GLM-5.3-Flash * server : report the trained context in the models listing update_caps already resolves the model file offline to read its modalities, so it now reads the trained context from the same GGUF metadata, and GET /models reports it as context_length when it is known. A router listing then carries the context without any Hub request, which lets the UI sort and filter by it offline. Assisted-by: pi:zai-org/GLM-5.3-Flash * ui : take the trained context from the models listing The router now reports context_length per model, so the option mapping fills contextLength from it and the manager reads it before the Hub record. The Context column, the context sort and the context filter then work with the Hugging Face Hub API turned off. A browser suite guards the sort and the search, the Hub-cache driven context filter and the re-sort when details arrive after the sort was clicked. Assisted-by: pi:zai-org/GLM-5.3-Flash * ui : mark favorite models with a heart A favorited model shows a rose heart in the selector even before its row is hovered, and the crossed heart takes its place on hover, so unfavoriting stays one hover away. The manager table marks its favorited rows with the same heart after the badges and capabilities. Assisted-by: pi:zai-org/GLM-5.3-Flash * fix: UI text nit * fix: UI nits * fix: Favorite models grouping in models table * feat: Remove sorting from Status column in Models Table * server: read the GGUF metadata once per model Read the decision type and the trained context in a single GGUF open, accept only a UINT32 context length like the model loader, and reset n_ctx_train with the other caps so a failed refresh drops it. * fix: Post-review fixes --------- Co-authored-by: Pascal --- common/common.cpp | 35 +-- common/common.h | 10 +- tools/server/server-models.cpp | 13 +- tools/server/server-models.h | 1 + .../app/models/ModelRowActions.svelte | 57 ++-- .../models/ModelsManager/ModelsManager.svelte | 31 ++- .../ModelsManagerModelRow.svelte | 9 +- .../ModelsManagerModelsTable.svelte | 11 +- .../app/models/ModelsManager/utils.ts | 21 +- .../ModelsSelectorDropdown.svelte | 2 +- .../dropdown-menu-content.svelte | 2 +- .../dropdown-menu/dropdown-menu-item.svelte | 2 +- .../src/lib/constants/settings.constants.ts | 2 +- tools/ui/src/lib/enums/model.enums.ts | 3 +- .../ui/src/lib/stores/models/index.svelte.ts | 7 + tools/ui/src/lib/types/api.d.ts | 2 + .../models-manager-sort-filter.svelte.test.ts | 243 ++++++++++++++++++ 17 files changed, 357 insertions(+), 94 deletions(-) create mode 100644 tools/ui/tests/client/models-manager-sort-filter.svelte.test.ts diff --git a/common/common.cpp b/common/common.cpp index 48caa80c1..28ab9ac6c 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1195,7 +1195,9 @@ common_decision_type common_get_decision_type(const struct llama_model * model) return common_decision_type_from_string(buf); } -common_decision_type common_get_decision_type(const std::string & fname) { +common_gguf_info common_get_gguf_info(const std::string & fname) { + common_gguf_info info; + struct gguf_init_params gguf_params = { /* .no_alloc = */ true, /* .ctx = */ nullptr, @@ -1203,31 +1205,32 @@ common_decision_type common_get_decision_type(const std::string & fname) { gguf_context_ptr gguf_ctx(gguf_init_from_file(fname.c_str(), gguf_params)); if (!gguf_ctx) { - return COMMON_DECISION_TYPE_UNKNOWN; // missing or unreadable file + return info; // missing or unreadable file } - std::string arch; const int64_t arch_id = gguf_find_key(gguf_ctx.get(), "general.architecture"); - if (arch_id < 0) { - return COMMON_DECISION_TYPE_UNKNOWN; // no architecture in the metadata + if (arch_id < 0 || gguf_get_kv_type(gguf_ctx.get(), arch_id) != GGUF_TYPE_STRING) { + return info; // no architecture in the metadata } - if (gguf_get_kv_type(gguf_ctx.get(), arch_id) != GGUF_TYPE_STRING) { - return COMMON_DECISION_TYPE_UNKNOWN; // malformed metadata - } - arch = gguf_get_val_str(gguf_ctx.get(), arch_id); + const std::string arch = gguf_get_val_str(gguf_ctx.get(), arch_id); if (arch.empty()) { - return COMMON_DECISION_TYPE_UNKNOWN; + return info; } - const std::string key = arch + ".decision.type"; - const int64_t type_id = gguf_find_key(gguf_ctx.get(), key.c_str()); + const int64_t type_id = gguf_find_key(gguf_ctx.get(), (arch + ".decision.type").c_str()); if (type_id < 0) { - return COMMON_DECISION_TYPE_NONE; + info.decision_type = COMMON_DECISION_TYPE_NONE; + } else if (gguf_get_kv_type(gguf_ctx.get(), type_id) == GGUF_TYPE_STRING) { + info.decision_type = common_decision_type_from_string(gguf_get_val_str(gguf_ctx.get(), type_id)); } - if (gguf_get_kv_type(gguf_ctx.get(), type_id) != GGUF_TYPE_STRING) { - return COMMON_DECISION_TYPE_UNKNOWN; // malformed metadata + + // same key and type as the model loader + const int64_t ctx_id = gguf_find_key(gguf_ctx.get(), (arch + ".context_length").c_str()); + if (ctx_id >= 0 && gguf_get_kv_type(gguf_ctx.get(), ctx_id) == GGUF_TYPE_UINT32) { + info.n_ctx_train = gguf_get_val_u32(gguf_ctx.get(), ctx_id); } - return common_decision_type_from_string(gguf_get_val_str(gguf_ctx.get(), type_id)); + + return info; } common_init_result::common_init_result(common_params & params, bool model_only) : diff --git a/common/common.h b/common/common.h index 557518e36..d2fe10fd7 100644 --- a/common/common.h +++ b/common/common.h @@ -970,9 +970,13 @@ enum common_decision_type { common_decision_type common_get_decision_type(const struct llama_model * model); -// same as above, but reads a GGUF file; it does not load the model -// returns COMMON_DECISION_TYPE_UNKNOWN if the file is missing, unreadable, or invalid -common_decision_type common_get_decision_type(const std::string & fname); +// metadata of a GGUF file, read without loading the model +struct common_gguf_info { + common_decision_type decision_type = COMMON_DECISION_TYPE_UNKNOWN; // UNKNOWN if the file is missing, unreadable, or invalid + uint32_t n_ctx_train = 0; // 0 if unknown +}; + +common_gguf_info common_get_gguf_info(const std::string & fname); // note: defines the model, context, samplers, ets. lifetimes struct common_init_result { diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp index 35d21c876..60353240a 100644 --- a/tools/server/server-models.cpp +++ b/tools/server/server-models.cpp @@ -540,6 +540,7 @@ void server_model_meta::update_args(common_preset_context & ctx_preset, std::str void server_model_meta::update_caps(const common_params & base) { // reset to the default so a failed refresh cannot keep old values architecture = server_model_architecture_json(false, false, false, {"text"}); + n_ctx_train = 0; // resolve the model file offline; do not download common_params params; @@ -564,10 +565,12 @@ void server_model_meta::update_caps(const common_params & base) { return; } - // read the output modalities from the GGUF metadata + // read the output modalities and the trained context from the GGUF metadata std::vector output_modalities = {"text"}; if (!params.model.path.empty()) { - output_modalities = server_model_output_modalities(common_get_decision_type(params.model.path)); + const common_gguf_info info = common_get_gguf_info(params.model.path); + output_modalities = server_model_output_modalities(info.decision_type); + n_ctx_train = info.n_ctx_train; } bool inp_image = false; @@ -2122,9 +2125,13 @@ void server_models_routes::init_routes() { {"source", server_model_source_to_string(meta.source)}, {"can_remove", meta.source == SERVER_MODEL_SOURCE_CACHE}, // {"need_download", meta.need_download}, - // TODO: add other fields, may require reading GGUF metadata + // TODO: add other fields from the GGUF metadata }; + if (meta.n_ctx_train > 0) { + model_info["context_length"] = meta.n_ctx_train; + } + // merge with loaded_info from the child process if available if (meta.is_running()) { for (auto it = meta.loaded_info.begin(); it != meta.loaded_info.end(); ++it) { diff --git a/tools/server/server-models.h b/tools/server/server-models.h index 238955e7c..f415b7c5f 100644 --- a/tools/server/server-models.h +++ b/tools/server/server-models.h @@ -86,6 +86,7 @@ struct server_model_meta { int stop_timeout = 0; // seconds to wait before force-killing the model instance during shutdown bool hidden = false; // hidden from GET /models, but still accept if requested json architecture = server_model_architecture_json(false, false, false, {"text"}); + uint32_t n_ctx_train = 0; // trained context, read from the GGUF metadata; 0 when unknown bool is_ready() const { return status == SERVER_MODEL_STATUS_LOADED; diff --git a/tools/ui/src/lib/components/app/models/ModelRowActions.svelte b/tools/ui/src/lib/components/app/models/ModelRowActions.svelte index 8f173174a..b40f88d83 100644 --- a/tools/ui/src/lib/components/app/models/ModelRowActions.svelte +++ b/tools/ui/src/lib/components/app/models/ModelRowActions.svelte @@ -12,37 +12,38 @@ } let { isFav, option, revealOnHover = true }: Props = $props(); + + // the favorite heart stays visible, so the reveal applies to the other icons + const revealClass = + 'pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 [@media(pointer:coarse)]:pointer-events-auto [@media(pointer:coarse)]:opacity-100';
event.stopPropagation()} onkeydown={(event) => event.stopPropagation()} role="presentation" > - - // a phone has no manager: its information dialog takes the icon - deviceStore.isMobile - ? uiStore.openModelInformation(option) - : uiStore.openModelsManager(option.id)} - tooltip="Manage model" - tooltipAsTitle - /> + + + // a phone has no manager: its information dialog takes the icon + deviceStore.isMobile + ? uiStore.openModelInformation(option) + : uiStore.openModelsManager(option.id)} + tooltip="Manage model" + tooltipAsTitle + /> + {#if isFav} modelsStore.toggleFavorite(option.model)} @@ -63,13 +64,15 @@ {:else} - modelsStore.toggleFavorite(option.model)} - tooltip="Add to favorites" - tooltipAsTitle - /> + + modelsStore.toggleFavorite(option.model)} + tooltip="Add to favorites" + tooltipAsTitle + /> + {/if}
diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte index e6020e917..36fd3e22a 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte @@ -16,7 +16,7 @@ import type { ModelOption } from '$lib/types/models'; import { filterModelOptions } from '$lib/utils'; import { type Snippet, untrack } from 'svelte'; - import { SvelteMap, SvelteSet } from 'svelte/reactivity'; + import { SvelteMap } from 'svelte/reactivity'; interface Props { class?: string; @@ -170,16 +170,29 @@ if (remaining.length > 0) rest.push({ ...entry, base: remaining[0], quants: remaining }); } - const claimed = new SvelteSet(); - const favorites = rest.filter((entry) => - entry.quants.some((q) => modelsStore.favoriteModelIds.has(q.model)) - ); + // a favorite quant stands on its own, listed flat like a loaded one, and the + // quants left behind stay with their repo in the local block + const favorites: ModelQuantGroup[] = []; + const localRest: ModelQuantGroup[] = []; - for (const entry of favorites) claimed.add(entry.key); + for (const entry of rest) { + for (const quant of entry.quants) { + if (modelsStore.favoriteModelIds.has(quant.model)) { + favorites.push({ ...entry, base: quant, key: quant.id, quants: [quant] }); + } + } - const { hidden, local } = splitHiddenQuants( - rest.filter((entry) => !claimed.has(entry.key)), - (option) => modelsStore.isHidden(option.id) + const remaining = entry.quants.filter( + (quant) => !modelsStore.favoriteModelIds.has(quant.model) + ); + + if (remaining.length > 0) { + localRest.push({ ...entry, base: remaining[0], quants: remaining }); + } + } + + const { hidden, local } = splitHiddenQuants(localRest, (option) => + modelsStore.isHidden(option.id) ); const ordered: ModelsTableGroup[] = []; // loaded models lead the table, then favorites, then the local block diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte index f4d86b729..2ded1926c 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte @@ -7,7 +7,7 @@ import ModelsManagerStatusCell from './ModelsManagerStatusCell.svelte'; import { modelRowActions } from './row-actions'; import { configuredContext, downloadProgressFor } from './utils'; - import { MoreHorizontal } from '@lucide/svelte'; + import { Heart, MoreHorizontal } from '@lucide/svelte'; import { DropdownMenuActions } from '$lib/components/app'; import { MODEL_ROW_GRID_CLASS, MODEL_ROW_TRAILING_CELL_CLASS } from '$lib/constants'; import { ModelRowDownloadState } from '$lib/enums'; @@ -74,6 +74,13 @@ + + {#if favorite} + +