import type { GpuInfo } from "../platform/base.js"; /** * Workstation resource-sizing math for local inference, lifted directly from the * blueprint's "Resource Sizing and Tuning Formulations" and "Local Quantization * Evaluation Matrix". Every constant here mirrors a blueprint parameter so the * generated env block is auditable against the spec — see the named constants * below for the formula each one belongs to. * * The functions are pure (no I/O, no runner) so they unit-test exactly and the * emitted env block regenerates byte-identically on re-run. */ /** * Fraction of total RAM the model server may use; the remaining 1 − this is the * blueprint's reserved boundary for host OS processes and open IDE workspaces * (protects against OOM crashes). M_server = floor(HOST_MEMORY_FRACTION · M_total). */ export declare const HOST_MEMORY_FRACTION = 0.8; /** * Physical cores reserved for system interrupt handling; the thread pool is * cores − this. Setting threads above physical cores thrashes on context * switching, so the pool never exceeds (cores − RESERVED_CORES). */ export declare const RESERVED_CORES = 2; /** * Context-buffer expansion factor applied per concurrent request to account for * KV-cache growth during sequence generation. parallel = M_server / (modelGb · this). */ export declare const KV_CACHE_EXPANSION = 1.2; /** A row of the blueprint's quantization evaluation matrix. */ export interface Quantization { /** Format label as it appears in the matrix (e.g. "Q4_K_M"). */ readonly name: string; /** Bits per weight. */ readonly bitsPerWeight: number; /** Model memory as a fraction of the FP16 base size. */ readonly memoryFraction: number; /** Minimum VRAM (GB) this format targets, per the matrix's sizing column. */ readonly minVramGb: number; /** One-line accuracy/footprint note from the matrix. */ readonly note: string; } /** * The quantization matrix, ordered most-precise → most-compressed (matches the * blueprint table top-to-bottom). `minVramGb` encodes each row's "Hardware * Sizing Target": FP16 server-grade, Q8_0 ≥24GB, Q5_K_M 16GB, Q4_K_M 8–12GB, * Q3_K_S 8GB unified. */ export declare const QUANTIZATIONS: readonly Quantization[]; /** The blueprint's recommended balanced default for developer workstations. */ export declare const DEFAULT_QUANTIZATION = "Q4_K_M"; /** The most-compressed format; the floor when even the smallest tier is in doubt. */ export declare const FLOOR_QUANTIZATION = "Q3_K_S"; export interface HardwareProfile { /** Total physical RAM in GB. */ totalRamGb: number; /** Physical CPU core count. */ cpuCores: number; gpu: GpuInfo; } export interface SizingResult { /** Max memory (GB) for the model server: floor(0.8 · totalRamGb). */ serverMemoryGb: number; /** Inference thread-pool size: max(1, cpuCores − 2). */ threads: number; /** Max concurrent requests: floor(serverMemoryGb / (modelSizeGb · 1.2)), min 1. */ parallelRequests: number; /** Recommended quantization name given available VRAM. */ quantization: string; } /** M_server = floor(HOST_MEMORY_FRACTION · M_total); reserves the host boundary. */ export declare function serverMemoryGb(totalRamGb: number): number; /** Thread pool = cores − RESERVED_CORES, floored at 1 so tiny hosts still run. */ export declare function inferenceThreads(cpuCores: number): number; /** * parallel = floor(M_server / (modelGb · KV_CACHE_EXPANSION)), never below 1. * A non-positive model size cannot be sized against, so it degrades to 1. */ export declare function parallelRequests(serverMemGb: number, modelSizeGb: number): number; /** * Pick the highest-precision quantization whose `minVramGb` fits within * available VRAM (walking the matrix from FP16 down). Q3_K_S has `minVramGb` 0 * so it is always reachable as the floor; a host with no GPU lands there. */ export declare function recommendQuantization(vramGb: number): string; /** Compute the full sizing result for a profiled host and a target model size. */ export declare function sizeForHost(profile: HardwareProfile, modelSizeGb: number): SizingResult;