Merge f-0243-strixspeed into f-0243-rel

This commit is contained in:
Niko1221 committed 2026-10-24 22:13:52 +02:00
commit 2dbdea2a77
3 files changed
+73 -7

No files matched your search

+5 -7
View File
@@ -6,6 +6,8 @@ import { useEffect, useState } from 'react';
import { api } from '../lib/client';
import { refreshNative, useNative, type NativeField } from '../lib/native';
import { Btn, ErrorNotice, Select } from './ui';
import { speedOptions } from '../lib/deepseek-speed';
import type { RunCard } from '../lib/native-fit';
import { NativeMcpEditor } from './NativeMcpEditor';
export function NativeSettings({ model }: {
model: string;
@@ -117,16 +119,12 @@ function NativeFieldInput({ field, value, onChange }: {
return <DecimalInput disabled={field.supported === false} ariaLabel={tr(field.label)} placeholder={tr("Default")} value={value === null || value === undefined || value === '' || !Number.isFinite(Number(value)) ? null : Number(value)} onChange={onChange}/>;
return <input disabled={field.supported === false} className="st-input" aria-label={tr(field.label)} placeholder={tr("Default")} value={Array.isArray(value) ? value.join(', ') : value ?? ''} onChange={e => onChange(e.target.value === '' ? null : field.type === 'array' ? e.target.value.split(',').map(s => s.trim()).filter(Boolean) : field.type === 'number' ? Number(e.target.value) : e.target.value)}/>;
}
/** DeepSeek's Speed choice. The engine's own rule (--experts auto): Faster (5 experts) when the graphics cards in use total 16 GB (17,179,869,184 bytes) or less, else Full quality (6). */
const SIXTEEN_GIB = 17179869184;
/** DeepSeek's Speed choice. The engine decides the default itself (--experts auto); the labels name the same default (lib/deepseek-speed.ts). */
function DeepSeekSpeed({ field, value, onChange }: { field: NativeField; value: any; onChange: (v: any) => void }) {
const native = useNative();
const cards = (native?.hardware?.gpus ?? []).filter(g => g.usable !== false);
const total = cards.reduce((sum, g) => sum + (g.vram_gb ?? 0) * 1073741824, 0);
const faster = total > 0 && total <= SIXTEEN_GIB;
const options = speedOptions(native?.hardware?.gpus as RunCard[] | undefined).map(o => ({ ...o, label: tr(o.label) }));
return <Select disabled={field.supported === false} ariaLabel={tr(field.label)} value={value === null || value === undefined ? '' : String(value)}
options={[{ value: '', label: tr(faster ? 'Default (Faster on this PC)' : 'Default (Full quality on this PC)') }, { value: '5', label: tr('Faster') }, { value: '6', label: tr('Full quality') }]}
onChange={v => onChange(v === '' ? null : v)}/>;
options={options} onChange={v => onChange(v === '' ? null : v)}/>;
}
function NativeAliases({ field, value, onChange }: {
field: NativeField;
+30
View File
@@ -0,0 +1,30 @@
import type { RunCard } from './native-fit';
/**
* DeepSeek's Speed default, said the way the engine decides it (`--experts auto`, src/dsv41/ds4_experts_rule.hpp): Faster (5 experts a word) when
* a card in use is an integrated / unified-memory GPU (Strix Halo, gfx1151: the model shares the PC's memory), or when the cards in use total
* 16 GiB or less; otherwise Full quality (6). The app never decides: the engine does; this only names the same default beside the choice.
* The total is compared in whole MiB (a 16 GB card reports 16376 MiB = 15.99 GiB and counts as 16 GiB or less).
*/
export const FASTER_MIB = 16 * 1024;
export const isIntegrated = (card: RunCard) => !!(card.uma || card.integrated || (card.unified_gb ?? 0) > 0);
export function fasterByDefault(cards: readonly RunCard[] | null | undefined): boolean {
const used = (cards ?? []).filter(card => card.usable !== false);
if (!used.length) return false;
if (used.some(isIntegrated)) return true;
const mib = used.reduce((sum, card) => sum + Math.round((card.vram_gb ?? 0) * 1024), 0);
return mib > 0 && mib <= FASTER_MIB;
}
/** The three entries of the Speed select: "Faster" or "Full quality" says "(default on this PC)" when it is what the engine picks by itself. */
export function speedOptions(cards: readonly RunCard[] | null | undefined): { value: string; label: string }[] {
const faster = fasterByDefault(cards);
const mark = ' (default on this PC)';
return [
{ value: '', label: faster ? 'Default (Faster on this PC)' : 'Default (Full quality on this PC)' },
{ value: '5', label: 'Faster' + (faster ? mark : '') },
{ value: '6', label: 'Full quality' + (faster ? '' : mark) },
];
}
+38
View File
@@ -0,0 +1,38 @@
/** The Speed label names the default the way the engine decides it: integrated / unified-memory GPU, or cards totalling 16 GiB or less. */
import test from 'node:test';
import assert from 'node:assert/strict';
import { build } from 'esbuild';
import { fileURLToPath } from 'node:url';
const out = await build({ entryPoints: [fileURLToPath(new URL('../src/lib/deepseek-speed.ts', import.meta.url))], bundle: true, format: 'esm', platform: 'node', write: false, logLevel: 'silent' });
const { fasterByDefault, speedOptions } = await import(`data:text/javascript;base64,${Buffer.from(out.outputFiles[0].text).toString('base64')}`);
const card = (vram_gb, extra = {}) => ({ index: 0, name: 'GPU', vram_gb, ...extra });
test('Strix Halo (an integrated / unified-memory GPU) defaults to Faster, whatever its memory figure says', () => {
assert.equal(fasterByDefault([card(96, { uma: true })]), true, 'a 96 GB share is not "16 GiB or less", the integrated rule applies');
assert.equal(fasterByDefault([card(0, { unified_gb: 128 })]), true);
assert.equal(fasterByDefault([card(64, { integrated: true })]), true);
assert.equal(fasterByDefault([card(24), card(96, { uma: true })]), true, 'an integrated card among the cards in use');
});
test('discrete cards: Faster at 16 GiB or less in total, Full quality above', () => {
assert.equal(fasterByDefault([card(11.9)]), true, 'RTX 5070 / 3060 12 GB');
assert.equal(fasterByDefault([card(15.99)]), true, 'a 16 GB card reports 16376 MiB');
assert.equal(fasterByDefault([card(16)]), true);
assert.equal(fasterByDefault([card(8), card(8)]), true, 'two 8 GB cards total 16');
assert.equal(fasterByDefault([card(16.05)]), false);
assert.equal(fasterByDefault([card(24)]), false);
assert.equal(fasterByDefault([card(8), card(12)]), false);
assert.equal(fasterByDefault([card(24, { usable: false }), card(12)]), true, 'a card the engine cannot use does not count');
assert.equal(fasterByDefault([]), false);
assert.equal(fasterByDefault(null), false);
});
test('the labels say "(default on this PC)" beside the choice that is the default, once', () => {
const faster = speedOptions([card(12)]).map(o => o.label);
assert.deepEqual(faster, ['Default (Faster on this PC)', 'Faster (default on this PC)', 'Full quality']);
const full = speedOptions([card(24)]).map(o => o.label);
assert.deepEqual(full, ['Default (Full quality on this PC)', 'Faster', 'Full quality (default on this PC)']);
const strix = speedOptions([card(96, { uma: true })]).map(o => o.label);
assert.deepEqual(strix, ['Default (Faster on this PC)', 'Faster (default on this PC)', 'Full quality']);
});