From 095e524fca8cbe7a8536a578b4f89c045ec84c8f Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 20 Oct 2026 19:02:06 +0200 Subject: [PATCH] App: GPU roles in the generic Run screen (two or more cards), preview fixture can name its cards --- apps/host/src/screens/ModelRun.tsx | 15 ++++++++++++--- apps/host/tests/fixtures/onboarding-ui-host.mjs | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/host/src/screens/ModelRun.tsx b/apps/host/src/screens/ModelRun.tsx index 16ec83e9..d3674544 100644 --- a/apps/host/src/screens/ModelRun.tsx +++ b/apps/host/src/screens/ModelRun.tsx @@ -9,6 +9,8 @@ import { api } from '../lib/client'; import { RunningModels } from '../components/RunningModels'; import { LocalModelImport } from '../components/LocalModelImport'; import { gpuId } from '../lib/monitor-hardware'; +import { GpuRoles } from '../components/GpuRoles'; +import { normalize as normalizeRoles, order as roleOrder, recommend as recommendRoles, sameRoles, type RoleCard, type Roles } from '../lib/gpu-roles'; import { RunImageModel } from '../components/RunImageModel'; import { IMAGE_GENERATION_VISIBLE } from '../lib/features'; import { FloatingMenu } from '../components/FloatingMenu'; @@ -49,6 +51,8 @@ function LegacyModelRunScreen({ importFirst = false, initialVariant }: { const runtime = useStore(s => s.runtime); const [deviceChoice, setDeviceChoice] = useState('auto'); const [customGpus, setCustomGpus] = useState([]); + // Two or more cards (Expert settings): a role for each card instead of the "Run on" list. null = the recommended roles. + const [runRoles, setRunRoles] = useState(null); const placementInitialized = useRef(''); const imageModels = useStore(s => s.imageModels), imagePending = useStore(s => !!s.busy['image:select']); const imageChoice = imageModels?.selected ?? 'off'; @@ -123,8 +127,11 @@ function LegacyModelRunScreen({ importFirst = false, initialVariant }: { const profileChanged = !!selectedProfile && !!config && (configIdentity(config) !== configIdentity(selectedProfile.config) || imageChoice !== (selectedProfile.imageModel ?? 'off')); const use = config?.headroom === 'full' ? 'full' : 'shared'; const ctx = contextTokens(config?.beginner.contextLength ?? 'recommended'); + const roleCards: RoleCard[] = (hardware?.gpus ?? []).map((g, i) => ({ index: i, name: g.name, vram_gb: g.vramGb ?? 0, integrated: !!g.unified, vendor: g.vendor })); + const rolesMode = expert && roleCards.length > 1; + const recommendedRoles = recommendRoles(roleCards).roles, effectiveRoles: Roles = runRoles ? normalizeRoles(runRoles, roleCards) : recommendedRoles; const effectiveDevice = expert ? deviceChoice : 'auto'; - const gpuIds = hardware ? (effectiveDevice === 'auto' ? hardware.gpus.map(gpuId) : effectiveDevice === 'cpu' ? [] : effectiveDevice === 'custom' ? customGpus : [effectiveDevice]) : []; + const gpuIds = hardware ? (rolesMode ? roleOrder(effectiveRoles, roleCards).map(i => gpuId(hardware.gpus[i])) : effectiveDevice === 'auto' ? hardware.gpus.map(gpuId) : effectiveDevice === 'cpu' ? [] : effectiveDevice === 'custom' ? customGpus : [effectiveDevice]) : []; const executionHardware = hardware ? { ...hardware, gpus: hardware.gpus.filter(g => gpuIds.includes(gpuId(g))), accelerator: { ...hardware.accelerator, backend: gpuIds.length ? hardware.accelerator.backend : 'cpu', unified: gpuIds.length ? hardware.accelerator.unified : false, usableVramGb: hardware.gpus.filter(g => gpuIds.includes(gpuId(g))).reduce((n, g) => n + g.vramGb, 0) } } : null; const cfg = execution({ ...config?.expert, ...(!expert ? { 'gpu.layers': gpuIds.length ? 'Automatic' : 'CPU only' } : !gpuIds.length ? { 'gpu.layers': 'CPU only' } : {}) }, ctx); const baseExperience = estimate(model, executionHardware, cfg, 'document', library?.mode === 'simulated' && !model?.local); @@ -213,7 +220,7 @@ function LegacyModelRunScreen({ importFirst = false, initialVariant }: { }); }, 180); return () => { active = false; clearTimeout(timer); }; - }, [text, model?.id, deviceChoice, customGpus.join(','), runtime?.revision, connected, expert, executionMode]); + }, [text, model?.id, deviceChoice, customGpus.join(','), JSON.stringify(runRoles), runtime?.revision, connected, expert, executionMode]); function loadPatch(doc: ConfigDocument) { const patch = configPatch(doc); if (!expert || !gpuIds.length) @@ -378,7 +385,7 @@ function LegacyModelRunScreen({ importFirst = false, initialVariant }: { else { if (!lifecycle.allowed) throw new Error(lifecycle.reason); - if (expert && deviceChoice !== 'auto') + if (expert && (rolesMode ? !!runRoles : deviceChoice !== 'auto')) throw new Error('GPU assignment requires a native engine adapter. Use Automatic with this host.'); await saveEngine(patch, true, true); const ok = getState().library?.loaded === model.id ? await restartEngine() : await loadVariant(model.id); @@ -443,9 +450,11 @@ function LegacyModelRunScreen({ importFirst = false, initialVariant }: { {tr(expert ?

{tr("Model execution")}

+ {rolesMode ? { setRunRoles(sameRoles(next, recommendedRoles) ? null : next); setStage('idle'); setIssues([]); }} onBack={() => { setRunRoles(null); setStage('idle'); setIssues([]); }}/> : <> {tr("Run on")} { setCustomGpus(ids => e.target.checked ? [...ids, gpuId(g)] : ids.filter(id => id !== gpuId(g))); setStage('idle'); }}/>{tr("GPU ")}{tr(i + 1)} · {tr(g.name)}{tr(g.unified ? 'Shared system memory' : `${sizeGb(g.vramGb)} VRAM`)}))} : null)} + }

{tr(runtime?.capabilities.multipleModels === false ? 'This native host currently supports one model with automatic GPU placement.' : !allowMultiple ? 'One model at a time. Loading switches to the selected model.' : placementPlan?.reloads ? 'Loading applies these settings to this instance. Other models stay loaded.' : 'Loading adds a model. Existing models keep their settings and GPU assignments.')}

{tr(runtime?.instances.length ?
{tr(placementPlan && !placementPlan.alreadyLoaded ? 'Shared RAM after load' : 'Shared RAM reserved')} {tr((placementPlan?.budget.ramGb ?? runtime.memory.ramGb).toFixed(1))} / {tr((placementPlan?.budget.budgetGb ?? runtime.memory.budgetGb).toFixed(1))}{tr(" GB")}{tr(runtime.memory.reserveGb.toFixed(0))}{tr(" GB RAM headroom \u00B7 estimates include all loaded models")}{tr((placementPlan?.budget.devices ?? runtime.memory.devices).map(d => {tr(d.name)}{tr(d.usedGb.toFixed(1))} / {tr(d.budgetGb.toFixed(1))}{tr(" GB")}))}
: null)}
: null)} diff --git a/apps/host/tests/fixtures/onboarding-ui-host.mjs b/apps/host/tests/fixtures/onboarding-ui-host.mjs index f9d82db1..afd049ac 100644 --- a/apps/host/tests/fixtures/onboarding-ui-host.mjs +++ b/apps/host/tests/fixtures/onboarding-ui-host.mjs @@ -7,6 +7,7 @@ const root=resolve(import.meta.dirname,'../../dist'),upstream=process.env.STRATA const native=process.env.STRATA_UI_PREVIEW==='1' ? JSON.parse(await readFile(new URL('./ui-preview-native.json',import.meta.url),'utf8')) : await (await fetch(upstream+'/api/native')).json(); native.hardware={cpu:{cores:16},ram_gb:128,gpus:[{index:0,name:'NVIDIA RTX 4090',vram_gb:24,usable:true}],disk_free_gb:250}; if(process.env.STRATA_ONBOARDING_SCENARIO==='multi-gpu')native.hardware.gpus.push({index:1,name:'NVIDIA RTX 3090',vram_gb:24,usable:true}); +if(process.env.STRATA_ONBOARDING_GPUS)native.hardware.gpus=JSON.parse(process.env.STRATA_ONBOARDING_GPUS); native.catalog.this_pc=native.hardware; native.catalog.recommendation={family:'qwen',model:'Q2_0',context:32768}; native.catalog.summary='Supported hardware fixture'; @@ -60,6 +61,7 @@ if(['make-it-yours','ready'].includes(process.env.STRATA_ONBOARDING_START)){ } } } +if(process.env.STRATA_ONBOARDING_GPUS){native.instances=[];native.defaultId=null;}/* GPU roles previews: the model is prepared, not loaded, so the roles shown are the recommendation */ if(process.env.STRATA_PREVIEW_STATE_FILE){const saved=JSON.parse(await readFile(process.env.STRATA_PREVIEW_STATE_FILE,'utf8'));Object.assign(native,saved.native);setup=saved.setup;const running=native.instances.find(i=>i.id===native.defaultId),entry=native.installed.models.find(m=>m.model===running?.model),family=native.catalog.families.find(f=>f.sizes.some(s=>s.id===entry?.model)),size=family?.sizes.find(s=>s.id===entry?.model);if(family&&size){selected={family:family.family,model:size.model,context:entry.context??32768,vision:entry.images==='off'?'no':'yes',kv:entry.kv??'int8',low_ram:entry.lowRamMode??'auto'};loadVision=entry.visionEnabled===false?'no':selected.vision;}} const server=http.createServer(async(req,res)=>{try{ const path=new URL(req.url,'http://fixture').pathname;let payload='';if(req.method!=='GET')for await(const chunk of req)payload+=chunk;const body=payload?JSON.parse(payload):{};