kq-chen commited on
Commit
caae4ce
1 Parent(s): ad963e0

update to chat-v1.1

Browse files
config.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "_name_or_path": "cogvlm-chat",
3
  "architectures": [
4
  "CogVLMForCausalLM"
5
  ],
 
1
  {
2
+ "_name_or_path": "cogvlm-chat-v1.1",
3
  "architectures": [
4
  "CogVLMForCausalLM"
5
  ],
model-00001-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:33c8a1fac87166147265084f0105715e2c7e8200d9114c4354fd32549b0b7a3e
3
  size 4938885184
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e29f6ec471ca55789ab14947b527729b9c30313ceb1e7726590b85f9f6406cca
3
  size 4938885184
model-00002-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:be8b2647278351fad70022f1cad3ee77e3540bbaf845c7c58f4351b09ecfe6e1
3
  size 4947290688
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e82356882701b1a778408f31e676d17c2aff799c543e8596ed74bc805b4a1213
3
  size 4947290688
model-00003-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d74b96de273d26f263dd485858ad4a9488cedeb8e5e2c4b38485f504e472f1e3
3
  size 4947307592
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04096f84f42798d0c89319ff8254995a2a3512c16ec88dfd078ce421867d92ec
3
  size 4947307592
model-00004-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:41d8faae19f310bb1210dc5435adcb7ab0614500d04cdc9e3e8ed53e083449e1
3
  size 4991331080
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b42af0bb16647959b3e55def4b3c66ab8c3a25fd948a5245c81d070f2b4313d
3
  size 4991331080
model-00005-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dd848d623b8bb6493f67bf2a05fbabd4971ab6cb65d7061664c19273a5532c76
3
  size 4991331088
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38c07825790e055dd169376479994a58a4f59775ba7cf31d5ca25d8a465e7b0c
3
  size 4991331088
model-00006-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:16a0c1faf56687643e7bf10418ca64879625d6f9eccebcafecfae20da2f3f6bb
3
  size 4970162920
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d01880ca5677e69a5f8632f9dda62814f0c549b5a40d4f7e136065e5d64c1a7d
3
  size 4970162920
model-00007-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:49595dbcce29f4368f9705c6afb0acae4fe86bbb71ac0cffd123dd1daefa2f50
3
  size 4960543792
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e70b0e10d2ac8800e69e514b6a9b04ac28cd7db43985ce62daa4e0e639b4e5ba
3
  size 4960543792
model-00008-of-00008.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fde07fd1de183c38dbbb8f6265e97776361395d7a9da4342b2dea63f9aee7bb9
3
  size 532677104
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a756381ef65b92af7f1fb97da3d59cb04586080982de86d76805299898223294
3
  size 532677104
modeling_cogvlm.py CHANGED
@@ -538,25 +538,23 @@ class CogVLMModel(CogVLMPreTrainedModel):
538
  return combined_attention_mask
539
 
540
 
541
- def chat_history_to_prompt(history, query):
542
- prompt = " [INST] "
543
- for i, (old_query, response) in enumerate(history):
544
- prompt += old_query + " [/INST] " + response + " [INST] "
545
- prompt += query + " [/INST] "
546
- return prompt
547
-
 
 
548
 
549
- def base_history_to_prompt(history, query):
550
- prompt = query
 
 
551
  return prompt
552
 
553
 
554
- _history_to_prompt = {
555
- "base": base_history_to_prompt,
556
- "chat": chat_history_to_prompt
557
- }
558
-
559
-
560
  class CogVLMForCausalLM(CogVLMPreTrainedModel):
561
  _auto_class = "AutoModelForCausalLM"
562
 
@@ -744,14 +742,14 @@ class CogVLMForCausalLM(CogVLMPreTrainedModel):
744
  query: str,
745
  history: Optional[List[Tuple[str, str]]] = None,
746
  images: Optional[List["PIL.Image"]] = None,
747
- template_version: Optional[Literal["base", "chat"]] = None,
748
  ):
749
  image_size: int = self.config.vision_config['image_size']
750
  patch_size: int = self.config.vision_config['patch_size']
751
  template_version = template_version or self.config.template_version
752
  assert images is None or len(images) <= 1, f"not support multi images by now."
753
  history = history or []
754
- text = _history_to_prompt[template_version](history, query)
755
 
756
  input_ids = [tokenizer.bos_token_id]
757
  token_type_ids = [LANGUAGE_TOKEN_TYPE]
 
538
  return combined_attention_mask
539
 
540
 
541
+ def _history_to_prompt(signal_type, history, query):
542
+ if signal_type == 'base':
543
+ return query
544
+ elif signal_type == 'vqa':
545
+ answer_format = 'Short answer:'
546
+ elif signal_type == 'chat':
547
+ answer_format = 'Answer:'
548
+ else:
549
+ assert False, f"Unknown signal type {signal_type}"
550
 
551
+ prompt = ''
552
+ for i, (old_query, response) in enumerate(history):
553
+ prompt += 'Question: ' + old_query + " {} ".format(answer_format) + response + "\n"
554
+ prompt += 'Question: {} {}'.format(query, answer_format)
555
  return prompt
556
 
557
 
 
 
 
 
 
 
558
  class CogVLMForCausalLM(CogVLMPreTrainedModel):
559
  _auto_class = "AutoModelForCausalLM"
560
 
 
742
  query: str,
743
  history: Optional[List[Tuple[str, str]]] = None,
744
  images: Optional[List["PIL.Image"]] = None,
745
+ template_version: Optional[Literal["base", "chat", "vqa"]] = None,
746
  ):
747
  image_size: int = self.config.vision_config['image_size']
748
  patch_size: int = self.config.vision_config['patch_size']
749
  template_version = template_version or self.config.template_version
750
  assert images is None or len(images) <= 1, f"not support multi images by now."
751
  history = history or []
752
+ text = _history_to_prompt(template_version, history, query)
753
 
754
  input_ids = [tokenizer.bos_token_id]
755
  token_type_ids = [LANGUAGE_TOKEN_TYPE]