Coordinate shared GPU access across studio instances

This commit is contained in:
Towsty
2026-09-06 16:32:18 -05:00
parent 911ddeab55
commit 0c6a035d04
17 changed files with 582 additions and 64 deletions
+13 -1
View File
@@ -1,4 +1,5 @@
import { comfyInputFilename } from '~/server/utils/comfy'
import { assertSharedGpu, sharedGpuHeaders, sharedGpuConfigured } from '~/server/utils/sharedGpu'
import { comfyInputFilename, getComfyHost } from '~/server/utils/comfy'
import { getSidecarImageHost } from '~/server/utils/imageComfy'
import { ensureSidecarReady } from '~/server/utils/imageComfyLifecycle'
import { buildVisionPromptWorkflow } from '~/server/utils/promptWorkflow'
@@ -19,6 +20,7 @@ const jobs = new Map<string, PromptJob>()
const MAX_JOBS = 20
export function getPromptComfyHost() {
if (sharedGpuConfigured()) return getComfyHost()
return getSidecarImageHost()
}
@@ -31,6 +33,12 @@ async function promptComfyFetch(path: string, init?: RequestInit) {
if (!host) {
throw createError({ statusCode: 503, statusMessage: 'Qwen VL is not configured. Set COMFY_HOST or IMAGE_COMFY_HOST to Beast.' })
}
if (init?.method && !['GET', 'HEAD'].includes(init.method.toUpperCase())) {
await assertSharedGpu()
const headers = new Headers(init.headers)
for (const [key, value] of Object.entries(sharedGpuHeaders())) headers.set(key, value)
init = { ...init, headers }
}
try {
return await fetch(`${host}${path}`, init)
} catch (error) {
@@ -260,3 +268,7 @@ export function failPromptJob(job: PromptJob, error: unknown) {
job.error = err.statusMessage || err.message || 'Prompt recommend failed'
job.message = job.error
}
export function hasActivePromptJobs() {
return [...jobs.values()].some(job => job.status === 'queued' || job.status === 'running')
}