Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Merge branch 'o/lora-plumbing' into claude/fuobe-parity-4

Claude41f9ece79ea3
diff --cc package.json
index a285195e,2ffaf2ec..43a1eab9
--- a/package.json
+++ b/package.json
@@@ -16,18 -16,8 +16,18 @@@
"test:e2e:library": "node tests/e2e/library-flows.mjs",
"test:e2e:mobile": "node tests/e2e/no-horizontal-scroll.mjs",
"test:e2e:shell": "node tests/e2e/shell.mjs",
- "gen:catalog": "python3 scripts/gen-cloud-models.py && python3 scripts/gen-higgsfield-models.py && python3 scripts/gen-higgsfield-presets.py && python3 scripts/gen-oss-loras.py && node scripts/gen-icon-map.mjs",
+ "gen:catalog": "python3 scripts/gen-cloud-models.py && python3 scripts/gen-higgsfield-models.py && python3 scripts/gen-higgsfield-presets.py && python3 scripts/gen-oss-loras.py && python3 scripts/gen-lora-library.py && node scripts/gen-icon-map.mjs",
- "typecheck": "tsc --noEmit"
+ "typecheck": "tsc --noEmit",
+ "eval:run": "node scripts/eval/eval.mjs run",
+ "eval:report": "node scripts/eval/eval.mjs report",
+ "eval:review": "node scripts/eval/eval.mjs review",
+ "eval:compare": "node scripts/eval/eval.mjs compare",
+ "eval:promote": "node scripts/eval/eval.mjs promote",
+ "eval:history": "node scripts/eval/eval.mjs history",
+ "eval:validate": "node scripts/eval/eval.mjs validate",
+ "eval:setup": "node scripts/eval/eval.mjs setup",
+ "eval:trash": "node scripts/eval/eval.mjs trash",
+ "eval:covers": "node scripts/eval/eval.mjs covers"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.135.0",
diff --cc src/lib/catalog/plan.ts
index d3c41fb4,86d44854..528d6d05
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@@ -12,6 -12,6 +12,7 @@@ import type
Pricing,
} from "./types";
import { chainGapProblem, chainTiming, FIRST_AT_ZERO, frameTimes, keyframeChain, MAX_KEYFRAMES, spread } from "./keyframes";
++import { cloudPath, fitLoras, gated, localOnly, loraCapacity, needsToken, routeLoraField } from "./loras";
/** Infer the operation from what the user attached. */
export function inferOperation(model: ModelDef, req: Pick<GenerationRequest, "op" | "inputs" | "params">): Operation {
@@@ -196,18 -196,9 +197,20 @@@ export function planGeneration
}
}
- if (req.loras?.length) loras = [...loras, ...req.loras];
+ // The user's own LoRAs (an @character's trained identity) go first: on an API that takes so many, the first
+ // ones win, so a look's or motion's LoRAs give way to them (fitLoras).
+ if (req.loras?.length) loras = [...req.loras, ...loras];
+ // A LoRA at strength 0 changes nothing: leave it out, so preset strength 0 is the preset's prompt alone (and its file isn't needed).
+ const kept = loras.filter((l) => (l.strength ?? 1) !== 0);
+ // Its trigger word goes with it: an open motion's template starts with its LoRA's trigger ("e13c7r1c electricity
+ // effect. …", see withOssLoras), which means nothing to the model without the LoRA.
+ const keptTriggers = new Set(kept.map((l) => l.trigger).filter(Boolean));
+ for (const l of loras) {
+ if ((l.strength ?? 1) !== 0 || !l.trigger || keptTriggers.has(l.trigger)) continue;
+ const lead = [". ", ", ", " "].map((sep) => l.trigger + sep).find((t) => prompt.startsWith(t));
+ if (lead) prompt = prompt.slice(lead.length);
+ }
+ loras = kept;
// Multi-shot: the clip is as long as its shots, and models without per-shot prompts get them written out.
const shots = params.shots?.filter((s) => s.prompt.trim());
@@@ -468,25 -459,8 +471,27 @@@ export function pricingAt(p: Pricing, n
*/
const CLIP_LENGTH_OPS = new Set<Operation>(["upscale-video", "interpolate", "sdr-to-hdr", "export-video"]);
+/**
+ * Which of a plan's LoRAs a route really applies, and why the others are left out: ComfyUI loads every file
- * (injectLoras); fal switches to the model's LoRA endpoint for LoRAs with a URL; other routes take none.
- * The preview reports it, so a caller (the evaluation harness) records the recipe that ran, not the one it asked for.
++ * (injectLoras); a cloud route carries the ones fitLoras keeps (the licence allows hosting, there is a URL to
++ * send, the API takes LoRAs and so many). The preview reports it, so a caller (the evaluation harness) records
++ * the recipe that ran, not the one it asked for.
+ */
- export function routeLoras(route: Pick<ModelRoute, "provider" | "loraEndpoint">, loras: LoraRef[]): { applied: LoraRef[]; dropped: { file: string; reason: string }[] } {
- if (route.provider === "comfyui") return { applied: loras, dropped: [] };
- const applied: LoraRef[] = [];
- const dropped: { file: string; reason: string }[] = [];
- for (const l of loras) {
- if (route.provider !== "fal" || !route.loraEndpoint) dropped.push({ file: l.file, reason: "this route takes no LoRAs" });
- else if (!l.url) dropped.push({ file: l.file, reason: "no URL to send to the LoRA endpoint" });
- else applied.push(l);
- }
- return { applied, dropped };
++export function routeLoras(route: Pick<ModelRoute, "provider" | "map" | "loraEndpoint">, loras: LoraRef[]): { applied: LoraRef[]; dropped: { file: string; reason: string }[] } {
++ const applied = fitLoras(loras, route).loras;
++ const field = routeLoraField(route);
++ const why = (l: LoraRef) => {
++ if (localOnly(l)) return "its licence doesn't allow hosting, so it runs only on your GPU";
++ if (gated(l) && !l.hostedUrl) return "it is in a gated Hugging Face repo, so it runs only on your GPU";
++ if (!cloudPath(l) && !needsToken(l.url)) return "no URL to send to the LoRA endpoint";
++ if (!field) return "this route takes no LoRAs";
++ return field.shape === "experts" ? "this API takes one LoRA per expert" : `this API takes up to ${loraCapacity(field)} LoRAs`;
++ };
++ return { applied, dropped: loras.filter((l) => !applied.includes(l)).map((l) => ({ file: l.file, reason: why(l) })) };
+}
+
/** Rough USD estimate for a plan (BYO-key cloud runs). Open-source runs are free. */
- export function estimateCost(model: ModelDef, params: GenParams, jobs = 1, op?: Operation): number | null {
+ export function estimateCost(model: ModelDef, params: GenParams, jobs = 1, op?: Operation, withLoras = false): number | null {
if (model.engine === "open" || !model.pricing) return model.engine === "open" ? 0 : null;
const p = model.pricing;
const n = params.numOutputs ?? 1;
diff --cc src/server/generations.ts
index 9093b049,4e4c9121..2bc0160b
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@@ -10,8 -10,9 +10,9 @@@ import { cueText, type Cue } from "@/li
import { HELPER_FEATURES, HELPER_SUFFIX, isReviewStatus, type AssetUse, type ReviewFilter } from "@/lib/library";
import { upscaleTier } from "@/lib/av/upscale";
import { chainedWaitMessage, keyframeChain } from "@/lib/catalog/keyframes";
-import { estimateCost, inferOperation, planGeneration, routesFor } from "@/lib/catalog/plan";
+import { estimateCost, inferOperation, planGeneration, routeLoras, routesFor } from "@/lib/catalog/plan";
- import { keepMatte } from "@/lib/catalog/payload";
+ import { framedLength, keepMatte } from "@/lib/catalog/payload";
+ import { fitLoras, lorasFit } from "@/lib/catalog/loras";
import {
LAST_FRAME_CHAIN,
OPERATION_OUTPUT,
@@@ -422,7 -436,23 +436,24 @@@ function prepare(original: GenerationRe
// Checks planGeneration can't make without knowing the model's kind or the text ops' needs.
if (plan.op === "color-match" && plan.model.kind === "video" && !req.inputs?.video) throw new Error("Add the video and a reference image");
if (plan.op === "translate" && !plan.params.targetLanguage) throw new Error("Pick a language to translate into");
- const { route, demo } = chooseRoute(routesFor(plan.model, plan.op), req.inputs?.images?.length ?? 0);
+ // The length asked of a clip that is made (not one that follows its input video's length).
+ const seconds = MADE_LENGTH_OPS.has(plan.op) ? plan.params.duration : undefined;
+ const { route, demo } = chooseRoute(routesFor(plan.model, plan.op), req.inputs?.images?.length ?? 0, plan.loras, seconds);
+ // What the cloud run can carry: a LoRA whose licence doesn't allow hosting stays on the GPU, and an API
+ // takes at most so many (the plan's notes say which were left out). Open runs carry them all.
- const fitted = fitLoras(plan.loras, route);
++ const asked = plan.loras;
++ const fitted = fitLoras(asked, route);
+ plan = { ...plan, loras: fitted.loras };
+ const notes = [...fitted.notes];
+ // A frame-count API that can't make the length asked (Replicate's Wan 2.2 fast: 81–121 frames) says what it makes.
+ const made = demo ? undefined : framedLength(route.map?.numFrames, seconds, plan.params.fps);
+ if (made !== undefined && route.map?.numFrames) {
+ const f = route.map.numFrames;
+ const fps = plan.params.fps && plan.params.fps > 0 ? plan.params.fps : f.fps;
+ const half = (x: number) => Math.round(x * 2) / 2;
+ const span = f.min !== undefined && f.max !== undefined ? ` makes ${half(f.min / fps)}–${half(f.max / fps)} s clips,` : "";
+ notes.push(`${plan.model.name} on ${provider(route.provider).label}${span} so this one is about ${half(made)} s, not ${seconds} s`);
+ }
// A route that can't batch (Higgsfield's Grok Imagine Image beside fal's num_images) runs one job per output.
if (!demo && route.map && !route.map.numOutputs && plan.perJobOutputs > 1) {
plan = { ...plan, jobs: plan.jobs * plan.perJobOutputs, perJobOutputs: 1, params: { ...plan.params, numOutputs: 1 } };
@@@ -430,14 -460,17 +461,18 @@@
const providerId: ProviderId = demo ? "mock" : route.provider;
// A text step that runs on Ollama is free; only Claude costs money.
const free = demo || (route.provider === "llm" && !llmUsesClaude(route));
- return { req, plan, route, demo, providerId, cost: free ? 0 : estimateCost(plan.model, plan.params, 1, plan.op) };
+ const withLoras = fitted.loras.length > 0 && !!route.loraEndpoint;
- return { req, plan, route, demo, providerId, notes, cost: free ? 0 : estimateCost(plan.model, plan.params, 1, plan.op, withLoras) };
++ return { req, plan, route, demo, providerId, notes, asked, cost: free ? 0 : estimateCost(plan.model, plan.params, 1, plan.op, withLoras) };
}
+ /** Operations whose clip length is the duration picked (made, or added by extend), not an input video's. */
+ const MADE_LENGTH_OPS = new Set<Operation>(["t2v", "i2v", "flf2v", "ref2v", "extend", "keyframes"]);
+
/** What a request would run as — model, operation, job count and cost — without starting it. */
export function previewGeneration(req: GenerationRequest) {
- const { plan, route, demo, providerId, cost } = prepare(req);
- const loras = routeLoras(route, plan.loras);
- const { plan, demo, providerId, cost, notes } = prepare(req);
++ const { plan, route, demo, providerId, cost, notes, asked } = prepare(req);
++ const loras = routeLoras(route, asked);
return {
model: plan.model,
op: plan.op,
@@@ -446,10 -479,7 +481,11 @@@
demo,
providerId,
costUsd: cost === null ? null : cost * plan.jobs,
+ // What the route runs (the evaluation harness records it): the provider endpoint, the final prompt and the LoRAs it loads.
- route: { provider: route.provider, endpoint: loras.applied.length && route.provider === "fal" && route.loraEndpoint ? route.loraEndpoint : route.endpoint },
++ route: { provider: route.provider, endpoint: loras.applied.length && route.provider !== "comfyui" && route.loraEndpoint ? route.loraEndpoint : route.endpoint },
+ prompt: plan.prompt,
+ loras,
+ ...(notes.length && { notes }),
};
}