Upload example_web.js with huggingface_hub
Browse files- example_web.js +5 -2
example_web.js
CHANGED
|
@@ -96,15 +96,18 @@ export async function loadSupra(repo = REPO, { onProgress, backends = ['webgpu']
|
|
| 96 |
const ort = await loadLib('onnxruntime-web', { globalName: 'ort' });
|
| 97 |
const { AutoTokenizer } = await loadLib('@huggingface/transformers', { url: TRANSFORMERS_CDN_URL });
|
| 98 |
const cfg = await (await fetch(fileUrl(repo, 'pipeline_config.json'))).json();
|
| 99 |
-
const [ditBuf,
|
| 100 |
download(fileUrl(repo, cfg.dit), cfg.dit, onProgress),
|
| 101 |
-
download(fileUrl(repo, cfg.text_encoder), cfg.text_encoder, onProgress),
|
| 102 |
download(fileUrl(repo, cfg.vae_decoder), cfg.vae_decoder, onProgress),
|
| 103 |
]);
|
| 104 |
const tokenize = await AutoTokenizer.from_pretrained(repo);
|
| 105 |
const errors = [];
|
| 106 |
for (const backend of backends) {
|
| 107 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
const opts = { executionProviders: [backend] };
|
| 109 |
const [dit, enc, vae] = await Promise.all([
|
| 110 |
ort.InferenceSession.create(ditBuf, opts),
|
|
|
|
| 96 |
const ort = await loadLib('onnxruntime-web', { globalName: 'ort' });
|
| 97 |
const { AutoTokenizer } = await loadLib('@huggingface/transformers', { url: TRANSFORMERS_CDN_URL });
|
| 98 |
const cfg = await (await fetch(fileUrl(repo, 'pipeline_config.json'))).json();
|
| 99 |
+
const [ditBuf, vaeBuf] = await Promise.all([
|
| 100 |
download(fileUrl(repo, cfg.dit), cfg.dit, onProgress),
|
|
|
|
| 101 |
download(fileUrl(repo, cfg.vae_decoder), cfg.vae_decoder, onProgress),
|
| 102 |
]);
|
| 103 |
const tokenize = await AutoTokenizer.from_pretrained(repo);
|
| 104 |
const errors = [];
|
| 105 |
for (const backend of backends) {
|
| 106 |
try {
|
| 107 |
+
// WASM/CPU backends get the fp32 encoder: fp16 support there is unreliable
|
| 108 |
+
// and a single NaN poisons the whole image (renders black, no error).
|
| 109 |
+
const encPath = backend === 'wasm' ? (cfg.text_encoder_fp32 || cfg.text_encoder) : cfg.text_encoder;
|
| 110 |
+
const encBuf = await download(fileUrl(repo, encPath), encPath, onProgress);
|
| 111 |
const opts = { executionProviders: [backend] };
|
| 112 |
const [dit, enc, vae] = await Promise.all([
|
| 113 |
ort.InferenceSession.create(ditBuf, opts),
|