mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-17 20:31:47 +02:00
ui : reuse the canonical quant bit-depth and extension parsing
Drop the duplicated UD- prefix and quant bit-depth regexes from the download options utils: quantBitDepth re-implemented, more crudely, what HuggingFaceService.getBitDepth already does, and the label helper re-declared the weight-extension pattern held by MODEL_ID. The command preview now derives its bit depth via the service, so the quant chips and the command sorts agree. Assisted-by: llama-ui:Qwen3.8-Flash-Next
This commit is contained in:
+4
-2
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { quantBitDepth } from './download-options.utils';
|
||||
import { Check, Copy, Plus, X } from '@lucide/svelte';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import {
|
||||
DEFAULT_BASE_BIT_DEPTH,
|
||||
MODEL_ID,
|
||||
type ModelSidecar,
|
||||
OTHER_BIT_DEPTH,
|
||||
SERVE_COMMAND,
|
||||
SPEC_TYPE
|
||||
} from '$lib/constants';
|
||||
@@ -30,7 +30,9 @@
|
||||
let withDraft = $state(false);
|
||||
|
||||
function bitDepthOf(path: string): number {
|
||||
return quantBitDepth(HuggingFaceService.extractQuantMeta(path)?.quant ?? null);
|
||||
const quant = HuggingFaceService.extractQuantMeta(path)?.quant;
|
||||
|
||||
return quant ? (HuggingFaceService.getBitDepth(quant) ?? OTHER_BIT_DEPTH) : OTHER_BIT_DEPTH;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-23
@@ -2,20 +2,12 @@ import {
|
||||
DRAFT_FILE_LABEL,
|
||||
isAuxSidecar,
|
||||
isDraftSidecar,
|
||||
OTHER_BIT_DEPTH,
|
||||
MODEL_ID,
|
||||
PATH_SEPARATOR
|
||||
} from '$lib/constants';
|
||||
import { SelectableFileKind } from '$lib/enums';
|
||||
import { HuggingFaceService } from '$lib/services';
|
||||
|
||||
/** Leading `UD-` (Unsloth Dynamic) quant prefix and its length. */
|
||||
const UD_QUANT_PREFIX = 'UD-';
|
||||
const UD_QUANT_PREFIX_REGEX = /^UD-(?=.)/i;
|
||||
/** Captures the bit-depth digits of a quant token, e.g. `Q4_K_M` -> `4`. */
|
||||
const QUANT_BIT_DEPTH_REGEX = /(?:I?Q|F)(\d+)/i;
|
||||
/** Trailing weight extension, stripped from a quantless file's label. */
|
||||
const WEIGHT_EXTENSION_LABEL_REGEX = /\.gguf$/i;
|
||||
|
||||
/** Kind of a file path: the main weights, a draft sidecar, or an aux sidecar (mmproj). */
|
||||
export function classify(path: string): SelectableFileKind {
|
||||
const sidecar = HuggingFaceService.extractQuantMeta(path)?.sidecar;
|
||||
@@ -37,18 +29,5 @@ export function labelFor(path: string): string {
|
||||
|
||||
const basename = path.split(PATH_SEPARATOR).pop() ?? path;
|
||||
|
||||
return basename.replace(WEIGHT_EXTENSION_LABEL_REGEX, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bit depth of a quant token; `OTHER_BIT_DEPTH` when it carries none. The `UD-`
|
||||
* unsloth prefix is stripped before matching.
|
||||
*/
|
||||
export function quantBitDepth(quant: string | null): number {
|
||||
if (!quant) return OTHER_BIT_DEPTH;
|
||||
|
||||
const stripped = UD_QUANT_PREFIX_REGEX.test(quant) ? quant.slice(UD_QUANT_PREFIX.length) : quant;
|
||||
const bit = stripped.match(QUANT_BIT_DEPTH_REGEX)?.[1];
|
||||
|
||||
return bit ? Number(bit) : OTHER_BIT_DEPTH;
|
||||
return basename.replace(MODEL_ID.WEIGHT_EXTENSION_REGEX, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user