Spaces:
Running
Running
fix(model): pin the CLIP text tower to a loadable ONNX revision
Browse filesFixes 'Không tải được bộ tìm kiếm' / [ShapeInferenceError] Inferred=1 Declared=768.
The model repo's first ONNX export declared 'masked' as [...,768]; commit 9e1d535
re-exported it cleanly. transformers.js cached the broken bytes under the
unversioned /resolve/main/ URL, so reload and 'Thử lại' replayed them. Pinning
'revision' changes the cache key and lets those browsers recover.
- dist/assets/index.js +0 -0
- dist/assets/worker-Ci6Eg777.js +0 -0
- src/assets.js +23 -0
- src/worker.js +11 -2
dist/assets/index.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/worker-Ci6Eg777.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/assets.js
CHANGED
|
@@ -10,6 +10,29 @@ export const DATASET = 'https://huggingface.co/datasets/bep40/interior-image-fie
|
|
| 10 |
// so this fork adds a `text_model.onnx` that includes mean pooling and the 768->512
|
| 11 |
// projection, letting Transformers.js run it under the usual CLIP file naming.
|
| 12 |
export const TEXT_MODEL = 'bep40/clip-vit-b32-multilingual-vi-text';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
export const TOKENIZER = 'sentence-transformers/clip-ViT-B-32-multilingual-v1';
|
| 14 |
export const DIMENSIONS = 512;
|
| 15 |
|
|
|
|
| 10 |
// so this fork adds a `text_model.onnx` that includes mean pooling and the 768->512
|
| 11 |
// projection, letting Transformers.js run it under the usual CLIP file naming.
|
| 12 |
export const TEXT_MODEL = 'bep40/clip-vit-b32-multilingual-vi-text';
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Pinned to the commit whose `onnx/text_model.onnx` actually loads, instead of
|
| 16 |
+
* following the `main` branch.
|
| 17 |
+
*
|
| 18 |
+
* The repo uploaded a broken export first (commit 68dc949, 136,951,792 bytes).
|
| 19 |
+
* Its graph declares `masked` as [batch_size, sequence_length, 768] while an
|
| 20 |
+
* attention mask only ever has 1 feature, so ONNX shape inference aborts with
|
| 21 |
+
*
|
| 22 |
+
* [ShapeInferenceError] Can't merge shape info ... Inferred=1 Declared=768
|
| 23 |
+
*
|
| 24 |
+
* and the app dies at "Không tải được bộ tìm kiếm". A later commit (9e1d535,
|
| 25 |
+
* 136,915,522 bytes) re-exported the graph with no `value_info` at all, which
|
| 26 |
+
* loads fine -- that is the revision pinned here.
|
| 27 |
+
*
|
| 28 |
+
* Pinning matters beyond reproducibility. transformers.js requests the
|
| 29 |
+
* *unversioned* `/resolve/main/...` URL unless `revision` is given, and caches
|
| 30 |
+
* under that same URL. Anyone who loaded the app while `main` still pointed at
|
| 31 |
+
* the broken graph keeps the bad bytes indefinitely: reload and "Thử lại" both
|
| 32 |
+
* replay from that cache. Naming an explicit commit changes the cache key, so
|
| 33 |
+
* those visitors fetch the known-good file instead of staying stuck.
|
| 34 |
+
*/
|
| 35 |
+
export const TEXT_MODEL_REVISION = '9e1d53553228b17abfe6986fbe92e22bd6bd6bad';
|
| 36 |
export const TOKENIZER = 'sentence-transformers/clip-ViT-B-32-multilingual-v1';
|
| 37 |
export const DIMENSIONS = 512;
|
| 38 |
|
src/worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { AutoTokenizer, CLIPTextModelWithProjection, env } from '@huggingface/transformers';
|
| 2 |
-
import { cachedFile, DATASET, TOKENIZER, TEXT_MODEL, DIMENSIONS } from './assets.js';
|
| 3 |
import { normalizeDatabase, rankImages } from './search.js';
|
| 4 |
import { loadCatalogue, searchCatalogue, tryLoadCatalogue } from './catalogue.js';
|
| 5 |
|
|
@@ -35,7 +35,16 @@ function initialize() {
|
|
| 35 |
// onnx/ contains exactly one graph, text_model.onnx (130.6 MB), and no
|
| 36 |
// *_quantized variant -- verified on the Hub. Any dtype other than 'fp32'
|
| 37 |
// would ask for a file that does not exist, so pin 'fp32' and device 'wasm'.
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
cachedFile(DATASET + 'image-embeddings.json').then(buffer => JSON.parse(new TextDecoder().decode(buffer))),
|
| 40 |
cachedFile(DATASET + 'image-embeddings_25k-512-32bit.bin'),
|
| 41 |
]);
|
|
|
|
| 1 |
import { AutoTokenizer, CLIPTextModelWithProjection, env } from '@huggingface/transformers';
|
| 2 |
+
import { cachedFile, DATASET, TOKENIZER, TEXT_MODEL, TEXT_MODEL_REVISION, DIMENSIONS } from './assets.js';
|
| 3 |
import { normalizeDatabase, rankImages } from './search.js';
|
| 4 |
import { loadCatalogue, searchCatalogue, tryLoadCatalogue } from './catalogue.js';
|
| 5 |
|
|
|
|
| 35 |
// onnx/ contains exactly one graph, text_model.onnx (130.6 MB), and no
|
| 36 |
// *_quantized variant -- verified on the Hub. Any dtype other than 'fp32'
|
| 37 |
// would ask for a file that does not exist, so pin 'fp32' and device 'wasm'.
|
| 38 |
+
//
|
| 39 |
+
// `revision` is load-bearing, not a reproducibility nicety: without it the
|
| 40 |
+
// graph is fetched and cached under the unversioned /resolve/main/ URL, so
|
| 41 |
+
// browsers that cached the broken 68dc949 export keep failing with
|
| 42 |
+
// [ShapeInferenceError] Inferred=1 Declared=768 on every reload. See
|
| 43 |
+
// TEXT_MODEL_REVISION in assets.js.
|
| 44 |
+
CLIPTextModelWithProjection.from_pretrained(
|
| 45 |
+
TEXT_MODEL,
|
| 46 |
+
{ dtype: 'fp32', device: 'wasm', revision: TEXT_MODEL_REVISION, progress_callback },
|
| 47 |
+
),
|
| 48 |
cachedFile(DATASET + 'image-embeddings.json').then(buffer => JSON.parse(new TextDecoder().decode(buffer))),
|
| 49 |
cachedFile(DATASET + 'image-embeddings_25k-512-32bit.bin'),
|
| 50 |
]);
|