From 1d08ea72103df1f778c5e2ab1c89493bcc7f1b8d Mon Sep 17 00:00:00 2001 From: andreinknv Date: Thu, 14 May 2026 18:57:39 -0400 Subject: [PATCH] fix(resolveGgmlTypeOption): accept case-insensitive ggml type names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously `resolveGgmlTypeOption("q8_0")` returned `undefined` because the lookup used `Object.hasOwn(GgmlType, option)` against the uppercase-by-convention enum keys (`Q8_0`, `F16`, `BF16`, ...). The caller then fell back to F16 silently — no warning, no error — making this a frustrating-to-debug "why is my Q8 KV cache acting like FP16" class of issue. This change uppercases the input string before the lookup. Numeric GgmlType enum values are still accepted unchanged. Empty / null / unrecognized values still return `undefined`. Affects: - `experimentalKvCacheKeyType` / `experimentalKvCacheValueType` on LlamaContextOptions and LlamaModelOptions - The CLI's `--kv-cache-key-type` / `--kv-cache-value-type` flags (`resolveCommandGgufPath.ts`) After: resolveGgmlTypeOption("q8_0") // => GgmlType.Q8_0 resolveGgmlTypeOption("Q8_0") // => GgmlType.Q8_0 (unchanged) resolveGgmlTypeOption("bf16") // => GgmlType.BF16 resolveGgmlTypeOption("nope") // => undefined (unchanged) --- src/gguf/types/GgufTensorInfoTypes.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gguf/types/GgufTensorInfoTypes.ts b/src/gguf/types/GgufTensorInfoTypes.ts index 39e2b984..7c19cc26 100644 --- a/src/gguf/types/GgufTensorInfoTypes.ts +++ b/src/gguf/types/GgufTensorInfoTypes.ts @@ -70,8 +70,16 @@ export function resolveGgmlTypeOption(option?: keyof typeof GgmlType | GgmlType) if (typeof option === "number" && Object.hasOwn(GgmlType, option)) return option as GgmlType; - else if (typeof option === "string" && Object.hasOwn(GgmlType, option)) - return GgmlType[option as keyof typeof GgmlType]; + else if (typeof option === "string") { + // GgmlType enum keys are conventionally uppercase (e.g. "Q8_0", + // "F16", "BF16"). Accept lowercase / mixed-case inputs so config + // files and CLI flags don't silently fall through to the default. + // Prior behaviour treated e.g. "q8_0" as unrecognised and returned + // undefined — callers then fell back to F16 with no warning. + const upper = option.toUpperCase(); + if (Object.hasOwn(GgmlType, upper)) + return GgmlType[upper as keyof typeof GgmlType]; + } return undefined; }