Transformers.js v3.5 optimizations (#2)
Browse files- Transformers.js v3.5 optimizations (9c78ee8eec92f0cbabdffcbd91d62f4853d4e806)
- Update config.json (b766e9e06f6a8777736101c0c91b1def50badc10)
- README.md +4 -6
- config.json +13 -1
README.md
CHANGED
|
@@ -12,9 +12,9 @@ https://github.com/apple/ml-mobileclip with ONNX weights to be compatible with T
|
|
| 12 |
|
| 13 |
## Usage (Transformers.js)
|
| 14 |
|
| 15 |
-
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@
|
| 16 |
```bash
|
| 17 |
-
npm i @
|
| 18 |
```
|
| 19 |
|
| 20 |
**Example:** Perform zero-shot image classification.
|
|
@@ -27,7 +27,7 @@ import {
|
|
| 27 |
RawImage,
|
| 28 |
dot,
|
| 29 |
softmax,
|
| 30 |
-
} from '@
|
| 31 |
|
| 32 |
const model_id = 'Xenova/mobileclip_blt';
|
| 33 |
|
|
@@ -37,9 +37,7 @@ const text_model = await CLIPTextModelWithProjection.from_pretrained(model_id);
|
|
| 37 |
|
| 38 |
// Load processor and vision model
|
| 39 |
const processor = await AutoProcessor.from_pretrained(model_id);
|
| 40 |
-
const vision_model = await CLIPVisionModelWithProjection.from_pretrained(model_id
|
| 41 |
-
quantized: false, // NOTE: vision model is sensitive to quantization.
|
| 42 |
-
});
|
| 43 |
|
| 44 |
// Run tokenization
|
| 45 |
const texts = ['cats', 'dogs', 'birds'];
|
|
|
|
| 12 |
|
| 13 |
## Usage (Transformers.js)
|
| 14 |
|
| 15 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
| 16 |
```bash
|
| 17 |
+
npm i @huggingface/transformers
|
| 18 |
```
|
| 19 |
|
| 20 |
**Example:** Perform zero-shot image classification.
|
|
|
|
| 27 |
RawImage,
|
| 28 |
dot,
|
| 29 |
softmax,
|
| 30 |
+
} from '@huggingface/transformers';
|
| 31 |
|
| 32 |
const model_id = 'Xenova/mobileclip_blt';
|
| 33 |
|
|
|
|
| 37 |
|
| 38 |
// Load processor and vision model
|
| 39 |
const processor = await AutoProcessor.from_pretrained(model_id);
|
| 40 |
+
const vision_model = await CLIPVisionModelWithProjection.from_pretrained(model_id);
|
|
|
|
|
|
|
| 41 |
|
| 42 |
// Run tokenization
|
| 43 |
const texts = ['cats', 'dogs', 'birds'];
|
config.json
CHANGED
|
@@ -1,3 +1,15 @@
|
|
| 1 |
{
|
| 2 |
-
"model_type": "clip"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"model_type": "clip",
|
| 3 |
+
"transformers.js_config": {
|
| 4 |
+
"dtype": {
|
| 5 |
+
"vision_model": "fp32"
|
| 6 |
+
},
|
| 7 |
+
"device_config": {
|
| 8 |
+
"webnn": {
|
| 9 |
+
"free_dimension_overrides": {
|
| 10 |
+
"batch_size": 1
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
}
|