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} + +