okami.mom/strata

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

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
2.8 KiB43 linesraw
1import { BASE_CONTEXT, cacheGb, DENSE_GB, MTP_VRAM_GB, ownPathFits, type ContextFit } from './native-fit';
2
3/**
4 * The conversation context a model opens with: 128K for every configuration, unless the person picks another (owner, 11-01). Where the
5 * model's own largest choice is under 128K, that largest choice. The engine's own recommendation (catalog.recommendation.context, which the
6 * Terminal still uses) is not what the app opens with.
7 */
8export const DEFAULT_CONTEXT = 131072;
9/** What the Models page used to open with: a saved model that holds exactly this has never had a context chosen for it. */
10export const OLD_DEFAULT_CONTEXT = 32768;
11
12/** The default among the sizes a model offers: 128K, or the largest size under it. */
13export function defaultContext(choices: readonly number[] | null | undefined): number {
14  const sizes = (choices ?? []).filter(n => Number.isFinite(n) && n > 0);
15  const under = sizes.filter(n => n <= DEFAULT_CONTEXT);
16  return under.length ? Math.max(...under) : sizes.length ? Math.min(...sizes) : DEFAULT_CONTEXT;
17}
18
19/**
20 * What a model that is already on this computer opens with: the context it was prepared with when someone chose it, else the default. A choice made
21 * from this update on is saved with a marker (`chosen`), whatever its size, 32K included; only an old saved 32K without a marker (the old default) moves
22 * to the new default.
23 */
24export function openingContext(saved: number | null | undefined, choices: readonly number[] | null | undefined, chosen = false, oldDefaults: readonly number[] = [OLD_DEFAULT_CONTEXT]): number {
25  return saved && saved > 0 && (chosen || !oldDefaults.includes(saved)) ? saved : defaultContext(choices);
26}
27
28/**
29 * Graphics memory left for the model's own data after the conversation memory of this context (the app's estimate, the same figures as the This
30 * computer card: dense weights and buffers, the conversation cache, the draft layer). Under ONE_GB the card is tight at this context.
31 */
32export function roomAfterContext(vramGb: number, context: number, kv = 'int8'): number {
33  const dense = Math.max(DENSE_GB - cacheGb(BASE_CONTEXT), 0) + cacheGb(context, kv);
34  return vramGb - dense - MTP_VRAM_GB;
35}
36/** A context past 32K that leaves a card under 1 GB for the model (the 32K default would leave more); for Qwen3.6 (`fit`, from the catalog), a context
37 *  that does not fit the card by its own rule (#5715, strata_control/own_path_fit.py). Said as a warning; nothing is refused or lowered. */
38export function contextIsTight(vramGb: number | null | undefined, context: number, kv = 'int8', fit?: ContextFit | null): boolean {
39  const vram = Number(vramGb);
40  if (!Number.isFinite(vram) || vram <= 0) return false;
41  if (fit) return !ownPathFits(fit, vram, context);
42  return context > BASE_CONTEXT && roomAfterContext(vram, context, kv) < 1;
43}