ui : move model memory-fit constants to lib

Move the hardware compatibility budget constants (MIB_BYTES, MB_PER_GB,
QUANT_WEIGHT, RAM_BUDGET_RATIO, RAM_OVERHEAD_MB, MAC_MEM_TIERS) out of
model-compatibility.ts into a new models-scoped constants file, so the
estimation util imports them from $lib/constants.

Assisted-by: llama-ui:Qwen3.8-Flash-Next
This commit is contained in:
Aleksander Grygier
2026-09-04 20:07:37 +02:00
parent a02c90cdc5
commit a8db34b0f3
3 changed files with 41 additions and 16 deletions
+1
View File
@@ -46,6 +46,7 @@ export * from './model-id.constants';
export * from './model-loading.constants';
export * from './models-discover.constants';
export * from './models-discover-download.constants';
export * from './model-compatibility.constants';
export * from './huggingface.constants';
export * from './precision.constants';
export * from './pwa.constants';
@@ -0,0 +1,32 @@
/**
* Model memory-fit constants.
*
* Mirrors the app's compatibility check (Model+Compatibility.swift):
* budget = RAM x RAM_BUDGET_RATIO - RAM_OVERHEAD_MB
* weightBytes = fileBytes x QUANT_WEIGHT
* a file fits when weightBytes <= budget. Kept here so the estimation util and
* any caller share one source.
*/
// LLAMA-APP-REUSE: hardware compatibility budget (mirrors Model+Compatibility.swift)
/** Bytes in one mebibyte (MiB), used to convert a file size to MB. */
export const MIB_BYTES = 1_048_576;
/** MB in one GB. */
export const MB_PER_GB = 1024;
/** Overhead multiplier applied to the file size when estimating weight memory. */
export const QUANT_WEIGHT = 1.05;
/** Share of RAM the app allows the model to occupy. */
export const RAM_BUDGET_RATIO = 0.75;
/** Fixed RAM overhead (MB) reserved for the system and KV cache. */
export const RAM_OVERHEAD_MB = 2048;
/**
* Memory tiers Macs ship with (GB). Tiers past 512 extrapolate Apple's step
* pattern so builds too big for any current Mac still show an honest
* requirement instead of silently omitting the line.
*/
export const MAC_MEM_TIERS = [8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 768, 1024];
+8 -16
View File
@@ -9,22 +9,14 @@
* device-specific budgets are deliberately ignored - callers present the
* requirement and let the user judge.
*/
// LLAMA-APP-REUSE: hardware compatibility estimation
const MIB_BYTES = 1_048_576;
const MB_PER_GB = 1024;
/** Overhead multiplier applied to the file size when estimating weight memory. */
const QUANT_WEIGHT = 1.05;
/** Share of RAM the app allows the model to occupy. */
const RAM_BUDGET_RATIO = 0.75;
/** Fixed RAM overhead (MB) reserved for the system and KV cache. */
const RAM_OVERHEAD_MB = 2048;
/**
* Memory tiers Macs ship with (GB). Tiers past 512 extrapolate Apple's step
* pattern so builds too big for any current Mac still show an honest
* requirement instead of silently omitting the line.
*/
const MAC_MEM_TIERS = [8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 768, 1024];
import {
MAC_MEM_TIERS,
MB_PER_GB,
MIB_BYTES,
QUANT_WEIGHT,
RAM_BUDGET_RATIO,
RAM_OVERHEAD_MB
} from '$lib/constants';
/**
* Estimated runtime memory (bytes) for a model of the given file size: