jeiku/moondream2-onnx-bnb4
By jeiku · ↓ 7 · ♥ 1 · Updated 2024-06-24
What's in this repo
This page lists the files in jeiku/moondream2-onnx-bnb4, including decoder_model_merged_bnb4.onnx, embed_tokens_bnb4.onnx, vision_encoder_bnb4.onnx.
- 3 ONNX models (.onnx files)
- 15 files, including 9 .json, 3 .onnx, 1 .md, 1 .txt
- Last updated 2024-06-24
ONNX files
| File | Size | Download |
|---|---|---|
| onnx/decoder_model_merged_bnb4.onnx | — | Download |
| onnx/embed_tokens_bnb4.onnx | — | Download |
| onnx/vision_encoder_bnb4.onnx | — | Download |
How to use
These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.
README
library_name: transformers.js pipeline_tag: image-text-to-text license: apache-2.0
https://huggingface.co/vikhyatk/moondream2 with ONNX weights to be compatible with Transformers.js.
Usage (Transformers.js)
[!IMPORTANT] NOTE: Moondream support is experimental and requires you to install Transformers.js v3 from source.
If you haven't already, you can install the Transformers.js JavaScript library from GitHub using:
npm install xenova/transformers.js#v3
Example:
import { AutoProcessor, AutoTokenizer, Moondream1ForConditionalGeneration, RawImage } from '@xenova/transformers';
// Load processor, tokenizer and model
const model_id = 'Xenova/moondream2';
const processor = await AutoProcessor.from_pretrained(model_id);
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const model = await Moondream1ForConditionalGeneration.from_pretrained(model_id, {
dtype: {
embed_tokens: 'fp16', // or 'fp32'
vision_encoder: 'fp16', // or 'q8'
decoder_model_merged: 'q4', // or 'q4f16' or 'q8'
},
device: 'webgpu',
});
// Prepare text inputs
const prompt = 'Describe this image.';
const text = `<image>\n\nQuestion: ${prompt}\n\nAnswer:`;
const text_inputs = tokenizer(text);
// Prepare vision inputs
const url = 'https://huggingface.co/vikhyatk/moondream1/resolve/main/assets/demo-1.jpg';
const image = await RawImage.fromURL(url);
const vision_inputs = await processor(image);
// Generate response
const output = await model.generate({
...text_inputs,
...vision_inputs,
do_sample: false,
max_new_tokens: 64,
});
const decoded = tokenizer.batch_decode(output, { skip_special_tokens: false });
console.log(decoded);
// [
// '<|endoftext|><image>\n\n' +
// 'Question: Describe this image.\n\n' +
// 'Answer: A hand is holding a white book titled "The Little Book of Deep Learning" against a backdrop of a balcony with a railing and a view of a building and trees.<|endoftext|>'
// ]
We also released an online demo, which you can try yourself: https://huggingface.co/spaces/Xenova/experimental-moondream-webgpu
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using 🤗 Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).
Model info
Created: 2024-06-24
Updated: 2024-06-24
View on Hugging Face