okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
3.0 KiB53 linesraw
1import type { Experience } from './experience';
2import type { Hardware } from './types';
3import type { ComputerUse } from './run-profiles';
4
5export interface RunMemory {
6  total: number;
7  weights: number;
8  context: number;
9  runtime: number;
10  ram: number;
11  gpu: number;
12  ssd: number;
13  budget: number;
14  reserve: number;
15  unified: boolean;
16  cacheFits: boolean;
17  devices: { name: string; budget: number }[];
18}
19
20/** A capacity planning preview. Actual placement must be verified by the engine. */
21export function planMemory(experience: Experience, hardware: Hardware | null, use: ComputerUse, parallel = 1, allowSpill = true): RunMemory | null {
22  if (!experience.memory || !hardware) return null;
23  const m = experience.memory;
24  const unified = hardware.accelerator.unified;
25  const cpuOnly = hardware.accelerator.backend === 'cpu' || experience.config.placement === 'CPU only';
26  const reserve = Math.min(hardware.memory.totalGb, use === 'shared' ? Math.max(4, hardware.memory.totalGb * .25) : Math.max(2, hardware.memory.totalGb * .125));
27  const ramBudget = Math.max(0, hardware.memory.totalGb - reserve);
28  const devices = unified || cpuOnly ? [] : hardware.gpus.filter(g => !g.unified && g.backend !== 'cpu').map(g => ({
29    name: g.name,
30    budget: Math.max(0, g.vramGb - (use === 'shared' ? Math.max(1, g.vramGb * .1) : Math.max(.5, g.vramGb * .05))),
31  }));
32  const gpuBudget = devices.reduce((sum, g) => sum + g.budget, 0);
33  // Explicit partial offload needs layer sizes, which this catalog does not expose.
34  if (!unified && !cpuOnly && !['Automatic', 'All layers'].includes(experience.config.placement)) return null;
35  const budget = ramBudget + gpuBudget;
36  const context = m.cache * Math.max(1, parallel);
37  const total = m.weights + context + m.runtime;
38  const fixed = context + m.runtime;
39  const cacheFits = fixed <= (unified || cpuOnly ? ramBudget : gpuBudget || ramBudget);
40  const ssd = cacheFits && allowSpill ? Math.min(m.weights, Math.max(0, total - budget)) : 0;
41  const gpu = Math.min(gpuBudget, total - ssd);
42  const ram = Math.min(ramBudget, Math.max(0, total - ssd - gpu));
43  return { total, weights: m.weights, context, runtime: m.runtime, ram, gpu, ssd, budget, reserve, unified, cacheFits, devices };
44}
45
46/** Illustrative preview curves stay separate from measured/estimated evidence. */
47export function demoRunExperience(experience: Experience, memory: RunMemory | null, use: ComputerUse): Experience {
48  if (experience.source !== 'demo' || !memory || !experience.reading || !experience.answer) return experience;
49  const spillFraction = memory.ssd / Math.max(1, memory.weights);
50  const factor = (use === 'full' ? 1.08 : 1) / (1 + spillFraction * 3);
51  const scale = (range: NonNullable<Experience['reading']>) => ({ low: Math.max(1, Math.round(range.low * factor)), high: Math.max(2, Math.round(range.high * factor)) });
52  return { ...experience, reading: scale(experience.reading), answer: scale(experience.answer), provenance: 'Illustrative design preview including context, computer use and SSD spill. Not a benchmark.' };
53}