File size: 2,285 Bytes
f616a1a
b87996d
 
 
 
f616a1a
b87996d
f616a1a
b87996d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f616a1a
 
b87996d
 
 
 
e6667fb
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
title: MiniGPT-4 WebGPU
emoji: 🖼️
colorFrom: purple
colorTo: gray
sdk: static
app_file: index.html
pinned: false
license: other
short_description: The original 2023 MiniGPT-4, on your GPU in the browser
custom_headers:
  cross-origin-embedder-policy: credentialless
  cross-origin-opener-policy: same-origin
  cross-origin-resource-policy: cross-origin
models:
  - WeReCooking/MiniGPT4-7B-WebGPU
  - Vision-CAIR/vicuna-7b
tags:
  - webgpu
  - wllama
  - onnxruntime-web
  - minigpt4
  - image-captioning
---

The original April 2023 [MiniGPT-4](https://github.com/Vision-CAIR/MiniGPT-4) (EVA ViT-G, Q-Former, one linear projection, Vicuna-7B v0) running in your browser, with nothing uploaded: the vision side as an 8-bit ONNX graph on ONNX Runtime Web, the language model as a 4-bit GGUF on wllama (llama.cpp WebAssembly + WebGPU). A browser port of [Luminia/MiniGPT-4](https://huggingface.co/spaces/Luminia/MiniGPT-4); weights in [WeReCooking/MiniGPT4-7B-WebGPU](https://huggingface.co/WeReCooking/MiniGPT4-7B-WebGPU).

llama.cpp cannot take raw embeddings, so the 32 image vectors are written into 32 reserved rows (`<0x80>`..`<0x9F>`) of the F16 token-embedding table before the model is loaded; the prompt carries those 32 token ids. A new image reloads the model from the browser cache; more questions about the same image do not.

**The Python version** (the original Gradio app on ZeroGPU, with the patched `minigpt4` package) is on the [`python` branch](https://huggingface.co/spaces/WeReCooking/MiniGPT4-WebGPU/tree/python).

If answers look wrong on your GPU, add `?vgpu=0`, `?llmgpu=0` or `?check=1` to the address (vision on CPU, language model on CPU, compare GPU/CPU image embeddings) to see which part misbehaves.

Checked in headless Chromium: image preprocessing is bit-exact with torchvision; the ONNX vision graph matches PyTorch (cosine 0.99996); the 8-bit WebGPU kernel matches the CPU one to 2.5e-7; native llama.cpp with the patched table captions the example correctly, and so does the full page on CPU; on an explicit adult test image both the native run and the page on CPU answer directly, with no refusals. **Not measured:** speed and memory on a real GPU (this sandbox has none). Vicuna v0 derives from LLaMA-1 (non-commercial research licence).