Inoichan commited on
Commit
2ab3a16
1 Parent(s): a2cbfe2

fix for llama

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +44 -26
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ heron
app.py CHANGED
@@ -15,16 +15,18 @@ from transformers import (
15
  )
16
 
17
 
18
- os.system(
19
- "git clone https://github.com/turingmotors/heron.git"
20
- "&& export CUDA_HOME=/usr/local/cuda; pip install -e heron"
21
- )
 
22
 
23
  sys.path.insert(0, "./heron")
24
  from heron.models.git_llm.git_japanese_stablelm_alpha import (
25
  GitJapaneseStableLMAlphaConfig,
26
  GitJapaneseStableLMAlphaForCausalLM,
27
  )
 
28
 
29
  logger = logging.getLogger(__name__)
30
 
@@ -59,7 +61,7 @@ class KeywordsStoppingCriteria(StoppingCriteria):
59
  def preprocess(history, image):
60
  text = ""
61
  for one_history in history:
62
- text += f"###human: {one_history[0]}\n###gpt: "
63
  # do preprocessing
64
  inputs = processor(
65
  text,
@@ -82,7 +84,7 @@ def add_text(textbox, history):
82
  title_markdown = """
83
  # Heronチャットデモ
84
 
85
- - モデル: [turing-motors/heron-chat-git-ja-stablelm-base-7b-v0](https://huggingface.co/turing-motors/heron-chat-git-ja-stablelm-base-7b-v0)
86
  - 学習コード: [Heron](https://github.com/turingmotors/heron)
87
  """
88
 
@@ -117,7 +119,8 @@ def stream_bot(imagebox, history):
117
  history[-1][1] = ""
118
  for new_text in streamer:
119
  history[-1][1] += new_text
120
- history[-1][1] = history[-1][1].replace(EOS_WORDS, "")
 
121
  time.sleep(0.05)
122
  yield history
123
 
@@ -143,25 +146,45 @@ def build_demo():
143
 
144
  gr.Examples(
145
  examples=[
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  [
147
  "./images/bus_kyoto.png",
148
- "この道路を運転する時には何に気をつけるべきですか?",
149
  ],
150
  [
151
  "./images/bear.png",
152
- "この画像には何が写っていますか?",
153
  ],
154
  [
155
  "./images/water_bus.png",
156
- "画像には何が写っていますか?",
157
  ],
158
  [
159
  "./images/extreme_ironing.jpg",
160
- "この画像の面白い点は何ですか?",
161
  ],
162
  [
163
  "./images/heron.png",
164
- "この画像はどういう点が面白いですか?",
165
  ],
166
  ],
167
  inputs=[imagebox, textbox],
@@ -206,34 +229,29 @@ def build_demo():
206
 
207
 
208
  if __name__ == "__main__":
209
- EOS_WORDS = "###"
210
 
211
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
212
  max_length = 512
213
 
214
  vision_model_name = "openai/clip-vit-large-patch14-336"
215
- MODEL_NAME = "turing-motors/heron-chat-git-ja-stablelm-base-7b-v0"
216
- PROCESSOR_PATH = "turing-motors/heron-chat-git-ja-stablelm-base-7b-v0"
217
 
218
  # prepare a pretrained model
219
- git_config = GitJapaneseStableLMAlphaConfig.from_pretrained(MODEL_NAME)
220
  git_config.set_vision_configs(
221
- num_image_with_embedding=1,
222
- vision_model_name=vision_model_name,
223
  )
224
- model = GitJapaneseStableLMAlphaForCausalLM.from_pretrained(
225
  MODEL_NAME, config=git_config, torch_dtype=torch.float16
226
  )
 
227
  model.eval()
228
  model.to(device)
229
 
230
  # prepare a processor
231
- processor = AutoProcessor.from_pretrained("microsoft/git-base")
232
- processor.image_processor = CLIPImageProcessor.from_pretrained(vision_model_name)
233
- processor.tokenizer = LlamaTokenizer.from_pretrained(
234
- "novelai/nerdstash-tokenizer-v1",
235
- additional_special_tokens=["▁▁"],
236
- )
237
 
238
  demo = build_demo()
239
- demo.queue(concurrency_count=1, max_size=5, api_open=False).launch()
 
15
  )
16
 
17
 
18
+ if os.path.exists("heron") == False:
19
+ os.system(
20
+ "git clone https://github.com/turingmotors/heron.git"
21
+ "&& export CUDA_HOME=/usr/local/cuda; pip install -e heron"
22
+ )
23
 
24
  sys.path.insert(0, "./heron")
25
  from heron.models.git_llm.git_japanese_stablelm_alpha import (
26
  GitJapaneseStableLMAlphaConfig,
27
  GitJapaneseStableLMAlphaForCausalLM,
28
  )
29
+ from heron.models.git_llm.git_llama import GitLlamaConfig, GitLlamaForCausalLM
30
 
31
  logger = logging.getLogger(__name__)
32
 
 
61
  def preprocess(history, image):
62
  text = ""
63
  for one_history in history:
64
+ text += f"##human: {one_history[0]}\n##gpt: "
65
  # do preprocessing
66
  inputs = processor(
67
  text,
 
84
  title_markdown = """
85
  # Heronチャットデモ
86
 
87
+ - モデル: [TBD](TBD)
88
  - 学習コード: [Heron](https://github.com/turingmotors/heron)
89
  """
90
 
 
119
  history[-1][1] = ""
120
  for new_text in streamer:
121
  history[-1][1] += new_text
122
+ while history[-1][1].endswith("#"):
123
+ history[-1][1] = history[-1][1][:-1]
124
  time.sleep(0.05)
125
  yield history
126
 
 
146
 
147
  gr.Examples(
148
  examples=[
149
+ # [
150
+ # "./images/bus_kyoto.png",
151
+ # "この道路を運転する時には何に気をつけるべきですか?",
152
+ # ],
153
+ # [
154
+ # "./images/bear.png",
155
+ # "この画像には何が写っていますか?",
156
+ # ],
157
+ # [
158
+ # "./images/water_bus.png",
159
+ # "画像には何が写っていますか?",
160
+ # ],
161
+ # [
162
+ # "./images/extreme_ironing.jpg",
163
+ # "この画像の面白い点は何ですか?",
164
+ # ],
165
+ # [
166
+ # "./images/heron.png",
167
+ # "この画像はどういう点が面白いですか?",
168
+ # ],
169
  [
170
  "./images/bus_kyoto.png",
171
+ "What should you be careful of when driving on this road?",
172
  ],
173
  [
174
  "./images/bear.png",
175
+ "What is shown in this image?",
176
  ],
177
  [
178
  "./images/water_bus.png",
179
+ "What is depicted in the picture?",
180
  ],
181
  [
182
  "./images/extreme_ironing.jpg",
183
+ "What is the unusual aspect of this image?",
184
  ],
185
  [
186
  "./images/heron.png",
187
+ "What is intriguing about this picture?",
188
  ],
189
  ],
190
  inputs=[imagebox, textbox],
 
229
 
230
 
231
  if __name__ == "__main__":
232
+ EOS_WORDS = "##"
233
 
234
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
235
  max_length = 512
236
 
237
  vision_model_name = "openai/clip-vit-large-patch14-336"
238
+ MODEL_NAME = "turing-motors/inoichi-exp176-llama2"
239
+ PROCESSOR_PATH = "turing-motors/inoichi-exp175-llama2"
240
 
241
  # prepare a pretrained model
242
+ git_config = GitLlamaConfig.from_pretrained(MODEL_NAME)
243
  git_config.set_vision_configs(
244
+ num_image_with_embedding=1, vision_model_name=vision_model_name
 
245
  )
246
+ model = GitLlamaForCausalLM.from_pretrained(
247
  MODEL_NAME, config=git_config, torch_dtype=torch.float16
248
  )
249
+
250
  model.eval()
251
  model.to(device)
252
 
253
  # prepare a processor
254
+ processor = AutoProcessor.from_pretrained(PROCESSOR_PATH)
 
 
 
 
 
255
 
256
  demo = build_demo()
257
+ demo.queue(concurrency_count=1, max_size=5, api_open=False).launch(share=True)