qnguyen3 commited on
Commit
2e84f1d
1 Parent(s): 5217ab3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -0
README.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - llava
6
+ - multimodal
7
+ - qwen
8
+ license: apache-2.0
9
+ ---
10
+ # nanoLLaVA - Sub 1B Vision-Language Model
11
+
12
+ <p align="center">
13
+ <img src="https://i.postimg.cc/d15k3YNG/nanollava.webp" alt="Logo" width="350">
14
+ </p>
15
+
16
+ ## Description
17
+ nanoLLaVA-1.5 is a "small but mighty" 1B vision-language model designed to run efficiently on edge devices. This is an update from the v1.0 version [qnguyen3/nanoLLaVA](https://huggingface.co/qnguyen3/nanoLLaVA)
18
+ - **Base LLM**: [Quyen-SE-v0.1](https://huggingface.co/vilm/Quyen-SE-v0.1) (Qwen1.5-0.5B)
19
+ - **Vision Encoder**: [google/siglip-so400m-patch14-384](https://huggingface.co/google/siglip-so400m-patch14-384)
20
+
21
+ | Model | **VQA v2** | **TextVQA** | **ScienceQA** | **POPE** | **MMMU (Test)** | **MMMU (Eval)** | **GQA** | **MM-VET** |
22
+ |---------|--------|---------|-----------|------|-------------|-------------|------|--------|
23
+ | nanoLLavA-1.0 | 70.84 | 46.71 | 58.97 | 84.1 | 28.6 | 30.4 | 54.79| 23.9 |
24
+ | nanoLLavA-1.5 | TBD | TBD | TBD | TBD | TBD | TBD | TBD| TBD |
25
+
26
+ ## Training Data
27
+ Training Data will be released later as I am still writing a paper on this. Expect the final final to be much more powerful than the current one.
28
+
29
+ ## Finetuning Code
30
+ Coming Soon!!!
31
+
32
+ ## Usage
33
+ You can use with `transformers` with the following script:
34
+
35
+ ```bash
36
+ pip install -U transformers accelerate flash_attn
37
+ ```
38
+
39
+ ```python
40
+ import torch
41
+ import transformers
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer
43
+ from PIL import Image
44
+ import warnings
45
+
46
+ # disable some warnings
47
+ transformers.logging.set_verbosity_error()
48
+ transformers.logging.disable_progress_bar()
49
+ warnings.filterwarnings('ignore')
50
+
51
+ # set device
52
+ torch.set_default_device('cuda') # or 'cpu'
53
+
54
+ model_name = 'qnguyen3/nanoLLaVA-1.5'
55
+
56
+ # create model
57
+ model = AutoModelForCausalLM.from_pretrained(
58
+ model_name,
59
+ torch_dtype=torch.float16,
60
+ device_map='auto',
61
+ trust_remote_code=True)
62
+ tokenizer = AutoTokenizer.from_pretrained(
63
+ model_name,
64
+ trust_remote_code=True)
65
+
66
+ # text prompt
67
+ prompt = 'Describe this image in detail'
68
+
69
+ messages = [
70
+ {"role": "user", "content": f'<image>\n{prompt}'}
71
+ ]
72
+ text = tokenizer.apply_chat_template(
73
+ messages,
74
+ tokenize=False,
75
+ add_generation_prompt=True
76
+ )
77
+
78
+ print(text)
79
+
80
+ text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
81
+ input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
82
+
83
+ # image, sample images can be found in images folder
84
+ image = Image.open('/path/to/image.png')
85
+ image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
86
+
87
+ # generate
88
+ output_ids = model.generate(
89
+ input_ids,
90
+ images=image_tensor,
91
+ max_new_tokens=2048,
92
+ use_cache=True)[0]
93
+
94
+ print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
95
+ ```
96
+
97
+ ## Prompt Format
98
+ The model follow the ChatML standard, however, without `\n` at the end of `<|im_end|>`:
99
+ ```
100
+ <|im_start|>system
101
+ Answer the question<|im_end|><|im_start|>user
102
+ <image>
103
+ What is the picture about?<|im_end|><|im_start|>assistant
104
+ ```
105
+
106
+ ---
107
+ | Image | Example |
108
+ |--------------------------------------|---------------------------------------------------------------------------------------------|
109
+ | ![small](example_1.png) | **What is the text saying?** <br> "Small but mighty". <br>**How does the text correlate to the context of the image?** <br> The text seems to be a playful or humorous representation of a small but mighty figure, possibly a mouse or a mouse toy, holding a weightlifting bar. |
110
+ ---