Add MOSS-Image on the Image v2 path and stop the queue calling it Klein.
The bench queue labeled every engine except Krea, Qwen, MiniMax, and LTX as Klein, and the v2 starter treated any engine other than Krea as Flux. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import kreaGenerateTemplate from '../assets/krea_v2_generate.json'
|
||||
import kreaEditTemplate from '../assets/krea_v2_edit.json'
|
||||
import kreaComposeTemplate from '../assets/krea_v2_compose.json'
|
||||
import kreaRefineTemplate from '../assets/krea_v2_refine.json'
|
||||
import mossGenerateTemplate from '../assets/moss_v2_generate.json'
|
||||
import { IMAGE_SCALE_TO_TOTAL_PIXELS } from '~/server/utils/comfy'
|
||||
import { imageComfyFetch } from '~/server/utils/imageComfy'
|
||||
import { applyImageV2UserLoras } from '~/server/utils/loras'
|
||||
@@ -23,6 +24,14 @@ import {
|
||||
IMAGE_V2_KREA_STEPS,
|
||||
IMAGE_V2_KREA_UNET_CANDIDATES,
|
||||
IMAGE_V2_KREA_VAE,
|
||||
IMAGE_V2_MOSS_CFG,
|
||||
IMAGE_V2_MOSS_CLIP_CANDIDATES,
|
||||
IMAGE_V2_MOSS_CLIP_TYPE,
|
||||
IMAGE_V2_MOSS_SHIFT,
|
||||
IMAGE_V2_MOSS_SLG_LAYER,
|
||||
IMAGE_V2_MOSS_STEPS,
|
||||
IMAGE_V2_MOSS_UNET,
|
||||
IMAGE_V2_MOSS_VAE_CANDIDATES,
|
||||
IMAGE_V2_DENOISE_DEFAULT,
|
||||
IMAGE_V2_GENERATE_HEIGHT,
|
||||
IMAGE_V2_GENERATE_WIDTH,
|
||||
@@ -58,6 +67,7 @@ export const IMAGE_V2_KREA_GENERATE_WORKFLOW = 'krea_v2_generate.json'
|
||||
export const IMAGE_V2_KREA_EDIT_WORKFLOW = 'krea_v2_edit.json'
|
||||
export const IMAGE_V2_KREA_COMPOSE_WORKFLOW = 'krea_v2_compose.json'
|
||||
export const IMAGE_V2_KREA_REFINE_WORKFLOW = 'krea_v2_refine.json'
|
||||
export const IMAGE_V2_MOSS_GENERATE_WORKFLOW = 'moss_v2_generate.json'
|
||||
|
||||
export interface ImageV2BuildParams {
|
||||
mode: ImageV2Mode
|
||||
@@ -86,6 +96,10 @@ export interface ImageV2BuildParams {
|
||||
kreaClipName?: string
|
||||
kreaVaeName?: string
|
||||
kreaConceptLora?: string
|
||||
mossUnetName?: string
|
||||
mossClipName?: string
|
||||
mossVaeName?: string
|
||||
mossClipDevice?: string
|
||||
loraStack?: LoraStackItem[]
|
||||
}
|
||||
|
||||
@@ -234,6 +248,59 @@ export async function resolveKreaGenerateAssets() {
|
||||
return { unet, clip, vae, conceptLora: configuredKreaConceptLora() }
|
||||
}
|
||||
|
||||
function clipLoaderChoices(clipInfo: unknown, field: string) {
|
||||
const rec = clipInfo && typeof clipInfo === 'object' ? clipInfo as Record<string, unknown> : {}
|
||||
const body = (rec.CLIPLoader && typeof rec.CLIPLoader === 'object' ? rec.CLIPLoader : rec) as {
|
||||
input?: { required?: Record<string, unknown> }
|
||||
}
|
||||
const spec = body.input?.required?.[field]
|
||||
return Array.isArray(spec) && Array.isArray(spec[0])
|
||||
? (spec[0] as unknown[]).map(item => String(item || ''))
|
||||
: []
|
||||
}
|
||||
|
||||
export async function resolveMossGenerateAssets() {
|
||||
const [unets, clips, vaes, clipInfo] = await Promise.all([
|
||||
listComfyModels('diffusion_models'),
|
||||
listComfyModels('text_encoders').then(async (names) => names.length ? names : listComfyModels('clip')),
|
||||
listComfyModels('vae'),
|
||||
imageComfyFetch('/object_info/CLIPLoader', { signal: AbortSignal.timeout(8000) })
|
||||
.then(async (res) => res.ok ? res.json() : null)
|
||||
.catch(() => null)
|
||||
])
|
||||
const unet = pickComfyModel(unets, [IMAGE_V2_MOSS_UNET])
|
||||
if (!unet) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `MOSS diffusion model is missing on Beast Comfy (${IMAGE_V2_MOSS_UNET} in diffusion_models).`
|
||||
})
|
||||
}
|
||||
const clip = pickComfyModel(clips, [...IMAGE_V2_MOSS_CLIP_CANDIDATES])
|
||||
if (!clip) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `MOSS text encoder is missing on Beast Comfy (${IMAGE_V2_MOSS_CLIP_CANDIDATES.join(' or ')}).`
|
||||
})
|
||||
}
|
||||
const vae = pickComfyModel(vaes, [...IMAGE_V2_MOSS_VAE_CANDIDATES])
|
||||
if (!vae) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `FLUX.2 VAE is missing on Beast Comfy (${IMAGE_V2_MOSS_VAE_CANDIDATES.join(' or ')}).`
|
||||
})
|
||||
}
|
||||
const types = clipLoaderChoices(clipInfo, 'type')
|
||||
if (types.length && !types.includes(IMAGE_V2_MOSS_CLIP_TYPE)) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: 'Beast Comfy CLIPLoader has no moss_image type. Update ComfyUI to 0.42 or later before using MOSS-Image.'
|
||||
})
|
||||
}
|
||||
const devices = clipLoaderChoices(clipInfo, 'device')
|
||||
const clipDevice = !devices.length || devices.includes('cpu') ? 'cpu' : 'default'
|
||||
return { unet, clip, vae, clipDevice }
|
||||
}
|
||||
|
||||
function graphFileNames(graph: WorkflowGraph) {
|
||||
const names: string[] = []
|
||||
for (const node of Object.values(graph)) {
|
||||
@@ -298,12 +365,61 @@ function assertKreaItiGraph(graph: WorkflowGraph, mode: ImageV2Mode) {
|
||||
assertKreaShared(graph)
|
||||
}
|
||||
|
||||
function assertMossGenerateGraph(graph: WorkflowGraph) {
|
||||
const loaders = loadImageNames(graph)
|
||||
if (loaders.length) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'MOSS generate graph has a required LoadImage. Refusing to run.'
|
||||
})
|
||||
}
|
||||
const latent = Object.values(graph).find(node => node.class_type === 'EmptyFlux2LatentImage')
|
||||
if (!latent) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS generate graph is missing EmptyFlux2LatentImage.' })
|
||||
}
|
||||
const clip = graph['5']
|
||||
if (!clip || clip.class_type !== 'CLIPLoader' || String(clip.inputs.type || '') !== IMAGE_V2_MOSS_CLIP_TYPE) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph CLIPLoader type must be moss_image.' })
|
||||
}
|
||||
const shift = Object.values(graph).find(node => node.class_type === 'ModelSamplingAuraFlow')
|
||||
if (!shift || Number(shift.inputs.shift) !== IMAGE_V2_MOSS_SHIFT) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph must set shift 5 with ModelSamplingAuraFlow.' })
|
||||
}
|
||||
const slg = Object.values(graph).find(node => node.class_type === 'SkipLayerGuidanceDiTSimple')
|
||||
const layers = String(slg?.inputs.single_layers || '')
|
||||
if (!slg || !layers.split(/[^\d]+/).includes(IMAGE_V2_MOSS_SLG_LAYER) || String(slg.inputs.double_layers || '').trim()) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph skip-layer guidance must skip layer 22 only.' })
|
||||
}
|
||||
const sampler = graph['15']
|
||||
if (!sampler || sampler.class_type !== 'KSampler') {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph is missing KSampler.' })
|
||||
}
|
||||
if (Object.values(graph).some(node => node.class_type === 'Flux2Scheduler' || node.class_type === 'ReferenceLatent' || node.class_type === 'LoraLoader')) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph contains a Klein scheduler, reference, or LoRA. Refusing to run.' })
|
||||
}
|
||||
const banned = graphFileNames(graph).filter((name) => {
|
||||
const id = modelIdentity(name)
|
||||
return /flux-?2-klein|klein_snofs|krea2_turbo|qwen_3_8b|qwen3vl_4b|full_encoder_small_decoder|qwen_image_vae/i.test(id)
|
||||
})
|
||||
if (banned.length) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'MOSS graph includes a Klein or Krea model. Refusing to run.'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imageBName?: string, engine: ImageV2Engine = 'flux') {
|
||||
const loaders = loadImageNames(graph)
|
||||
if (mode === 'generate' && engine === 'krea') {
|
||||
assertKreaGenerateGraph(graph)
|
||||
} else if (engine === 'krea') {
|
||||
assertKreaItiGraph(graph, mode)
|
||||
} else if (engine === 'moss') {
|
||||
if (mode !== 'generate') {
|
||||
throw createError({ statusCode: 400, statusMessage: 'MOSS-Image is text-to-image only.' })
|
||||
}
|
||||
assertMossGenerateGraph(graph)
|
||||
} else if (mode === 'generate') {
|
||||
if (loaders.length && !(imageBName && loaders.length === 1 && graph['reference:load']?.inputs.image === imageBName)) {
|
||||
throw createError({
|
||||
@@ -503,8 +619,76 @@ function buildKreaGenerateWorkflow(params: ImageV2BuildParams) {
|
||||
return { graph, workflowFile, loaders, prompt, strength: undefined }
|
||||
}
|
||||
|
||||
function requireMossModels(params: ImageV2BuildParams) {
|
||||
if (!params.mossUnetName || !params.mossClipName || !params.mossVaeName) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: 'MOSS models were not resolved. Refusing to fall back to Flux or Krea.'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function buildMossGenerateWorkflow(params: ImageV2BuildParams) {
|
||||
if (params.mode !== 'generate') {
|
||||
throw createError({ statusCode: 400, statusMessage: 'MOSS-Image is text-to-image only.' })
|
||||
}
|
||||
requireMossModels(params)
|
||||
const graph = structuredClone(mossGenerateTemplate) as WorkflowGraph
|
||||
const prompt = composeImageV2Prompt('generate', 't2i', params.prompt)
|
||||
const negative = String(params.negative || '')
|
||||
const size = clampImageV2Size(params.width, params.height, params.aspect)
|
||||
const steps = clampImageSteps(params.steps, IMAGE_V2_MOSS_STEPS)
|
||||
const cfg = clampImageCfg(params.cfg, IMAGE_V2_MOSS_CFG)
|
||||
const workflowFile = IMAGE_V2_MOSS_GENERATE_WORKFLOW
|
||||
|
||||
setInput(graph, '4', 'unet_name', params.mossUnetName)
|
||||
setInput(graph, '5', 'clip_name', params.mossClipName)
|
||||
setInput(graph, '5', 'type', IMAGE_V2_MOSS_CLIP_TYPE)
|
||||
setInput(graph, '5', 'device', params.mossClipDevice || 'cpu')
|
||||
setInput(graph, '6', 'vae_name', params.mossVaeName)
|
||||
setInput(graph, '14', 'width', size.width)
|
||||
setInput(graph, '14', 'height', size.height)
|
||||
setInput(graph, '40', 'shift', IMAGE_V2_MOSS_SHIFT)
|
||||
setInput(graph, '41', 'single_layers', IMAGE_V2_MOSS_SLG_LAYER)
|
||||
setInput(graph, '41', 'double_layers', '')
|
||||
setInput(graph, PROMPT, 'text', prompt)
|
||||
setInput(graph, NEGATIVE, 'text', negative)
|
||||
setInput(graph, '15', 'seed', params.seed)
|
||||
setInput(graph, '15', 'steps', steps)
|
||||
setInput(graph, '15', 'cfg', cfg)
|
||||
setInput(graph, '15', 'sampler_name', 'euler')
|
||||
setInput(graph, '15', 'scheduler', 'sgm_uniform')
|
||||
setInput(graph, '15', 'denoise', 1)
|
||||
setInput(graph, SAVE, 'filename_prefix', params.filenamePrefix || 'v2-moss')
|
||||
|
||||
assertImageV2Graph(graph, 'generate', undefined, 'moss')
|
||||
const loaders = loadImageNames(graph)
|
||||
console.log(JSON.stringify({
|
||||
src: 'image-v2',
|
||||
engine: 'moss',
|
||||
workflow: workflowFile,
|
||||
mode: 'generate',
|
||||
task: 't2i',
|
||||
size: { width: size.width, height: size.height },
|
||||
models: {
|
||||
unet: params.mossUnetName,
|
||||
clip: params.mossClipName,
|
||||
vae: params.mossVaeName,
|
||||
clipDevice: params.mossClipDevice || 'cpu'
|
||||
},
|
||||
shift: IMAGE_V2_MOSS_SHIFT,
|
||||
slg: IMAGE_V2_MOSS_SLG_LAYER,
|
||||
upsampler: false,
|
||||
steps,
|
||||
cfg,
|
||||
seed: params.seed
|
||||
}))
|
||||
return { graph, workflowFile, loaders, prompt, strength: undefined }
|
||||
}
|
||||
|
||||
export function buildImageV2Workflow(params: ImageV2BuildParams) {
|
||||
const engine = parseImageV2Engine(params.engine, 'flux')
|
||||
if (engine === 'moss') return buildMossGenerateWorkflow(params)
|
||||
if (engine === 'krea') {
|
||||
return params.mode === 'generate' ? buildKreaGenerateWorkflow(params) : buildKreaItiWorkflow(params)
|
||||
}
|
||||
@@ -602,6 +786,8 @@ export const IMAGE_V2_NODE_LABELS: Record<string, string> = {
|
||||
'33': 'Applying mask',
|
||||
'14': 'Building empty latent',
|
||||
'15': 'Sampling',
|
||||
'40': 'Applying shift',
|
||||
'41': 'Skip-layer guidance',
|
||||
'19': 'Sampling',
|
||||
'20': 'Decoding still',
|
||||
'21': 'Saving still'
|
||||
|
||||
Reference in New Issue
Block a user