@hackbuild/ai-views 0.1.10 → 0.1.12
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/README.md +3 -3
- package/dist/single/elements.iife.js +26 -13
- package/dist/single/elements.js +26 -13
- package/dist/single/index.iife.js +100 -73
- package/dist/single/index.js +100 -73
- package/dist/single/vue.iife.js +95 -20
- package/dist/single/vue.js +95 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -254,9 +254,9 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
254
254
|
|
|
255
255
|
| file | gzip (measured) | ceiling |
|
|
256
256
|
|---|---|---|
|
|
257
|
-
| `dist/index.js` (main entry, imports external) | 21,
|
|
258
|
-
| `dist/single/elements.iife.js` (single file build) | 100,
|
|
257
|
+
| `dist/index.js` (main entry, imports external) | 21,601 bytes | 22,681 bytes |
|
|
258
|
+
| `dist/single/elements.iife.js` (single file build) | 100,338 bytes | 105,354 bytes |
|
|
259
259
|
|
|
260
|
-
Measured 2026-11-
|
|
260
|
+
Measured 2026-11-30 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
261
261
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
262
262
|
5 percent from its row.
|
|
@@ -6553,6 +6553,11 @@ ${n}` : n;
|
|
|
6553
6553
|
{ path: "unet/model.onnx" },
|
|
6554
6554
|
{ path: "vae_decoder/model.onnx" }
|
|
6555
6555
|
];
|
|
6556
|
+
const SD15 = [
|
|
6557
|
+
"Stable-Diffusion-v1.5-text-encoder-float16",
|
|
6558
|
+
"sd-unet-v1.5-model-b2c4h64w64s77-float16-compute-and-inputs-layernorm",
|
|
6559
|
+
"Stable-Diffusion-v1.5-vae-decoder-float16-fp32-instancenorm"
|
|
6560
|
+
];
|
|
6556
6561
|
const free512 = { freeDimensionOverrides: {
|
|
6557
6562
|
batch_size: 1,
|
|
6558
6563
|
num_channels: 4,
|
|
@@ -6590,7 +6595,7 @@ ${n}` : n;
|
|
|
6590
6595
|
notes: [
|
|
6591
6596
|
"webgpu only, no wasm floor",
|
|
6592
6597
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)",
|
|
6593
|
-
"graph
|
|
6598
|
+
"graph files, names and dtypes read from the export (measured): fp32 edges, int32 input_ids, int64 timestep; pads with token 0"
|
|
6594
6599
|
],
|
|
6595
6600
|
form: {
|
|
6596
6601
|
steps: {
|
|
@@ -6604,6 +6609,7 @@ ${n}` : n;
|
|
|
6604
6609
|
spacing: "trailing",
|
|
6605
6610
|
note: "distilled from sd 2.1. 1 to 4 steps, no negative prompt. the fastest path.",
|
|
6606
6611
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
6612
|
+
pad: 0,
|
|
6607
6613
|
graphs
|
|
6608
6614
|
}
|
|
6609
6615
|
}, {
|
|
@@ -6614,9 +6620,10 @@ ${n}` : n;
|
|
|
6614
6620
|
group: "good",
|
|
6615
6621
|
provides: ["imagegen"],
|
|
6616
6622
|
provider: "ort",
|
|
6623
|
+
unrunnable: "its unet takes a fixed batch of 2 at 64 by 64 latents with fp16 inputs (measured from the graph); the pipeline sends batch 1 in fp32.",
|
|
6617
6624
|
source: {
|
|
6618
6625
|
repo: "microsoft/stable-diffusion-v1.5-webnn",
|
|
6619
|
-
files
|
|
6626
|
+
files: SD15.map((g) => ({ path: `${g}.onnx` }))
|
|
6620
6627
|
},
|
|
6621
6628
|
sizeMB: 1969,
|
|
6622
6629
|
sizeSource: "vendor",
|
|
@@ -6630,7 +6637,7 @@ ${n}` : n;
|
|
|
6630
6637
|
place: "gpu",
|
|
6631
6638
|
runtime: "onnxruntime-web@1.27.0",
|
|
6632
6639
|
notes: [
|
|
6633
|
-
"about 2 GB (vendor)
|
|
6640
|
+
"about 2 GB (vendor). the export's three graphs were read (measured): int32 input_ids, fp16 hidden states, a unet fixed at batch 2 with fp16 sample and int64 timestep, an fp16 vae",
|
|
6634
6641
|
"runs the unet twice a step for guidance, so a step costs about twice an sd-turbo step (inferred)",
|
|
6635
6642
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)"
|
|
6636
6643
|
],
|
|
@@ -6651,14 +6658,19 @@ ${n}` : n;
|
|
|
6651
6658
|
spacing: "leading",
|
|
6652
6659
|
note: "classic sd, openrail-m licence. 20 to 30 steps with guidance, takes a negative prompt. slower per image.",
|
|
6653
6660
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
6654
|
-
graphs
|
|
6661
|
+
graphs: {
|
|
6662
|
+
textEncoder: SD15[0],
|
|
6663
|
+
unet: SD15[1],
|
|
6664
|
+
vaeDecoder: SD15[2]
|
|
6665
|
+
}
|
|
6655
6666
|
}
|
|
6656
6667
|
}];
|
|
6657
6668
|
/**
|
|
6658
6669
|
* Listed for pickers, not registered by attachImagegen, so routing by
|
|
6659
|
-
* capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl
|
|
6660
|
-
* export's input and output names
|
|
6661
|
-
*
|
|
6670
|
+
* capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl`. The
|
|
6671
|
+
* export's input and output names and dtypes were read from the end of
|
|
6672
|
+
* each onnx file (2026-11-29, measured); the pipeline has not run on the
|
|
6673
|
+
* real weights. `loadImagegen(hub, { id:
|
|
6662
6674
|
* "sdxl-turbo" })` adds it and loads it.
|
|
6663
6675
|
*/
|
|
6664
6676
|
const IMAGEGEN_PICKER_RECORDS = [{
|
|
@@ -6666,7 +6678,7 @@ ${n}` : n;
|
|
|
6666
6678
|
label: "sdxl-turbo 512",
|
|
6667
6679
|
speed: "steady",
|
|
6668
6680
|
verdict: "not run yet",
|
|
6669
|
-
unrunnable: "not run yet. the
|
|
6681
|
+
unrunnable: "not run yet. the graph names and dtypes are read from the export's files (measured); the pipeline has not run on them.",
|
|
6670
6682
|
group: "good",
|
|
6671
6683
|
provides: ["imagegen"],
|
|
6672
6684
|
provider: "ort",
|
|
@@ -6692,7 +6704,7 @@ ${n}` : n;
|
|
|
6692
6704
|
runtime: "onnxruntime-web@1.27.0",
|
|
6693
6705
|
notes: [
|
|
6694
6706
|
"two text encoders, pooled embeddings and time ids, on generateXl",
|
|
6695
|
-
"fp16
|
|
6707
|
+
"fp16 edges and a float16 timestep; input_ids int32 for the first encoder and int64 for the second (measured from the graphs)",
|
|
6696
6708
|
"the highest quality of the three image models"
|
|
6697
6709
|
],
|
|
6698
6710
|
form: {
|
|
@@ -6716,7 +6728,8 @@ ${n}` : n;
|
|
|
6716
6728
|
pipeline: "sdxl",
|
|
6717
6729
|
xl: {
|
|
6718
6730
|
io: "float16",
|
|
6719
|
-
timestep: "float16"
|
|
6731
|
+
timestep: "float16",
|
|
6732
|
+
ids2: "int64"
|
|
6720
6733
|
}
|
|
6721
6734
|
}
|
|
6722
6735
|
}];
|
|
@@ -8173,7 +8186,7 @@ ${n}` : n;
|
|
|
8173
8186
|
zoomIn: svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M11 8v6M8 11h6\"/>"),
|
|
8174
8187
|
zoomOut: svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M8 11h6\"/>"),
|
|
8175
8188
|
fit: svg("<path d=\"M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5\"/>"),
|
|
8176
|
-
x: svg("<path d=\"M6 6l12 12M18 6 6 18\"/>",
|
|
8189
|
+
x: svg("<path d=\"M6 6l12 12M18 6 6 18\"/>", 14),
|
|
8177
8190
|
copy: svg("<rect x=\"9\" y=\"9\" width=\"11\" height=\"11\"/><path d=\"M5 15V4h11\"/>", 14),
|
|
8178
8191
|
redoMsg: svg("<path d=\"M21 12a9 9 0 1 1-3-6.7L21 8\"/><path d=\"M21 3v5h-5\"/>", 14),
|
|
8179
8192
|
point: svg("<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v5M12 17v5M2 12h5M17 12h5\"/>", 18),
|
|
@@ -8184,8 +8197,8 @@ ${n}` : n;
|
|
|
8184
8197
|
camera: svg("<path d=\"M3 7h4l2-3h6l2 3h4v13H3z\"/><circle cx=\"12\" cy=\"13\" r=\"4\"/>"),
|
|
8185
8198
|
menu: svg("<path d=\"M4 6h16M4 12h16M4 18h16\"/>"),
|
|
8186
8199
|
plus: svg("<path d=\"M12 5v14M5 12h14\"/>", 14),
|
|
8187
|
-
pen: svg("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>",
|
|
8188
|
-
trash: svg("<path d=\"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13\"/>",
|
|
8200
|
+
pen: svg("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>", 14),
|
|
8201
|
+
trash: svg("<path d=\"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13\"/>", 14)
|
|
8189
8202
|
};
|
|
8190
8203
|
// packages/ai-views/src/mount-chat.ts
|
|
8191
8204
|
/**
|
package/dist/single/elements.js
CHANGED
|
@@ -6551,6 +6551,11 @@ const files = [
|
|
|
6551
6551
|
{ path: "unet/model.onnx" },
|
|
6552
6552
|
{ path: "vae_decoder/model.onnx" }
|
|
6553
6553
|
];
|
|
6554
|
+
const SD15 = [
|
|
6555
|
+
"Stable-Diffusion-v1.5-text-encoder-float16",
|
|
6556
|
+
"sd-unet-v1.5-model-b2c4h64w64s77-float16-compute-and-inputs-layernorm",
|
|
6557
|
+
"Stable-Diffusion-v1.5-vae-decoder-float16-fp32-instancenorm"
|
|
6558
|
+
];
|
|
6554
6559
|
const free512 = { freeDimensionOverrides: {
|
|
6555
6560
|
batch_size: 1,
|
|
6556
6561
|
num_channels: 4,
|
|
@@ -6588,7 +6593,7 @@ const IMAGEGEN_RECORDS = [{
|
|
|
6588
6593
|
notes: [
|
|
6589
6594
|
"webgpu only, no wasm floor",
|
|
6590
6595
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)",
|
|
6591
|
-
"graph
|
|
6596
|
+
"graph files, names and dtypes read from the export (measured): fp32 edges, int32 input_ids, int64 timestep; pads with token 0"
|
|
6592
6597
|
],
|
|
6593
6598
|
form: {
|
|
6594
6599
|
steps: {
|
|
@@ -6602,6 +6607,7 @@ const IMAGEGEN_RECORDS = [{
|
|
|
6602
6607
|
spacing: "trailing",
|
|
6603
6608
|
note: "distilled from sd 2.1. 1 to 4 steps, no negative prompt. the fastest path.",
|
|
6604
6609
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
6610
|
+
pad: 0,
|
|
6605
6611
|
graphs
|
|
6606
6612
|
}
|
|
6607
6613
|
}, {
|
|
@@ -6612,9 +6618,10 @@ const IMAGEGEN_RECORDS = [{
|
|
|
6612
6618
|
group: "good",
|
|
6613
6619
|
provides: ["imagegen"],
|
|
6614
6620
|
provider: "ort",
|
|
6621
|
+
unrunnable: "its unet takes a fixed batch of 2 at 64 by 64 latents with fp16 inputs (measured from the graph); the pipeline sends batch 1 in fp32.",
|
|
6615
6622
|
source: {
|
|
6616
6623
|
repo: "microsoft/stable-diffusion-v1.5-webnn",
|
|
6617
|
-
files
|
|
6624
|
+
files: SD15.map((g) => ({ path: `${g}.onnx` }))
|
|
6618
6625
|
},
|
|
6619
6626
|
sizeMB: 1969,
|
|
6620
6627
|
sizeSource: "vendor",
|
|
@@ -6628,7 +6635,7 @@ const IMAGEGEN_RECORDS = [{
|
|
|
6628
6635
|
place: "gpu",
|
|
6629
6636
|
runtime: "onnxruntime-web@1.27.0",
|
|
6630
6637
|
notes: [
|
|
6631
|
-
"about 2 GB (vendor)
|
|
6638
|
+
"about 2 GB (vendor). the export's three graphs were read (measured): int32 input_ids, fp16 hidden states, a unet fixed at batch 2 with fp16 sample and int64 timestep, an fp16 vae",
|
|
6632
6639
|
"runs the unet twice a step for guidance, so a step costs about twice an sd-turbo step (inferred)",
|
|
6633
6640
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)"
|
|
6634
6641
|
],
|
|
@@ -6649,14 +6656,19 @@ const IMAGEGEN_RECORDS = [{
|
|
|
6649
6656
|
spacing: "leading",
|
|
6650
6657
|
note: "classic sd, openrail-m licence. 20 to 30 steps with guidance, takes a negative prompt. slower per image.",
|
|
6651
6658
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
6652
|
-
graphs
|
|
6659
|
+
graphs: {
|
|
6660
|
+
textEncoder: SD15[0],
|
|
6661
|
+
unet: SD15[1],
|
|
6662
|
+
vaeDecoder: SD15[2]
|
|
6663
|
+
}
|
|
6653
6664
|
}
|
|
6654
6665
|
}];
|
|
6655
6666
|
/**
|
|
6656
6667
|
* Listed for pickers, not registered by attachImagegen, so routing by
|
|
6657
|
-
* capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl
|
|
6658
|
-
* export's input and output names
|
|
6659
|
-
*
|
|
6668
|
+
* capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl`. The
|
|
6669
|
+
* export's input and output names and dtypes were read from the end of
|
|
6670
|
+
* each onnx file (2026-11-29, measured); the pipeline has not run on the
|
|
6671
|
+
* real weights. `loadImagegen(hub, { id:
|
|
6660
6672
|
* "sdxl-turbo" })` adds it and loads it.
|
|
6661
6673
|
*/
|
|
6662
6674
|
const IMAGEGEN_PICKER_RECORDS = [{
|
|
@@ -6664,7 +6676,7 @@ const IMAGEGEN_PICKER_RECORDS = [{
|
|
|
6664
6676
|
label: "sdxl-turbo 512",
|
|
6665
6677
|
speed: "steady",
|
|
6666
6678
|
verdict: "not run yet",
|
|
6667
|
-
unrunnable: "not run yet. the
|
|
6679
|
+
unrunnable: "not run yet. the graph names and dtypes are read from the export's files (measured); the pipeline has not run on them.",
|
|
6668
6680
|
group: "good",
|
|
6669
6681
|
provides: ["imagegen"],
|
|
6670
6682
|
provider: "ort",
|
|
@@ -6690,7 +6702,7 @@ const IMAGEGEN_PICKER_RECORDS = [{
|
|
|
6690
6702
|
runtime: "onnxruntime-web@1.27.0",
|
|
6691
6703
|
notes: [
|
|
6692
6704
|
"two text encoders, pooled embeddings and time ids, on generateXl",
|
|
6693
|
-
"fp16
|
|
6705
|
+
"fp16 edges and a float16 timestep; input_ids int32 for the first encoder and int64 for the second (measured from the graphs)",
|
|
6694
6706
|
"the highest quality of the three image models"
|
|
6695
6707
|
],
|
|
6696
6708
|
form: {
|
|
@@ -6714,7 +6726,8 @@ const IMAGEGEN_PICKER_RECORDS = [{
|
|
|
6714
6726
|
pipeline: "sdxl",
|
|
6715
6727
|
xl: {
|
|
6716
6728
|
io: "float16",
|
|
6717
|
-
timestep: "float16"
|
|
6729
|
+
timestep: "float16",
|
|
6730
|
+
ids2: "int64"
|
|
6718
6731
|
}
|
|
6719
6732
|
}
|
|
6720
6733
|
}];
|
|
@@ -8171,7 +8184,7 @@ const ICON = {
|
|
|
8171
8184
|
zoomIn: svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M11 8v6M8 11h6\"/>"),
|
|
8172
8185
|
zoomOut: svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M8 11h6\"/>"),
|
|
8173
8186
|
fit: svg("<path d=\"M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5\"/>"),
|
|
8174
|
-
x: svg("<path d=\"M6 6l12 12M18 6 6 18\"/>",
|
|
8187
|
+
x: svg("<path d=\"M6 6l12 12M18 6 6 18\"/>", 14),
|
|
8175
8188
|
copy: svg("<rect x=\"9\" y=\"9\" width=\"11\" height=\"11\"/><path d=\"M5 15V4h11\"/>", 14),
|
|
8176
8189
|
redoMsg: svg("<path d=\"M21 12a9 9 0 1 1-3-6.7L21 8\"/><path d=\"M21 3v5h-5\"/>", 14),
|
|
8177
8190
|
point: svg("<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v5M12 17v5M2 12h5M17 12h5\"/>", 18),
|
|
@@ -8182,8 +8195,8 @@ const ICON = {
|
|
|
8182
8195
|
camera: svg("<path d=\"M3 7h4l2-3h6l2 3h4v13H3z\"/><circle cx=\"12\" cy=\"13\" r=\"4\"/>"),
|
|
8183
8196
|
menu: svg("<path d=\"M4 6h16M4 12h16M4 18h16\"/>"),
|
|
8184
8197
|
plus: svg("<path d=\"M12 5v14M5 12h14\"/>", 14),
|
|
8185
|
-
pen: svg("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>",
|
|
8186
|
-
trash: svg("<path d=\"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13\"/>",
|
|
8198
|
+
pen: svg("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>", 14),
|
|
8199
|
+
trash: svg("<path d=\"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13\"/>", 14)
|
|
8187
8200
|
};
|
|
8188
8201
|
// packages/ai-views/src/mount-chat.ts
|
|
8189
8202
|
/**
|
|
@@ -7727,6 +7727,73 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7727
7727
|
return x;
|
|
7728
7728
|
}
|
|
7729
7729
|
var init_schedule = __esmMin((() => {}));
|
|
7730
|
+
// packages/imagegen/src/half.ts
|
|
7731
|
+
/** Half float conversion at the graph edge, for exports with fp16 inputs and outputs. */
|
|
7732
|
+
/** Float32 to IEEE 754 half bits, round to nearest even. */
|
|
7733
|
+
function toHalf(f) {
|
|
7734
|
+
const out = new Uint16Array(f.length);
|
|
7735
|
+
const b = /* @__PURE__ */ new Float32Array(1);
|
|
7736
|
+
const u = new Uint32Array(b.buffer);
|
|
7737
|
+
for (let i = 0; i < f.length; i++) {
|
|
7738
|
+
b[0] = f[i];
|
|
7739
|
+
const x = u[0];
|
|
7740
|
+
const sign = x >>> 16 & 32768;
|
|
7741
|
+
const exp = x >>> 23 & 255;
|
|
7742
|
+
let mant = x & 8388607;
|
|
7743
|
+
if (exp === 255) {
|
|
7744
|
+
out[i] = sign | 31744 | (mant ? 512 : 0);
|
|
7745
|
+
continue;
|
|
7746
|
+
}
|
|
7747
|
+
const e = exp - 127 + 15;
|
|
7748
|
+
if (e >= 31) {
|
|
7749
|
+
out[i] = sign | 31744;
|
|
7750
|
+
continue;
|
|
7751
|
+
}
|
|
7752
|
+
if (e <= 0) {
|
|
7753
|
+
if (e < -10) {
|
|
7754
|
+
out[i] = sign;
|
|
7755
|
+
continue;
|
|
7756
|
+
}
|
|
7757
|
+
mant |= 8388608;
|
|
7758
|
+
const shift = 14 - e;
|
|
7759
|
+
let h = mant >>> shift;
|
|
7760
|
+
const rem = mant & (1 << shift) - 1;
|
|
7761
|
+
const half = 1 << shift - 1;
|
|
7762
|
+
if (rem > half || rem === half && h & 1) h++;
|
|
7763
|
+
out[i] = sign | h;
|
|
7764
|
+
continue;
|
|
7765
|
+
}
|
|
7766
|
+
let h = e << 10 | mant >>> 13;
|
|
7767
|
+
const rem = mant & 8191;
|
|
7768
|
+
if (rem > 4096 || rem === 4096 && h & 1) h++;
|
|
7769
|
+
out[i] = sign | h;
|
|
7770
|
+
}
|
|
7771
|
+
return out;
|
|
7772
|
+
}
|
|
7773
|
+
/** IEEE 754 half bits to float32. */
|
|
7774
|
+
function fromHalf(h) {
|
|
7775
|
+
const out = new Float32Array(h.length);
|
|
7776
|
+
for (let i = 0; i < h.length; i++) {
|
|
7777
|
+
const v = h[i];
|
|
7778
|
+
const s = v & 32768 ? -1 : 1;
|
|
7779
|
+
const e = v >>> 10 & 31;
|
|
7780
|
+
const m = v & 1023;
|
|
7781
|
+
out[i] = e === 0 ? s * m * 2 ** -24 : e === 31 ? m ? NaN : s * Infinity : s * (1 + m / 1024) * 2 ** (e - 15);
|
|
7782
|
+
}
|
|
7783
|
+
return out;
|
|
7784
|
+
}
|
|
7785
|
+
/**
|
|
7786
|
+
* An output's floats. onnxruntime-web gives a float16 output as a
|
|
7787
|
+
* Float16Array of real values where the browser has one, and as Uint16Array
|
|
7788
|
+
* half bits where it does not; only the bits are decoded.
|
|
7789
|
+
*/
|
|
7790
|
+
function floatsOf(t) {
|
|
7791
|
+
const F16 = globalThis.Float16Array;
|
|
7792
|
+
if (F16 && t.data instanceof F16) return Float32Array.from(t.data);
|
|
7793
|
+
if (t.data instanceof Uint16Array) return fromHalf(t.data);
|
|
7794
|
+
return Float32Array.from(t.data);
|
|
7795
|
+
}
|
|
7796
|
+
var init_half = __esmMin((() => {}));
|
|
7730
7797
|
// packages/imagegen/src/pipeline.ts
|
|
7731
7798
|
/** NCHW floats in [-1, 1] to RGBA bytes. */
|
|
7732
7799
|
function toRgba(nchw, w, h) {
|
|
@@ -7765,10 +7832,10 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7765
7832
|
};
|
|
7766
7833
|
let t = now();
|
|
7767
7834
|
const encode = async (text) => {
|
|
7768
|
-
const ids = padIds(await tokenize(text.length ? text : " "));
|
|
7835
|
+
const ids = padIds(await tokenize(text.length ? text : " "), 77, o.pad);
|
|
7769
7836
|
const te = await run(() => s.textEncoder.run({ input_ids: new ort.Tensor("int32", ids, [1, 77]) }));
|
|
7770
7837
|
const hidden = te.last_hidden_state ?? Object.values(te)[0];
|
|
7771
|
-
return new ort.Tensor("float32",
|
|
7838
|
+
return new ort.Tensor("float32", floatsOf(hidden), [...hidden.dims ?? [
|
|
7772
7839
|
1,
|
|
7773
7840
|
77,
|
|
7774
7841
|
hidden.data.length / 77
|
|
@@ -7802,7 +7869,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7802
7869
|
timestep: new ort.Tensor("int64", BigInt64Array.from([BigInt(timestep)]), [1]),
|
|
7803
7870
|
encoder_hidden_states: h
|
|
7804
7871
|
}));
|
|
7805
|
-
return (u.out_sample ?? Object.values(u)[0])
|
|
7872
|
+
return floatsOf(u.out_sample ?? Object.values(u)[0]);
|
|
7806
7873
|
};
|
|
7807
7874
|
const c = await unet(hiddenTensor);
|
|
7808
7875
|
let e = c;
|
|
@@ -7841,13 +7908,14 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7841
7908
|
return {
|
|
7842
7909
|
width: size,
|
|
7843
7910
|
height: size,
|
|
7844
|
-
rgba: toRgba((v.sample ?? Object.values(v)[0])
|
|
7911
|
+
rgba: toRgba(floatsOf(v.sample ?? Object.values(v)[0]), size, size),
|
|
7845
7912
|
seed,
|
|
7846
7913
|
ms
|
|
7847
7914
|
};
|
|
7848
7915
|
}
|
|
7849
7916
|
var VAE_SCALE;
|
|
7850
7917
|
var init_pipeline = __esmMin((() => {
|
|
7918
|
+
init_half();
|
|
7851
7919
|
init_schedule();
|
|
7852
7920
|
VAE_SCALE = .18215;
|
|
7853
7921
|
}));
|
|
@@ -7863,7 +7931,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7863
7931
|
if (rec.sizeMB === 0) return `load ${name}, no download`;
|
|
7864
7932
|
return `load ${name}, about ${rec.sizeMB >= 1e3 ? `${(rec.sizeMB / 1e3).toFixed(1)} gb` : `${rec.sizeMB} mb`} (${rec.sizeSource})`;
|
|
7865
7933
|
}
|
|
7866
|
-
var graphs, files, free512, IMAGEGEN_RECORDS, IMAGEGEN_PICKER_RECORDS;
|
|
7934
|
+
var graphs, files, SD15, free512, IMAGEGEN_RECORDS, IMAGEGEN_PICKER_RECORDS;
|
|
7867
7935
|
var init_records$3 = __esmMin((() => {
|
|
7868
7936
|
graphs = {
|
|
7869
7937
|
textEncoder: "text_encoder",
|
|
@@ -7875,6 +7943,11 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7875
7943
|
{ path: "unet/model.onnx" },
|
|
7876
7944
|
{ path: "vae_decoder/model.onnx" }
|
|
7877
7945
|
];
|
|
7946
|
+
SD15 = [
|
|
7947
|
+
"Stable-Diffusion-v1.5-text-encoder-float16",
|
|
7948
|
+
"sd-unet-v1.5-model-b2c4h64w64s77-float16-compute-and-inputs-layernorm",
|
|
7949
|
+
"Stable-Diffusion-v1.5-vae-decoder-float16-fp32-instancenorm"
|
|
7950
|
+
];
|
|
7878
7951
|
free512 = { freeDimensionOverrides: {
|
|
7879
7952
|
batch_size: 1,
|
|
7880
7953
|
num_channels: 4,
|
|
@@ -7911,7 +7984,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7911
7984
|
notes: [
|
|
7912
7985
|
"webgpu only, no wasm floor",
|
|
7913
7986
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)",
|
|
7914
|
-
"graph
|
|
7987
|
+
"graph files, names and dtypes read from the export (measured): fp32 edges, int32 input_ids, int64 timestep; pads with token 0"
|
|
7915
7988
|
],
|
|
7916
7989
|
form: {
|
|
7917
7990
|
steps: {
|
|
@@ -7925,6 +7998,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7925
7998
|
spacing: "trailing",
|
|
7926
7999
|
note: "distilled from sd 2.1. 1 to 4 steps, no negative prompt. the fastest path.",
|
|
7927
8000
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
8001
|
+
pad: 0,
|
|
7928
8002
|
graphs
|
|
7929
8003
|
}
|
|
7930
8004
|
}, {
|
|
@@ -7935,9 +8009,10 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7935
8009
|
group: "good",
|
|
7936
8010
|
provides: ["imagegen"],
|
|
7937
8011
|
provider: "ort",
|
|
8012
|
+
unrunnable: "its unet takes a fixed batch of 2 at 64 by 64 latents with fp16 inputs (measured from the graph); the pipeline sends batch 1 in fp32.",
|
|
7938
8013
|
source: {
|
|
7939
8014
|
repo: "microsoft/stable-diffusion-v1.5-webnn",
|
|
7940
|
-
files
|
|
8015
|
+
files: SD15.map((g) => ({ path: `${g}.onnx` }))
|
|
7941
8016
|
},
|
|
7942
8017
|
sizeMB: 1969,
|
|
7943
8018
|
sizeSource: "vendor",
|
|
@@ -7951,7 +8026,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7951
8026
|
place: "gpu",
|
|
7952
8027
|
runtime: "onnxruntime-web@1.27.0",
|
|
7953
8028
|
notes: [
|
|
7954
|
-
"about 2 GB (vendor)
|
|
8029
|
+
"about 2 GB (vendor). the export's three graphs were read (measured): int32 input_ids, fp16 hidden states, a unet fixed at batch 2 with fp16 sample and int64 timestep, an fp16 vae",
|
|
7955
8030
|
"runs the unet twice a step for guidance, so a step costs about twice an sd-turbo step (inferred)",
|
|
7956
8031
|
"tokenizer: Xenova/clip-vit-base-patch16 through transformers.js (CLIP weights MIT)"
|
|
7957
8032
|
],
|
|
@@ -7972,7 +8047,11 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7972
8047
|
spacing: "leading",
|
|
7973
8048
|
note: "classic sd, openrail-m licence. 20 to 30 steps with guidance, takes a negative prompt. slower per image.",
|
|
7974
8049
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
7975
|
-
graphs
|
|
8050
|
+
graphs: {
|
|
8051
|
+
textEncoder: SD15[0],
|
|
8052
|
+
unet: SD15[1],
|
|
8053
|
+
vaeDecoder: SD15[2]
|
|
8054
|
+
}
|
|
7976
8055
|
}
|
|
7977
8056
|
}];
|
|
7978
8057
|
IMAGEGEN_PICKER_RECORDS = [{
|
|
@@ -7980,7 +8059,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7980
8059
|
label: "sdxl-turbo 512",
|
|
7981
8060
|
speed: "steady",
|
|
7982
8061
|
verdict: "not run yet",
|
|
7983
|
-
unrunnable: "not run yet. the
|
|
8062
|
+
unrunnable: "not run yet. the graph names and dtypes are read from the export's files (measured); the pipeline has not run on them.",
|
|
7984
8063
|
group: "good",
|
|
7985
8064
|
provides: ["imagegen"],
|
|
7986
8065
|
provider: "ort",
|
|
@@ -8006,7 +8085,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8006
8085
|
runtime: "onnxruntime-web@1.27.0",
|
|
8007
8086
|
notes: [
|
|
8008
8087
|
"two text encoders, pooled embeddings and time ids, on generateXl",
|
|
8009
|
-
"fp16
|
|
8088
|
+
"fp16 edges and a float16 timestep; input_ids int32 for the first encoder and int64 for the second (measured from the graphs)",
|
|
8010
8089
|
"the highest quality of the three image models"
|
|
8011
8090
|
],
|
|
8012
8091
|
form: {
|
|
@@ -8030,70 +8109,13 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8030
8109
|
pipeline: "sdxl",
|
|
8031
8110
|
xl: {
|
|
8032
8111
|
io: "float16",
|
|
8033
|
-
timestep: "float16"
|
|
8112
|
+
timestep: "float16",
|
|
8113
|
+
ids2: "int64"
|
|
8034
8114
|
}
|
|
8035
8115
|
}
|
|
8036
8116
|
}];
|
|
8037
8117
|
}));
|
|
8038
8118
|
// packages/imagegen/src/xl.ts
|
|
8039
|
-
/** Float32 to IEEE 754 half bits, round to nearest even. */
|
|
8040
|
-
function toHalf(f) {
|
|
8041
|
-
const out = new Uint16Array(f.length);
|
|
8042
|
-
const b = /* @__PURE__ */ new Float32Array(1);
|
|
8043
|
-
const u = new Uint32Array(b.buffer);
|
|
8044
|
-
for (let i = 0; i < f.length; i++) {
|
|
8045
|
-
b[0] = f[i];
|
|
8046
|
-
const x = u[0];
|
|
8047
|
-
const sign = x >>> 16 & 32768;
|
|
8048
|
-
const exp = x >>> 23 & 255;
|
|
8049
|
-
let mant = x & 8388607;
|
|
8050
|
-
if (exp === 255) {
|
|
8051
|
-
out[i] = sign | 31744 | (mant ? 512 : 0);
|
|
8052
|
-
continue;
|
|
8053
|
-
}
|
|
8054
|
-
const e = exp - 127 + 15;
|
|
8055
|
-
if (e >= 31) {
|
|
8056
|
-
out[i] = sign | 31744;
|
|
8057
|
-
continue;
|
|
8058
|
-
}
|
|
8059
|
-
if (e <= 0) {
|
|
8060
|
-
if (e < -10) {
|
|
8061
|
-
out[i] = sign;
|
|
8062
|
-
continue;
|
|
8063
|
-
}
|
|
8064
|
-
mant |= 8388608;
|
|
8065
|
-
const shift = 14 - e;
|
|
8066
|
-
let h = mant >>> shift;
|
|
8067
|
-
const rem = mant & (1 << shift) - 1;
|
|
8068
|
-
const half = 1 << shift - 1;
|
|
8069
|
-
if (rem > half || rem === half && h & 1) h++;
|
|
8070
|
-
out[i] = sign | h;
|
|
8071
|
-
continue;
|
|
8072
|
-
}
|
|
8073
|
-
let h = e << 10 | mant >>> 13;
|
|
8074
|
-
const rem = mant & 8191;
|
|
8075
|
-
if (rem > 4096 || rem === 4096 && h & 1) h++;
|
|
8076
|
-
out[i] = sign | h;
|
|
8077
|
-
}
|
|
8078
|
-
return out;
|
|
8079
|
-
}
|
|
8080
|
-
/** IEEE 754 half bits to float32. */
|
|
8081
|
-
function fromHalf(h) {
|
|
8082
|
-
const out = new Float32Array(h.length);
|
|
8083
|
-
for (let i = 0; i < h.length; i++) {
|
|
8084
|
-
const v = h[i];
|
|
8085
|
-
const s = v & 32768 ? -1 : 1;
|
|
8086
|
-
const e = v >>> 10 & 31;
|
|
8087
|
-
const m = v & 1023;
|
|
8088
|
-
out[i] = e === 0 ? s * m * 2 ** -24 : e === 31 ? m ? NaN : s * Infinity : s * (1 + m / 1024) * 2 ** (e - 15);
|
|
8089
|
-
}
|
|
8090
|
-
return out;
|
|
8091
|
-
}
|
|
8092
|
-
/** An output's floats; fp16 outputs (type "float16" or Uint16Array data) are decoded. */
|
|
8093
|
-
function floatsOf(t) {
|
|
8094
|
-
if (t.type === "float16" || t.data instanceof Uint16Array) return fromHalf(t.data);
|
|
8095
|
-
return Float32Array.from(t.data);
|
|
8096
|
-
}
|
|
8097
8119
|
/** CLIP ids for the second encoder: up to the first end token, then `pad` to 77. */
|
|
8098
8120
|
function padIds2(ids, pad = 0) {
|
|
8099
8121
|
const list = Array.from(ids);
|
|
@@ -8134,8 +8156,9 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8134
8156
|
let t = now();
|
|
8135
8157
|
const encode = async (text) => {
|
|
8136
8158
|
const ids = await tokenize(text.length ? text : " ");
|
|
8137
|
-
const
|
|
8138
|
-
const
|
|
8159
|
+
const idsOf = (v, dtype) => dtype === "int64" ? new ort.Tensor("int64", BigInt64Array.from(v, (x) => BigInt(x)), [1, 77]) : new ort.Tensor("int32", v, [1, 77]);
|
|
8160
|
+
const a = await run(() => s.textEncoder.run({ input_ids: idsOf(padIds(ids), io.ids1) }));
|
|
8161
|
+
const b = await run(() => s.textEncoder2.run({ input_ids: idsOf(padIds2(ids, io.pad2), io.ids2) }));
|
|
8139
8162
|
const h1 = floatsOf(pick(a, io.hidden1, ["last_hidden_state"], "text encoder"));
|
|
8140
8163
|
const h2 = floatsOf(pick(b, io.hidden2, ["last_hidden_state"], "text encoder 2"));
|
|
8141
8164
|
const pooled = floatsOf(pick(b, io.pooled, ["pooler_output"], "text encoder 2"));
|
|
@@ -8241,9 +8264,12 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8241
8264
|
var init_xl = __esmMin((() => {
|
|
8242
8265
|
init_pipeline();
|
|
8243
8266
|
init_schedule();
|
|
8267
|
+
init_half();
|
|
8244
8268
|
XL_IO = {
|
|
8245
8269
|
io: "float32",
|
|
8246
8270
|
timestep: "int64",
|
|
8271
|
+
ids1: "int32",
|
|
8272
|
+
ids2: "int32",
|
|
8247
8273
|
hidden1: "hidden_states.11",
|
|
8248
8274
|
hidden2: "hidden_states.31",
|
|
8249
8275
|
pooled: "text_embeds",
|
|
@@ -8286,6 +8312,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8286
8312
|
if (form.guidance) out.guidance = Math.min(form.guidance.max, Math.max(form.guidance.min, o.guidance ?? form.guidance.default));
|
|
8287
8313
|
else delete out.guidance;
|
|
8288
8314
|
if (!form.negative) delete out.negative;
|
|
8315
|
+
if (form.pad !== void 0) out.pad = form.pad;
|
|
8289
8316
|
return out;
|
|
8290
8317
|
}
|
|
8291
8318
|
/**
|
|
@@ -16575,7 +16602,7 @@ self.onmessage = async (ev) => {
|
|
|
16575
16602
|
}
|
|
16576
16603
|
/** Inline SVG icons, stroked in currentColor, 16 px. */
|
|
16577
16604
|
const svg = (d, size = 16) => `<svg class="hb-icon is-stroke" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" aria-hidden="true">${d}</svg>`;
|
|
16578
|
-
svg("<path d=\"M9 14 4 9l5-5\"/><path d=\"M4 9h10a6 6 0 0 1 0 12h-3\"/>"), svg("<path d=\"m15 14 5-5-5-5\"/><path d=\"M20 9H10a6 6 0 0 0 0 12h3\"/>"), svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M11 8v6M8 11h6\"/>"), svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M8 11h6\"/>"), svg("<path d=\"M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5\"/>"), svg("<path d=\"M6 6l12 12M18 6 6 18\"/>",
|
|
16605
|
+
svg("<path d=\"M9 14 4 9l5-5\"/><path d=\"M4 9h10a6 6 0 0 1 0 12h-3\"/>"), svg("<path d=\"m15 14 5-5-5-5\"/><path d=\"M20 9H10a6 6 0 0 0 0 12h3\"/>"), svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M11 8v6M8 11h6\"/>"), svg("<circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"M21 21l-4.3-4.3M8 11h6\"/>"), svg("<path d=\"M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5\"/>"), svg("<path d=\"M6 6l12 12M18 6 6 18\"/>", 14), svg("<rect x=\"9\" y=\"9\" width=\"11\" height=\"11\"/><path d=\"M5 15V4h11\"/>", 14), svg("<path d=\"M21 12a9 9 0 1 1-3-6.7L21 8\"/><path d=\"M21 3v5h-5\"/>", 14), svg("<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v5M12 17v5M2 12h5M17 12h5\"/>", 18), svg("<path d=\"m3 21 12-12M15 3v3M18 6h3M19 2l-1 1M14 9l1 1\"/>", 18), svg("<path d=\"M18 3 9 12l3 3 9-9z\"/><path d=\"M9 12c-3 0-5 2-5 5 0 2-1 3-2 4 4 0 8-1 9-4\"/>", 18), svg("<ellipse cx=\"12\" cy=\"9\" rx=\"8\" ry=\"5\"/><path d=\"M7 13c-1 2 0 4 2 4s2 3 0 5\"/>", 18), svg("<rect x=\"3\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"3\" y=\"14\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"14\" width=\"7\" height=\"7\"/>", 18), svg("<path d=\"M3 7h4l2-3h6l2 3h4v13H3z\"/><circle cx=\"12\" cy=\"13\" r=\"4\"/>"), svg("<path d=\"M4 6h16M4 12h16M4 18h16\"/>"), svg("<path d=\"M12 5v14M5 12h14\"/>", 14), svg("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>", 14), svg("<path d=\"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13\"/>", 14);
|
|
16579
16606
|
// packages/ai-views/src/memory.ts
|
|
16580
16607
|
const n3 = (x) => Number.isFinite(x) ? x.toFixed(3) : "none";
|
|
16581
16608
|
const rank = (r) => r >= 0 ? `#${r + 1}` : "none";
|