MrOvkill commited on
Commit
3c0f209
·
1 Parent(s): cbb08d7

Update handler

Browse files
.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar 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
- *.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
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,71 +0,0 @@
1
- ---
2
- license: cc-by-sa-4.0
3
- language:
4
- - en
5
- tags:
6
- - Multimodal
7
- - StableLM
8
- datasets:
9
- - LDJnr/Capybara
10
- - LDJnr/LessWrong-Amplify-Instruct
11
- - LDJnr/Pure-Dove
12
- - LDJnr/Verified-Camel
13
- ---
14
-
15
- # Obsidian: Worlds smallest multi-modal LLM. First multi-modal model in size 3B
16
-
17
- ## Model Name: Obsidian-3B-V0.5
18
-
19
- Obsidian is a brand new series of Multimodal Language Models. This first project is led by Quan N. and Luigi D.(LDJ).
20
-
21
- Obsidian-3B-V0.5 is a multi-modal AI model that has vision! it's smarts are built on [Capybara-3B-V1.9](https://huggingface.co/NousResearch/Capybara-3B-V1.9) based on [StableLM-3B-4e1t](https://huggingface.co/stabilityai/stablelm-3b-4e1t). Capybara-3B-V1.9 achieves state-of-the-art performance when compared to model with similar size, even beats some 7B models.
22
-
23
- Current finetuning and inference code is available on our GitHub repo: [Here](https://github.com/NousResearch/Obsidian)
24
-
25
- ## Acknowledgement
26
-
27
- Obsidian-3B-V0.5 was developed and finetuned by [Nous Research](https://huggingface.co/NousResearch), in collaboration with [Virtual Interactive](https://huggingface.co/vilm).
28
- Special thank you to **LDJ** for the wonderful Capybara dataset, and **qnguyen3** for the model training procedure.
29
- ## Model Training
30
-
31
- Obsidian-3B-V0.5 followed the same training procedure as LLaVA 1.5
32
-
33
- ## Prompt Format
34
-
35
- The model followed ChatML format. However, with `###` as the seperator
36
-
37
- ```
38
- <|im_start|>user
39
- What is this sign about?\n<image>
40
- ###
41
- <|im_start|>assistant
42
- The sign is about bullying, and it is placed on a black background with a red background.
43
- ###
44
- ```
45
-
46
- ## Benchmarks
47
-
48
- Coming Soon!
49
-
50
-
51
- Citation:
52
-
53
- ```
54
- @article{nguyen2023Obsidian-3B,
55
- title={Obsidian-3B: First Multi-modal below 7B Parameters.},
56
- author={Nguyen, Quan and Daniele},
57
- journal={HuggingFace:https://huggingface.co/NousResearch/Obsidian-3B-V0.5},
58
- year={2023}
59
- }
60
- ```
61
-
62
- Acknowledgements:
63
-
64
- ```
65
- @article{daniele2023amplify-instruct,
66
- title={Amplify-Instruct: Synthetically Generated Diverse Multi-turn Conversations for Effecient LLM Training.},
67
- author={Daniele, Luigi and Suphavadeeprasit},
68
- journal={arXiv preprint arXiv:(comming soon)},
69
- year={2023}
70
- }
71
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "_name_or_path": "NousResearch/Obsidian-3B-V0.5",
3
- "architectures": [
4
- "LlavaStableLMEpochForCausalLM"
5
- ],
6
- "bos_token_id": 0,
7
- "eos_token_id": 0,
8
- "freeze_mm_mlp_adapter": false,
9
- "hidden_act": "silu",
10
- "hidden_size": 2560,
11
- "image_aspect_ratio": "pad",
12
- "image_grid_pinpoints": null,
13
- "initializer_range": 0.02,
14
- "intermediate_size": 6912,
15
- "max_position_embeddings": 4096,
16
- "mm_hidden_size": 1024,
17
- "mm_projector_type": "mlp2x_gelu",
18
- "mm_use_im_patch_token": false,
19
- "mm_use_im_start_end": false,
20
- "mm_vision_select_feature": "patch",
21
- "mm_vision_select_layer": -2,
22
- "mm_vision_tower": "openai/clip-vit-large-patch14-336",
23
- "model_type": "llava_stablelm_epoch",
24
- "norm_eps": 1e-05,
25
- "num_attention_heads": 32,
26
- "num_heads": 32,
27
- "num_hidden_layers": 32,
28
- "num_key_value_heads": 32,
29
- "rope_pct": 0.25,
30
- "rope_theta": 10000,
31
- "rotary_scaling_factor": 1.0,
32
- "tie_word_embeddings": false,
33
- "torch_dtype": "bfloat16",
34
- "transformers_version": "4.34.1",
35
- "tune_mm_mlp_adapter": false,
36
- "use_cache": true,
37
- "use_mm_proj": true,
38
- "vocab_size": 50304
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
generation_config.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "_from_model_config": true,
3
- "bos_token_id": 0,
4
- "eos_token_id": 0,
5
- "transformers_version": "4.34.1"
6
- }
 
 
 
 
 
 
 
handler.py CHANGED
@@ -1,11 +1,16 @@
1
  from typing import Dict, List, Any
2
- from transformers import pipeline
3
- from obsidian import Vision
4
 
5
  class EndpointHandler():
6
  def __init__(self, path="", vision_model="obsidian3b"):
7
- self.pipeline = pipeline("text-generation", model=path)
8
- self.vision = Vision(vision_model)
 
 
 
 
 
9
 
10
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
11
  """
@@ -18,23 +23,28 @@ class EndpointHandler():
18
  # get inputs
19
  inputs = data.pop("inputs", "")
20
  image = data.pop("image", None)
 
 
 
 
21
 
22
- if image:
23
  # perform image classification using Obsidian 3b vision
24
- image_features = self.vision.encode_image(image)
25
- image_embedding = self.vision.extract_feature(image_features)
26
- image_caption = self.vision.generate_caption(image_embedding)
27
 
28
  # combine text and image captions
29
- combined_captions = [inputs, image_caption]
30
 
31
  # run text classification on combined captions
32
- prediction = self.pipeline(combined_captions, temperature=0.33, num_beams=5, stop=[], do_sample=True)
33
 
34
- return prediction
 
35
 
36
- else:
37
  # run text classification on plain text input
38
- prediction = self.pipeline(inputs, temperature=0.33, num_beams=5, stop=[], do_sample=True)
39
 
40
- return prediction
 
1
  from typing import Dict, List, Any
2
+ import torch
3
+ from transformers import AutoProcessor, LlavaForConditionalGeneration
4
 
5
  class EndpointHandler():
6
  def __init__(self, path="", vision_model="obsidian3b"):
7
+ self.model = LlavaForConditionalGeneration.from_pretrained(
8
+ "NousResearch/Obsidian-3B-V0.5",
9
+ torch_dtype=torch.float16,
10
+ low_cpu_mem_usage=True,
11
+ ).to("cuda" if torch.is_cuda_available() else "cpu")
12
+ self.processor = AutoProcessor.from_pretrained("NousResearch/Obsidian-3B-V0.5")
13
+
14
 
15
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
16
  """
 
23
  # get inputs
24
  inputs = data.pop("inputs", "")
25
  image = data.pop("image", None)
26
+
27
+ inputs = self.processor(inputs, image, return_tensors="pt")
28
+ res = self.model.generate(**inputs, do_sample=False, max_new_tokens=4096)
29
+ return self.processor.decode(res[0], skip_special_tokens=True)
30
 
31
+ #if image:
32
  # perform image classification using Obsidian 3b vision
33
+ #image_features = self.vision.encode_image(image)
34
+ #image_embedding = self.vision.extract_feature(image_features)
35
+ #image_caption = self.vision.generate_caption(image_embedding)
36
 
37
  # combine text and image captions
38
+ #combined_captions = [inputs, image_caption]
39
 
40
  # run text classification on combined captions
41
+ #prediction = self.pipeline(combined_captions, temperature=0.33, num_beams=5, stop=[], do_sample=True)
42
 
43
+ #return prediction
44
+
45
 
46
+ #else:
47
  # run text classification on plain text input
48
+ # prediction = self.pipeline(inputs, temperature=0.33, num_beams=5, stop=[], do_sample=True)
49
 
50
+ # return prediction
mm_projector.bin DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:67836e202ca22f809c2a8b5117cc774e1119770e35ce37a6ed53d05e22ae0de6
3
- size 18362424
 
 
 
 
pytorch_model.bin DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:7c2a1f8f626c586ee15139590c7b63768ed3b3c756b12892be8466a2d050b3ca
3
- size 6216525942
 
 
 
 
requirements.txt DELETED
@@ -1 +0,0 @@
1
- obsidian
 
 
special_tokens_map.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "bos_token": {
3
- "content": "<|endoftext|>",
4
- "lstrip": false,
5
- "normalized": false,
6
- "rstrip": false,
7
- "single_word": false
8
- },
9
- "eos_token": {
10
- "content": "<|im_end|>",
11
- "lstrip": false,
12
- "normalized": false,
13
- "rstrip": false,
14
- "single_word": false
15
- },
16
- "pad_token": "<|endoftext|>",
17
- "unk_token": {
18
- "content": "<|endoftext|>",
19
- "lstrip": false,
20
- "normalized": false,
21
- "rstrip": false,
22
- "single_word": false
23
- }
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tokenizer.json DELETED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json DELETED
@@ -1,237 +0,0 @@
1
- {
2
- "add_prefix_space": false,
3
- "added_tokens_decoder": {
4
- "0": {
5
- "content": "<|endoftext|>",
6
- "lstrip": false,
7
- "normalized": false,
8
- "rstrip": false,
9
- "single_word": false,
10
- "special": true
11
- },
12
- "1": {
13
- "content": "<|padding|>",
14
- "lstrip": false,
15
- "normalized": false,
16
- "rstrip": false,
17
- "single_word": false,
18
- "special": true
19
- },
20
- "50254": {
21
- "content": " ",
22
- "lstrip": false,
23
- "normalized": true,
24
- "rstrip": false,
25
- "single_word": false,
26
- "special": false
27
- },
28
- "50255": {
29
- "content": " ",
30
- "lstrip": false,
31
- "normalized": true,
32
- "rstrip": false,
33
- "single_word": false,
34
- "special": false
35
- },
36
- "50256": {
37
- "content": " ",
38
- "lstrip": false,
39
- "normalized": true,
40
- "rstrip": false,
41
- "single_word": false,
42
- "special": false
43
- },
44
- "50257": {
45
- "content": " ",
46
- "lstrip": false,
47
- "normalized": true,
48
- "rstrip": false,
49
- "single_word": false,
50
- "special": false
51
- },
52
- "50258": {
53
- "content": " ",
54
- "lstrip": false,
55
- "normalized": true,
56
- "rstrip": false,
57
- "single_word": false,
58
- "special": false
59
- },
60
- "50259": {
61
- "content": " ",
62
- "lstrip": false,
63
- "normalized": true,
64
- "rstrip": false,
65
- "single_word": false,
66
- "special": false
67
- },
68
- "50260": {
69
- "content": " ",
70
- "lstrip": false,
71
- "normalized": true,
72
- "rstrip": false,
73
- "single_word": false,
74
- "special": false
75
- },
76
- "50261": {
77
- "content": " ",
78
- "lstrip": false,
79
- "normalized": true,
80
- "rstrip": false,
81
- "single_word": false,
82
- "special": false
83
- },
84
- "50262": {
85
- "content": " ",
86
- "lstrip": false,
87
- "normalized": true,
88
- "rstrip": false,
89
- "single_word": false,
90
- "special": false
91
- },
92
- "50263": {
93
- "content": " ",
94
- "lstrip": false,
95
- "normalized": true,
96
- "rstrip": false,
97
- "single_word": false,
98
- "special": false
99
- },
100
- "50264": {
101
- "content": " ",
102
- "lstrip": false,
103
- "normalized": true,
104
- "rstrip": false,
105
- "single_word": false,
106
- "special": false
107
- },
108
- "50265": {
109
- "content": " ",
110
- "lstrip": false,
111
- "normalized": true,
112
- "rstrip": false,
113
- "single_word": false,
114
- "special": false
115
- },
116
- "50266": {
117
- "content": " ",
118
- "lstrip": false,
119
- "normalized": true,
120
- "rstrip": false,
121
- "single_word": false,
122
- "special": false
123
- },
124
- "50267": {
125
- "content": " ",
126
- "lstrip": false,
127
- "normalized": true,
128
- "rstrip": false,
129
- "single_word": false,
130
- "special": false
131
- },
132
- "50268": {
133
- "content": " ",
134
- "lstrip": false,
135
- "normalized": true,
136
- "rstrip": false,
137
- "single_word": false,
138
- "special": false
139
- },
140
- "50269": {
141
- "content": " ",
142
- "lstrip": false,
143
- "normalized": true,
144
- "rstrip": false,
145
- "single_word": false,
146
- "special": false
147
- },
148
- "50270": {
149
- "content": " ",
150
- "lstrip": false,
151
- "normalized": true,
152
- "rstrip": false,
153
- "single_word": false,
154
- "special": false
155
- },
156
- "50271": {
157
- "content": " ",
158
- "lstrip": false,
159
- "normalized": true,
160
- "rstrip": false,
161
- "single_word": false,
162
- "special": false
163
- },
164
- "50272": {
165
- "content": " ",
166
- "lstrip": false,
167
- "normalized": true,
168
- "rstrip": false,
169
- "single_word": false,
170
- "special": false
171
- },
172
- "50273": {
173
- "content": " ",
174
- "lstrip": false,
175
- "normalized": true,
176
- "rstrip": false,
177
- "single_word": false,
178
- "special": false
179
- },
180
- "50274": {
181
- "content": " ",
182
- "lstrip": false,
183
- "normalized": true,
184
- "rstrip": false,
185
- "single_word": false,
186
- "special": false
187
- },
188
- "50275": {
189
- "content": " ",
190
- "lstrip": false,
191
- "normalized": true,
192
- "rstrip": false,
193
- "single_word": false,
194
- "special": false
195
- },
196
- "50276": {
197
- "content": " ",
198
- "lstrip": false,
199
- "normalized": true,
200
- "rstrip": false,
201
- "single_word": false,
202
- "special": false
203
- },
204
- "50277": {
205
- "content": "[PAD]",
206
- "lstrip": false,
207
- "normalized": false,
208
- "rstrip": false,
209
- "single_word": false,
210
- "special": true
211
- },
212
- "50278": {
213
- "content": "<|im_end|>",
214
- "lstrip": false,
215
- "normalized": false,
216
- "rstrip": false,
217
- "single_word": false,
218
- "special": true
219
- },
220
- "50279": {
221
- "content": "<|im_start|>",
222
- "lstrip": false,
223
- "normalized": false,
224
- "rstrip": false,
225
- "single_word": false,
226
- "special": false
227
- }
228
- },
229
- "bos_token": "<|endoftext|>",
230
- "clean_up_tokenization_spaces": true,
231
- "eos_token": "<|im_end|>",
232
- "model_max_length": 2048,
233
- "pad_token": "<|endoftext|>",
234
- "padding_side": "right",
235
- "tokenizer_class": "GPTNeoXTokenizer",
236
- "unk_token": "<|endoftext|>"
237
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trainer_state.json DELETED
The diff for this file is too large to render. See raw diff
 
training_args.bin DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:b4ceb1055fa28417dfe2aea3217be11add461c4ce297769ce39eb6127af791d1
3
- size 7224