@hackbuild/imagegen 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +130 -2
- package/dist/hub.d.ts +53 -0
- package/dist/hub.js +106 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/pipeline.d.ts +72 -0
- package/dist/pipeline.js +95 -0
- package/dist/records.d.ts +49 -0
- package/dist/records.js +91 -0
- package/dist/schedule.d.ts +36 -0
- package/dist/schedule.js +90 -0
- package/dist/single/index.iife.js +457 -0
- package/dist/single/index.js +434 -0
- package/package.json +34 -4
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// packages/imagegen/src/schedule.ts
|
|
2
|
+
/** Sigma for each of the 1000 training timesteps. sigmas()[999] is about 14.6146 (computed). */
|
|
3
|
+
function sigmas(n = 1e3, betaStart = 85e-5, betaEnd = .012) {
|
|
4
|
+
const sb = Math.sqrt(betaStart);
|
|
5
|
+
const se = Math.sqrt(betaEnd);
|
|
6
|
+
const out = new Float64Array(n);
|
|
7
|
+
let cum = 1;
|
|
8
|
+
for (let i = 0; i < n; i++) {
|
|
9
|
+
const beta = (sb + (se - sb) * i / (n - 1)) ** 2;
|
|
10
|
+
cum *= 1 - beta;
|
|
11
|
+
out[i] = Math.sqrt((1 - cum) / cum);
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/** Trailing spacing: 1 step is [999], 4 steps are [999, 749, 499, 249]. */
|
|
16
|
+
function trailingTimesteps(steps, train = 1e3) {
|
|
17
|
+
const ratio = train / steps;
|
|
18
|
+
const out = [];
|
|
19
|
+
for (let t = train; t > .5 && out.length < steps; t -= ratio) out.push(Math.round(t) - 1);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
/** mulberry32: a 32 bit seeded generator in [0, 1). */
|
|
23
|
+
function mulberry32(seed) {
|
|
24
|
+
let a = seed >>> 0;
|
|
25
|
+
return () => {
|
|
26
|
+
a = a + 1831565813 >>> 0;
|
|
27
|
+
let t = a;
|
|
28
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
29
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
30
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Standard normal samples by Box-Muller over a uniform source. */
|
|
34
|
+
function gaussian(rng) {
|
|
35
|
+
return () => {
|
|
36
|
+
const u = 1 - rng();
|
|
37
|
+
const v = rng();
|
|
38
|
+
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Leading spacing with an offset of 1, the Euler default SD 1.5 ships
|
|
43
|
+
* with: 1000 // steps apart from 0, reversed, plus 1. 4 steps are 751,
|
|
44
|
+
* 501, 251, 1.
|
|
45
|
+
*/
|
|
46
|
+
function leadingTimesteps(steps, train = 1e3, offset = 1) {
|
|
47
|
+
const ratio = Math.floor(train / steps);
|
|
48
|
+
const out = [];
|
|
49
|
+
for (let i = steps - 1; i >= 0; i--) out.push(Math.min(train - 1, i * ratio + offset));
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function eulerPlan(steps, spacing = "trailing") {
|
|
53
|
+
const all = sigmas();
|
|
54
|
+
const timesteps = spacing === "leading" ? leadingTimesteps(steps) : trailingTimesteps(steps);
|
|
55
|
+
return {
|
|
56
|
+
timesteps,
|
|
57
|
+
sigmas: [...timesteps.map((t) => all[t]), 0]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Run the Euler loop. `eps(scaled, timestep)` is the UNet: it receives the
|
|
62
|
+
* latent divided by sqrt(sigma^2 + 1) and returns predicted noise; the
|
|
63
|
+
* step is latent += eps * (sigmaNext - sigma).
|
|
64
|
+
*/
|
|
65
|
+
async function euler(latent, plan, eps, signal) {
|
|
66
|
+
let x = latent;
|
|
67
|
+
for (let s = 0; s < plan.timesteps.length; s++) {
|
|
68
|
+
if (signal?.aborted) throw new DOMException("image generation stopped", "AbortError");
|
|
69
|
+
const sigma = plan.sigmas[s];
|
|
70
|
+
const next = plan.sigmas[s + 1];
|
|
71
|
+
const div = Math.sqrt(sigma * sigma + 1);
|
|
72
|
+
const scaled = new Float32Array(x.length);
|
|
73
|
+
for (let i = 0; i < x.length; i++) scaled[i] = x[i] / div;
|
|
74
|
+
const e = await eps(scaled, plan.timesteps[s], s);
|
|
75
|
+
const dt = next - sigma;
|
|
76
|
+
const y = new Float32Array(x.length);
|
|
77
|
+
for (let i = 0; i < x.length; i++) y[i] = x[i] + e[i] * dt;
|
|
78
|
+
x = y;
|
|
79
|
+
}
|
|
80
|
+
return x;
|
|
81
|
+
}
|
|
82
|
+
// packages/imagegen/src/pipeline.ts
|
|
83
|
+
/**
|
|
84
|
+
* SD-Turbo text to image on onnxruntime-web: CLIP token ids into the text
|
|
85
|
+
* encoder, the Euler loop over the UNet, the latent divided by 0.18215
|
|
86
|
+
* into the VAE decoder, and the [-1, 1] NCHW output to RGBA. The caller
|
|
87
|
+
* brings the ort module, the three sessions (weights through
|
|
88
|
+
* @hackbuild/weights) and a tokenizer; the hub's run() wraps each graph
|
|
89
|
+
* call so the gpu lock and frame budget apply.
|
|
90
|
+
*/
|
|
91
|
+
const VAE_SCALE = .18215;
|
|
92
|
+
/** NCHW floats in [-1, 1] to RGBA bytes. */
|
|
93
|
+
function toRgba(nchw, w, h) {
|
|
94
|
+
const out = new Uint8ClampedArray(w * h * 4);
|
|
95
|
+
const plane = w * h;
|
|
96
|
+
for (let i = 0; i < plane; i++) {
|
|
97
|
+
for (let c = 0; c < 3; c++) out[i * 4 + c] = Math.round((nchw[c * plane + i] + 1) / 2 * 255);
|
|
98
|
+
out[i * 4 + 3] = 255;
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
function padIds(ids, n = 77, pad) {
|
|
103
|
+
const out = new Int32Array(n);
|
|
104
|
+
const last = ids.length ? ids[ids.length - 1] : 0;
|
|
105
|
+
out.fill(pad ?? last);
|
|
106
|
+
for (let i = 0; i < Math.min(n, ids.length); i++) out[i] = ids[i];
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
async function generate(ort, s, tokenize, o) {
|
|
110
|
+
const now = o.now ?? (() => globalThis.performance ? performance.now() : Date.now());
|
|
111
|
+
const run = o.run ?? ((fn) => fn());
|
|
112
|
+
const steps = Math.max(1, Math.min(50, o.steps ?? 1));
|
|
113
|
+
const guidance = o.guidance ?? 1;
|
|
114
|
+
const cfg = guidance > 1;
|
|
115
|
+
const seed = (o.seed ?? 0) >>> 0;
|
|
116
|
+
const size = o.size ?? 512;
|
|
117
|
+
if (size % 8) throw new Error("size must be a multiple of 8");
|
|
118
|
+
const lw = size / 8;
|
|
119
|
+
const n = 4 * lw * lw;
|
|
120
|
+
const ms = {
|
|
121
|
+
text: 0,
|
|
122
|
+
unet: 0,
|
|
123
|
+
vae: 0
|
|
124
|
+
};
|
|
125
|
+
let t = now();
|
|
126
|
+
const encode = async (text) => {
|
|
127
|
+
const ids = padIds(await tokenize(text.length ? text : " "));
|
|
128
|
+
const te = await run(() => s.textEncoder.run({ input_ids: new ort.Tensor("int32", ids, [1, 77]) }));
|
|
129
|
+
const hidden = te.last_hidden_state ?? Object.values(te)[0];
|
|
130
|
+
return new ort.Tensor("float32", Float32Array.from(hidden.data), [...hidden.dims ?? [
|
|
131
|
+
1,
|
|
132
|
+
77,
|
|
133
|
+
hidden.data.length / 77
|
|
134
|
+
]]);
|
|
135
|
+
};
|
|
136
|
+
const hiddenTensor = await encode(o.prompt);
|
|
137
|
+
const uncondTensor = cfg ? await encode(o.negative ?? "") : null;
|
|
138
|
+
ms.text = now() - t;
|
|
139
|
+
o.onStep?.({
|
|
140
|
+
stage: "text",
|
|
141
|
+
step: 0,
|
|
142
|
+
steps,
|
|
143
|
+
ms: ms.text
|
|
144
|
+
});
|
|
145
|
+
const plan = eulerPlan(steps, o.spacing);
|
|
146
|
+
const randn = gaussian(o.rng ?? mulberry32(seed));
|
|
147
|
+
const latent = new Float32Array(n);
|
|
148
|
+
const s0 = plan.sigmas[0];
|
|
149
|
+
const init = o.spacing === "leading" ? Math.sqrt(s0 * s0 + 1) : s0;
|
|
150
|
+
for (let i = 0; i < n; i++) latent[i] = randn() * init;
|
|
151
|
+
const final = await euler(latent, plan, async (scaled, timestep, step) => {
|
|
152
|
+
const t0 = now();
|
|
153
|
+
const unet = async (h) => {
|
|
154
|
+
const u = await run(() => s.unet.run({
|
|
155
|
+
sample: new ort.Tensor("float32", scaled, [
|
|
156
|
+
1,
|
|
157
|
+
4,
|
|
158
|
+
lw,
|
|
159
|
+
lw
|
|
160
|
+
]),
|
|
161
|
+
timestep: new ort.Tensor("int64", BigInt64Array.from([BigInt(timestep)]), [1]),
|
|
162
|
+
encoder_hidden_states: h
|
|
163
|
+
}));
|
|
164
|
+
return (u.out_sample ?? Object.values(u)[0]).data;
|
|
165
|
+
};
|
|
166
|
+
const c = await unet(hiddenTensor);
|
|
167
|
+
let e = c;
|
|
168
|
+
if (uncondTensor) {
|
|
169
|
+
const u = await unet(uncondTensor);
|
|
170
|
+
const g = new Float32Array(c.length);
|
|
171
|
+
for (let i = 0; i < g.length; i++) g[i] = u[i] + guidance * (c[i] - u[i]);
|
|
172
|
+
e = g;
|
|
173
|
+
}
|
|
174
|
+
const d = now() - t0;
|
|
175
|
+
ms.unet += d;
|
|
176
|
+
o.onStep?.({
|
|
177
|
+
stage: "denoise",
|
|
178
|
+
step: step + 1,
|
|
179
|
+
steps,
|
|
180
|
+
ms: d
|
|
181
|
+
});
|
|
182
|
+
return e;
|
|
183
|
+
}, o.signal);
|
|
184
|
+
t = now();
|
|
185
|
+
const vin = new Float32Array(n);
|
|
186
|
+
for (let i = 0; i < n; i++) vin[i] = final[i] / VAE_SCALE;
|
|
187
|
+
const v = await run(() => s.vaeDecoder.run({ latent_sample: new ort.Tensor("float32", vin, [
|
|
188
|
+
1,
|
|
189
|
+
4,
|
|
190
|
+
lw,
|
|
191
|
+
lw
|
|
192
|
+
]) }));
|
|
193
|
+
ms.vae = now() - t;
|
|
194
|
+
o.onStep?.({
|
|
195
|
+
stage: "decode",
|
|
196
|
+
step: steps,
|
|
197
|
+
steps,
|
|
198
|
+
ms: ms.vae
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
width: size,
|
|
202
|
+
height: size,
|
|
203
|
+
rgba: toRgba((v.sample ?? Object.values(v)[0]).data, size, size),
|
|
204
|
+
seed,
|
|
205
|
+
ms
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// packages/imagegen/src/records.ts
|
|
209
|
+
const graphs = {
|
|
210
|
+
textEncoder: "text_encoder",
|
|
211
|
+
unet: "unet",
|
|
212
|
+
vaeDecoder: "vae_decoder"
|
|
213
|
+
};
|
|
214
|
+
const files = [
|
|
215
|
+
{ path: "text_encoder/model.onnx" },
|
|
216
|
+
{ path: "unet/model.onnx" },
|
|
217
|
+
{ path: "vae_decoder/model.onnx" }
|
|
218
|
+
];
|
|
219
|
+
const free512 = { freeDimensionOverrides: {
|
|
220
|
+
batch_size: 1,
|
|
221
|
+
num_channels: 4,
|
|
222
|
+
height: 64,
|
|
223
|
+
width: 64,
|
|
224
|
+
sequence_length: 77,
|
|
225
|
+
num_channels_latent: 4,
|
|
226
|
+
height_latent: 64,
|
|
227
|
+
width_latent: 64
|
|
228
|
+
} };
|
|
229
|
+
const IMAGEGEN_RECORDS = [{
|
|
230
|
+
id: "sd-turbo",
|
|
231
|
+
label: "sd-turbo 512",
|
|
232
|
+
provides: ["imagegen"],
|
|
233
|
+
provider: "ort",
|
|
234
|
+
source: {
|
|
235
|
+
repo: "schmuell/sd-turbo-ort-web",
|
|
236
|
+
files
|
|
237
|
+
},
|
|
238
|
+
sizeMB: 2600,
|
|
239
|
+
sizeSource: "inferred",
|
|
240
|
+
ladder: [{
|
|
241
|
+
device: "webgpu",
|
|
242
|
+
ort: { executionProviders: ["webgpu"] },
|
|
243
|
+
options: free512
|
|
244
|
+
}],
|
|
245
|
+
licence: "Stability AI Non-Commercial Research Community License (the LICENSE in schmuell/sd-turbo-ort-web; upstream stabilityai/sd-turbo moved to the Community License in July 2024, this export did not)",
|
|
246
|
+
commercial: false,
|
|
247
|
+
place: "gpu",
|
|
248
|
+
runtime: "onnxruntime-web@1.27.0",
|
|
249
|
+
notes: [
|
|
250
|
+
"webgpu only in an earlier build, no wasm floor",
|
|
251
|
+
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)",
|
|
252
|
+
"graph file paths inferred from an earlier build, not checked against the repo"
|
|
253
|
+
],
|
|
254
|
+
form: {
|
|
255
|
+
steps: {
|
|
256
|
+
min: 1,
|
|
257
|
+
max: 4,
|
|
258
|
+
default: 2
|
|
259
|
+
},
|
|
260
|
+
guidance: null,
|
|
261
|
+
negative: false,
|
|
262
|
+
sizes: [512],
|
|
263
|
+
spacing: "trailing",
|
|
264
|
+
note: "distilled from sd 2.1. 1 to 4 steps, no negative prompt. the fastest path.",
|
|
265
|
+
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
266
|
+
graphs
|
|
267
|
+
}
|
|
268
|
+
}, {
|
|
269
|
+
id: "sd-1.5",
|
|
270
|
+
label: "stable diffusion 1.5",
|
|
271
|
+
provides: ["imagegen"],
|
|
272
|
+
provider: "ort",
|
|
273
|
+
source: {
|
|
274
|
+
repo: "microsoft/stable-diffusion-v1.5-webnn",
|
|
275
|
+
files
|
|
276
|
+
},
|
|
277
|
+
sizeMB: 2e3,
|
|
278
|
+
sizeSource: "inferred",
|
|
279
|
+
ladder: [{
|
|
280
|
+
device: "webgpu",
|
|
281
|
+
ort: { executionProviders: ["webgpu"] },
|
|
282
|
+
options: free512
|
|
283
|
+
}],
|
|
284
|
+
licence: "CreativeML OpenRAIL-M (use restrictions in its attachment A)",
|
|
285
|
+
commercial: true,
|
|
286
|
+
place: "gpu",
|
|
287
|
+
runtime: "onnxruntime-web@1.27.0",
|
|
288
|
+
notes: [
|
|
289
|
+
"about 2 GB by an earlier bench's label (vendor); the repo, its file paths and its input dtypes are inferred and not checked",
|
|
290
|
+
"runs the unet twice a step for guidance, so a step costs about twice an sd-turbo step (inferred)",
|
|
291
|
+
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)"
|
|
292
|
+
],
|
|
293
|
+
form: {
|
|
294
|
+
steps: {
|
|
295
|
+
min: 5,
|
|
296
|
+
max: 40,
|
|
297
|
+
default: 22
|
|
298
|
+
},
|
|
299
|
+
guidance: {
|
|
300
|
+
min: 1,
|
|
301
|
+
max: 12,
|
|
302
|
+
default: 7.5,
|
|
303
|
+
step: .5
|
|
304
|
+
},
|
|
305
|
+
negative: true,
|
|
306
|
+
sizes: [512],
|
|
307
|
+
spacing: "leading",
|
|
308
|
+
note: "classic sd, openrail-m licence. 20 to 30 steps with guidance, takes a negative prompt. slower per image.",
|
|
309
|
+
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
310
|
+
graphs
|
|
311
|
+
}
|
|
312
|
+
}];
|
|
313
|
+
/** The form for a record, or null for a record without one (a stub). */
|
|
314
|
+
function formOf(rec) {
|
|
315
|
+
return rec?.form ?? null;
|
|
316
|
+
}
|
|
317
|
+
/** The load button label: names the model and its download size with the size's source. */
|
|
318
|
+
function loadLabel(rec) {
|
|
319
|
+
const name = rec.label ?? rec.id;
|
|
320
|
+
if (rec.sizeMB === null) return `load ${name}, size unknown`;
|
|
321
|
+
if (rec.sizeMB === 0) return `load ${name}, no download`;
|
|
322
|
+
return `load ${name}, about ${rec.sizeMB >= 1e3 ? `${(rec.sizeMB / 1e3).toFixed(1)} gb` : `${rec.sizeMB} mb`} (${rec.sizeSource})`;
|
|
323
|
+
}
|
|
324
|
+
// packages/imagegen/src/hub.ts
|
|
325
|
+
/** Thrown when a request does not fit the model's form; the message is the copy to show. */
|
|
326
|
+
var FormError = class extends Error {
|
|
327
|
+
name = "FormError";
|
|
328
|
+
};
|
|
329
|
+
/** Add the image records to the hub's registry. */
|
|
330
|
+
function attachImagegen(hub) {
|
|
331
|
+
hub.registry.add(...IMAGEGEN_RECORDS);
|
|
332
|
+
}
|
|
333
|
+
/** The three sessions of a loaded model, by the form's graph names. */
|
|
334
|
+
function sessionsOf(m, form) {
|
|
335
|
+
const pick = (k) => {
|
|
336
|
+
const s = m.sessions[k];
|
|
337
|
+
if (!s) throw new Error(`the loaded model has no ${k} graph; it has ${Object.keys(m.sessions).join(", ") || "none"}`);
|
|
338
|
+
return s;
|
|
339
|
+
};
|
|
340
|
+
return {
|
|
341
|
+
textEncoder: pick(form.graphs.textEncoder),
|
|
342
|
+
unet: pick(form.graphs.unet),
|
|
343
|
+
vaeDecoder: pick(form.graphs.vaeDecoder)
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/** Clamp a request to what the form allows, with the form's defaults. */
|
|
347
|
+
function applyForm(form, o) {
|
|
348
|
+
const size = o.size ?? form.sizes[0];
|
|
349
|
+
if (!form.sizes.includes(size)) throw new FormError(`this model makes ${form.sizes.join(" or ")} pixel images, not ${size}.`);
|
|
350
|
+
const steps = Math.round(Math.min(form.steps.max, Math.max(form.steps.min, o.steps ?? form.steps.default)));
|
|
351
|
+
const out = {
|
|
352
|
+
...o,
|
|
353
|
+
size,
|
|
354
|
+
steps,
|
|
355
|
+
spacing: form.spacing
|
|
356
|
+
};
|
|
357
|
+
if (form.guidance) out.guidance = Math.min(form.guidance.max, Math.max(form.guidance.min, o.guidance ?? form.guidance.default));
|
|
358
|
+
else delete out.guidance;
|
|
359
|
+
if (!form.negative) delete out.negative;
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Load an image model through the hub: a record id (`{ id: "sd-1.5" }`)
|
|
364
|
+
* or the capability ("imagegen", which the hub routes, or sends to the
|
|
365
|
+
* stub in stub mode). A record without a form (the stub) gets SD-Turbo's.
|
|
366
|
+
*/
|
|
367
|
+
async function loadImagegen(hub, what = "imagegen", o = {}) {
|
|
368
|
+
const loaded = await hub.use(what, o);
|
|
369
|
+
const form = formOf(loaded.record) ?? IMAGEGEN_RECORDS[0].form;
|
|
370
|
+
let sessions;
|
|
371
|
+
try {
|
|
372
|
+
sessions = sessionsOf(loaded.value, form);
|
|
373
|
+
} catch (e) {
|
|
374
|
+
hub.release(loaded);
|
|
375
|
+
throw e;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
loaded,
|
|
379
|
+
record: loaded.record,
|
|
380
|
+
form,
|
|
381
|
+
sessions,
|
|
382
|
+
generate(tokenize, req) {
|
|
383
|
+
const { runOptions, ...rest } = req;
|
|
384
|
+
const run = (fn) => hub.run(loaded, () => fn(), {
|
|
385
|
+
...runOptions ?? {},
|
|
386
|
+
...rest.signal ? { signal: rest.signal } : {}
|
|
387
|
+
});
|
|
388
|
+
return generate(loaded.value.ort, sessions, tokenize, {
|
|
389
|
+
...applyForm(form, rest),
|
|
390
|
+
run
|
|
391
|
+
});
|
|
392
|
+
},
|
|
393
|
+
release() {
|
|
394
|
+
hub.release(loaded);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* A weightless model for stub pages and tests: the text encoder returns
|
|
400
|
+
* zeros, the UNet predicts zero noise, and the VAE returns a flat grey, so
|
|
401
|
+
* the whole flow (stages, timing cells, history) runs with no download.
|
|
402
|
+
*/
|
|
403
|
+
function stubImagegenModel() {
|
|
404
|
+
class Tensor {
|
|
405
|
+
type;
|
|
406
|
+
data;
|
|
407
|
+
dims;
|
|
408
|
+
constructor(type, data, dims) {
|
|
409
|
+
this.type = type;
|
|
410
|
+
this.data = data;
|
|
411
|
+
this.dims = dims;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const dims = (t) => t.dims;
|
|
415
|
+
return {
|
|
416
|
+
ort: { Tensor },
|
|
417
|
+
sessions: {
|
|
418
|
+
text_encoder: { run: async () => ({ last_hidden_state: {
|
|
419
|
+
data: /* @__PURE__ */ new Float32Array(616),
|
|
420
|
+
dims: [
|
|
421
|
+
1,
|
|
422
|
+
77,
|
|
423
|
+
8
|
|
424
|
+
]
|
|
425
|
+
} }) },
|
|
426
|
+
unet: { run: async (f) => ({ out_sample: { data: new Float32Array(f.sample.data.length) } }) },
|
|
427
|
+
vae_decoder: { run: async (f) => {
|
|
428
|
+
const [, , h, w] = dims(f.latent_sample);
|
|
429
|
+
return { sample: { data: new Float32Array(3 * h * 8 * w * 8) } };
|
|
430
|
+
} }
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
export { FormError, IMAGEGEN_RECORDS, VAE_SCALE, applyForm, attachImagegen, euler, eulerPlan, formOf, gaussian, generate, leadingTimesteps, loadImagegen, loadLabel, mulberry32, padIds, sessionsOf, sigmas, stubImagegenModel, toRgba, trailingTimesteps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/imagegen",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Text to image in a tab: SD-Turbo and SD 1.5 text encoder, UNet and VAE on onnxruntime-web with a seeded Euler scheduler on trailing or leading timesteps, guidance with a negative prompt, per model form records, loaded through the models hub and run under its gpu lock.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Moheeb Zara <hackbuildvideo@gmail.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/hackbuild/hackbuild-browser-ai.git",
|
|
11
|
+
"directory": "packages/imagegen"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"unpkg": "./dist/single/index.iife.js",
|
|
29
|
+
"jsdelivr": "./dist/single/index.iife.js",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -b"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@hackbuild/models": "0.1.0"
|
|
35
|
+
}
|
|
36
|
+
}
|