NullSense commited on
Commit
742f61a
·
verified ·
1 Parent(s): 1113378

Publish IconClip text encoder q8 (transformers.js layout + quantization linkage)

Browse files
Files changed (1) hide show
  1. README.md +14 -5
README.md CHANGED
@@ -276,15 +276,24 @@ import { AutoTokenizer, AutoModel } from "@huggingface/transformers";
276
 
277
  const repo = "Cortiq-Labs/IconClip-ViT-L-14-text-encoder-ONNX";
278
  const tokenizer = await AutoTokenizer.from_pretrained(repo);
279
- const model = await AutoModel.from_pretrained(repo, { quantized: true });
 
 
 
280
 
281
- const enc = await tokenizer("shopping cart", {
 
 
 
282
  padding: "max_length",
283
- truncation: true,
284
  max_length: 77,
 
285
  });
286
- const { embeddings } = await model({ input_ids: enc.input_ids });
287
- // embeddings: Float32Array(768), L2-normalised
 
 
 
288
  ```
289
 
290
  For best results, enable cross-origin isolation (`COOP: same-origin` +
 
276
 
277
  const repo = "Cortiq-Labs/IconClip-ViT-L-14-text-encoder-ONNX";
278
  const tokenizer = await AutoTokenizer.from_pretrained(repo);
279
+ const model = await AutoModel.from_pretrained(repo, {
280
+ dtype: "q8",
281
+ device: "wasm", // or "webgpu" where supported
282
+ });
283
 
284
+ // CLIP text encoders use a fixed 77-token context window — pad every input
285
+ // to that length. This matches OpenAI CLIP, LAION CLIP, and every other
286
+ // CLIP-family ONNX export on HF.
287
+ const enc = await tokenizer(["shopping cart"], {
288
  padding: "max_length",
 
289
  max_length: 77,
290
+ truncation: true,
291
  });
292
+ const out = await model(enc);
293
+ // The ONNX exposes the projected 768-d output under the `embeddings` key.
294
+ // transformers.js v4's EncoderOnly fallback uses this name when the
295
+ // CLIPTextModel config maps to the q8 quantized graph.
296
+ const vec = out.embeddings.data; // Float32Array(768), L2-normalised
297
  ```
298
 
299
  For best results, enable cross-origin isolation (`COOP: same-origin` +