AumCoreAI commited on
Commit
be5fd29
·
verified ·
1 Parent(s): d449d43

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -25,7 +25,6 @@
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
28
  *.tflite filter=lfs diff=lfs merge=lfs -text
29
  *.tgz filter=lfs diff=lfs merge=lfs -text
30
  *.wasm filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - vision
6
+ - image-to-text
7
+ - image-captioning
8
+ - visual-question-answering
9
+ pipeline_tag: image-text-to-text
10
+ ---
11
+
12
+ # BLIP-2, OPT-2.7b, pre-trained only
13
+
14
+ BLIP-2 model, leveraging [OPT-2.7b](https://huggingface.co/facebook/opt-2.7b) (a large language model with 2.7 billion parameters).
15
+ It was introduced in the paper [BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models](https://arxiv.org/abs/2301.12597) by Li et al. and first released in [this repository](https://github.com/salesforce/LAVIS/tree/main/projects/blip2).
16
+
17
+ Disclaimer: The team releasing BLIP-2 did not write a model card for this model so this model card has been written by the Hugging Face team.
18
+
19
+ ## Model description
20
+
21
+ BLIP-2 consists of 3 models: a CLIP-like image encoder, a Querying Transformer (Q-Former) and a large language model.
22
+
23
+ The authors initialize the weights of the image encoder and large language model from pre-trained checkpoints and keep them frozen
24
+ while training the Querying Transformer, which is a BERT-like Transformer encoder that maps a set of "query tokens" to query embeddings,
25
+ which bridge the gap between the embedding space of the image encoder and the large language model.
26
+
27
+ The goal for the model is simply to predict the next text token, giving the query embeddings and the previous text.
28
+
29
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/blip2_architecture.jpg"
30
+ alt="drawing" width="600"/>
31
+
32
+ This allows the model to be used for tasks like:
33
+
34
+ - image captioning
35
+ - visual question answering (VQA)
36
+ - chat-like conversations by feeding the image and the previous conversation as prompt to the model
37
+
38
+ ## Direct Use and Downstream Use
39
+
40
+ You can use the raw model for conditional text generation given an image and optional text. See the [model hub](https://huggingface.co/models?search=Salesforce/blip) to look for
41
+ fine-tuned versions on a task that interests you.
42
+
43
+ ## Bias, Risks, Limitations, and Ethical Considerations
44
+
45
+ BLIP2-OPT uses off-the-shelf OPT as the language model. It inherits the same risks and limitations as mentioned in Meta's model card.
46
+
47
+ > Like other large language models for which the diversity (or lack thereof) of training
48
+ > data induces downstream impact on the quality of our model, OPT-175B has limitations in terms
49
+ > of bias and safety. OPT-175B can also have quality issues in terms of generation diversity and
50
+ > hallucination. In general, OPT-175B is not immune from the plethora of issues that plague modern
51
+ > large language models.
52
+ >
53
+ BLIP2 is fine-tuned on image-text datasets (e.g. [LAION](https://laion.ai/blog/laion-400-open-dataset/) ) collected from the internet. As a result the model itself is potentially vulnerable to generating equivalently inappropriate content or replicating inherent biases in the underlying data.
54
+
55
+ BLIP2 has not been tested in real world applications. It should not be directly deployed in any applications. Researchers should first carefully assess the safety and fairness of the model in relation to the specific context they’re being deployed within.
56
+
57
+ ## Ethical Considerations
58
+ This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
59
+
60
+ ### How to use
61
+
62
+ For code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/main/en/model_doc/blip-2#transformers.Blip2ForConditionalGeneration.forward.example).
63
+
64
+ ### Memory requirements
65
+
66
+ The memory requirements differ based on the precision one uses. One can use 4-bit inference using [Bitsandbytes](https://huggingface.co/blog/4bit-transformers-bitsandbytes), which greatly reduce the memory requirements.
67
+
68
+ | dtype | Largest Layer or Residual Group | Total Size | Training using Adam |
69
+ |-------------------|---------------------------------|------------|----------------------|
70
+ | float32 | 490.94 MB | 14.43 GB | 57.72 GB |
71
+ | float16/bfloat16 | 245.47 MB | 7.21 GB | 28.86 GB |
72
+ | int8 | 122.73 MB | 3.61 GB | 14.43 GB |
73
+ | int4 | 61.37 MB | 1.8 GB | 7.21 GB |
74
+
75
+ #### Running the model on CPU
76
+
77
+ <details>
78
+ <summary> Click to expand </summary>
79
+
80
+ ```python
81
+ import requests
82
+ from PIL import Image
83
+ from transformers import Blip2Processor, Blip2ForConditionalGeneration
84
+
85
+ processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
86
+ model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b")
87
+
88
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
89
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
90
+
91
+ question = "how many dogs are in the picture?"
92
+ inputs = processor(raw_image, question, return_tensors="pt")
93
+
94
+ out = model.generate(**inputs)
95
+ print(processor.decode(out[0], skip_special_tokens=True).strip())
96
+ ```
97
+ </details>
98
+
99
+ #### Running the model on GPU
100
+
101
+ ##### In full precision
102
+
103
+ <details>
104
+ <summary> Click to expand </summary>
105
+
106
+ ```python
107
+ # pip install accelerate
108
+ import requests
109
+ from PIL import Image
110
+ from transformers import Blip2Processor, Blip2ForConditionalGeneration
111
+
112
+ processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
113
+ model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", device_map="auto")
114
+
115
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
116
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
117
+
118
+ question = "how many dogs are in the picture?"
119
+ inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
120
+
121
+ out = model.generate(**inputs)
122
+ print(processor.decode(out[0], skip_special_tokens=True).strip())
123
+ ```
124
+ </details>
125
+
126
+ ##### In half precision (`float16`)
127
+
128
+ <details>
129
+ <summary> Click to expand </summary>
130
+
131
+ ```python
132
+ # pip install accelerate
133
+ import torch
134
+ import requests
135
+ from PIL import Image
136
+ from transformers import Blip2Processor, Blip2ForConditionalGeneration
137
+
138
+ processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
139
+ model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")
140
+
141
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
142
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
143
+
144
+ question = "how many dogs are in the picture?"
145
+ inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)
146
+
147
+ out = model.generate(**inputs)
148
+ print(processor.decode(out[0], skip_special_tokens=True).strip())
149
+ ```
150
+ </details>
151
+
152
+ ##### In 8-bit precision (`int8`)
153
+
154
+ <details>
155
+ <summary> Click to expand </summary>
156
+
157
+ ```python
158
+ # pip install accelerate bitsandbytes
159
+ import torch
160
+ import requests
161
+ from PIL import Image
162
+ from transformers import Blip2Processor, Blip2ForConditionalGeneration
163
+
164
+ processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
165
+ model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", load_in_8bit=True, device_map="auto")
166
+
167
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
168
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
169
+
170
+ question = "how many dogs are in the picture?"
171
+ inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)
172
+
173
+ out = model.generate(**inputs)
174
+ print(processor.decode(out[0], skip_special_tokens=True).strip())
175
+ ```
176
+ </details>
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image>": 50265
3
+ }
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Blip2ForConditionalGeneration"
4
+ ],
5
+ "image_text_hidden_size": 256,
6
+ "image_token_index": 50265,
7
+ "initializer_factor": 1.0,
8
+ "initializer_range": 0.02,
9
+ "model_type": "blip-2",
10
+ "num_query_tokens": 32,
11
+ "qformer_config": {
12
+ "classifier_dropout": null,
13
+ "model_type": "blip_2_qformer"
14
+ },
15
+ "text_config": {
16
+ "_name_or_path": "facebook/opt-2.7b",
17
+ "activation_dropout": 0.0,
18
+ "architectures": [
19
+ "OPTForCausalLM"
20
+ ],
21
+ "eos_token_id": 50118,
22
+ "ffn_dim": 10240,
23
+ "hidden_size": 2560,
24
+ "model_type": "opt",
25
+ "num_attention_heads": 32,
26
+ "num_hidden_layers": 32,
27
+ "prefix": "</s>",
28
+ "torch_dtype": "float16",
29
+ "vocab_size": 50304,
30
+ "word_embed_proj_dim": 2560
31
+ },
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.47.0.dev0",
34
+ "use_decoder_only_language_model": true,
35
+ "vision_config": {
36
+ "dropout": 0.0,
37
+ "initializer_factor": 1.0,
38
+ "model_type": "blip_2_vision_model",
39
+ "num_channels": 3,
40
+ "projection_dim": 512
41
+ }
42
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 2,
4
+ "eos_token_id": 50118,
5
+ "pad_token_id": 1,
6
+ "transformers_version": "4.47.0.dev0"
7
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b81228c9ac1b3dee1731ee71d51fe3b2c34f915019c44c25a793b51300ae24fc
3
+ size 9996328120
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:536bd73b8f1de7d94f503b23fea2eaa4f7f3ea5f74f8f874fcb21d6df1555a19
3
+ size 4982879016
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
preprocessor_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": true,
3
+ "do_normalize": true,
4
+ "do_rescale": true,
5
+ "do_resize": true,
6
+ "image_mean": [
7
+ 0.48145466,
8
+ 0.4578275,
9
+ 0.40821073
10
+ ],
11
+ "image_processor_type": "BlipImageProcessor",
12
+ "image_std": [
13
+ 0.26862954,
14
+ 0.26130258,
15
+ 0.27577711
16
+ ],
17
+ "processor_class": "Blip2Processor",
18
+ "resample": 3,
19
+ "rescale_factor": 0.00392156862745098,
20
+ "size": {
21
+ "height": 224,
22
+ "width": 224
23
+ }
24
+ }
processor_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "num_query_tokens": 32,
3
+ "processor_class": "Blip2Processor"
4
+ }
pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83f4604e9f2c81dace48cbbb245cbe9acadddce7471c17eedc10cd675bf9af62
3
+ size 9996239804
pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b224ac0c148bf3aa0a211e5d043d38918ef57c2d3b714771a7c4b124129dbd48
3
+ size 5497724774
pytorch_model.bin.index.json ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "</s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<pad>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "</s>",
25
+ "lstrip": false,
26
+ "normalized": true,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "1": {
6
+ "content": "<pad>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "2": {
14
+ "content": "</s>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "50265": {
22
+ "content": "<image>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "bos_token": "</s>",
31
+ "clean_up_tokenization_spaces": false,
32
+ "eos_token": "</s>",
33
+ "errors": "replace",
34
+ "model_max_length": 1000000000000000019884624838656,
35
+ "pad_token": "<pad>",
36
+ "processor_class": "Blip2Processor",
37
+ "tokenizer_class": "GPT2Tokenizer",
38
+ "unk_token": "</s>"
39
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff