Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model:
|
4 |
+
- mistral-community/pixtral-12b
|
5 |
+
pipeline_tag: visual-question-answering
|
6 |
+
library_name: transformers
|
7 |
+
---
|
8 |
+
|
9 |
+
Converted from [mistral-community/pixtral-12b](https://huggingface.co/mistral-community/pixtral-12b) using BitsAndBytes with NF4 (4-bit) quantization. Not using double quantization.
|
10 |
+
Requires `bitsandbytes` to load.
|
11 |
+
|
12 |
+
Example usage for image captioning:
|
13 |
+
```python
|
14 |
+
from transformers import LlavaForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
|
15 |
+
from PIL import Image
|
16 |
+
import time
|
17 |
+
|
18 |
+
# Load model
|
19 |
+
model_id = "./pixtral-12b-nf4"
|
20 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
21 |
+
model_id,
|
22 |
+
use_safetensors=True,
|
23 |
+
device_map="cuda:0"
|
24 |
+
)
|
25 |
+
# Load tokenizer
|
26 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
27 |
+
|
28 |
+
# Caption a local image
|
29 |
+
IMG_URLS = [Image.open("test.png").convert("RGB")]
|
30 |
+
PROMPT = "<s>[INST]Caption this image:\n[IMG][/INST]"
|
31 |
+
|
32 |
+
inputs = processor(images=IMG_URLS, text=PROMPT, return_tensors="pt").to("cuda")
|
33 |
+
prompt_tokens = len(inputs['input_ids'][0])
|
34 |
+
print(f"Prompt tokens: {prompt_tokens}")
|
35 |
+
|
36 |
+
t0 = time.time()
|
37 |
+
generate_ids = model.generate(**inputs, max_new_tokens=512)
|
38 |
+
t1 = time.time()
|
39 |
+
total_time = t1 - t0
|
40 |
+
generated_tokens = len(generate_ids[0]) - prompt_tokens
|
41 |
+
time_per_token = generated_tokens/total_time
|
42 |
+
print(f"Generated {generated_tokens} tokens in {total_time:.3f} s ({time_per_token:.3f} tok/s)")
|
43 |
+
|
44 |
+
output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
45 |
+
print(output)
|
46 |
+
```
|
47 |
+
|
48 |
+
On a 4090, this is getting about 10 - 12 tok/s (without flash attention) and the captions seem pretty good, though I haven't tested very many. It uses about 10 GB VRAM.
|