Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Zhengxiao Du | 02a065cf27 | |
Zhengxiao Du | e214c5b71d | |
duzx16 | d8a6cfc6cb | |
duzx16 | f6b88da8c1 | |
duzx16 | 63d66b0572 | |
duzx16 | f55a1089a2 | |
duzx16 | e02ba894cf | |
duzx16 | 6498797e79 | |
duzx16 | 1e40d965fe | |
songxxzp | 630d0efd8b | |
songxxzp | bcc35f08b4 | |
songxxzp | fe0674f86d |
|
@ -9,7 +9,7 @@ tags:
|
|||
---
|
||||
# ChatGLM-6B-INT4
|
||||
<p align="center">
|
||||
👋 Join our <a href="https://join.slack.com/t/chatglm/shared_invite/zt-1t4a8evfn-vduo2hhNcYqBUnZ71IXiqQ" target="_blank">Slack</a> and <a href="https://github.com/THUDM/ChatGLM-6B/blob/main/resources/WECHAT.md" target="_blank">WeChat</a>
|
||||
👋 Join our <a href="https://join.slack.com/t/chatglm/shared_invite/zt-1udqapmrr-ocT1DS_mxWe6dDY8ahRWzg" target="_blank">Slack</a> and <a href="https://github.com/THUDM/ChatGLM-6B/blob/main/resources/WECHAT.md" target="_blank">WeChat</a>
|
||||
</p>
|
||||
|
||||
## 介绍
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
},
|
||||
"bos_token_id": 130004,
|
||||
"eos_token_id": 130005,
|
||||
"mask_token_id": 130000,
|
||||
"gmask_token_id": 130001,
|
||||
"pad_token_id": 3,
|
||||
"hidden_size": 4096,
|
||||
"inner_hidden_size": 16384,
|
||||
"layernorm_epsilon": 1e-05,
|
||||
"mask_token_id": 130000,
|
||||
"max_sequence_length": 2048,
|
||||
"model_type": "chatglm",
|
||||
"num_attention_heads": 32,
|
||||
"num_layers": 28,
|
||||
"pad_token_id": 3,
|
||||
"position_encoding_2d": true,
|
||||
"quantization_bit": 4,
|
||||
"quantization_embeddings": false,
|
||||
|
|
|
@ -918,7 +918,7 @@ class ChatGLMModel(ChatGLMPreTrainedModel):
|
|||
elif input_ids is not None:
|
||||
batch_size, seq_length = input_ids.shape[:2]
|
||||
elif inputs_embeds is not None:
|
||||
batch_size, seq_length, _ = inputs_embeds.shape[:2]
|
||||
batch_size, seq_length = inputs_embeds.shape[:2]
|
||||
else:
|
||||
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
||||
|
||||
|
@ -972,9 +972,8 @@ class ChatGLMModel(ChatGLMPreTrainedModel):
|
|||
|
||||
if attention_mask is None:
|
||||
attention_mask = torch.zeros(1, 1, device=input_ids.device).bool()
|
||||
|
||||
else:
|
||||
attention_mask = attention_mask.to(input_ids.device)
|
||||
attention_mask = attention_mask.to(hidden_states.device)
|
||||
|
||||
for i, layer in enumerate(self.layers):
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:35828b49cf23cbae4c27788d4b04fc68c79a276300e09f14d72a49b0b738b4a9
|
||||
oid sha256:245786435bde9f4593c105ea846fa461fe42bc63c12b738d0272fcaed6276645
|
||||
size 3893083075
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -31,6 +31,9 @@ class TextTokenizer:
|
|||
def tokenize(self, text):
|
||||
return self.sp.EncodeAsPieces(text)
|
||||
|
||||
def convert_tokens_to_string(self, tokens):
|
||||
return self.sp.DecodePieces(tokens)
|
||||
|
||||
def convert_tokens_to_ids(self, tokens):
|
||||
return [self.sp.PieceToId(token) for token in tokens]
|
||||
|
||||
|
@ -111,16 +114,25 @@ class SPTokenizer:
|
|||
tokens = [x + self.num_image_tokens for x in tmp]
|
||||
return tokens if add_dummy_prefix else tokens[2:]
|
||||
|
||||
def decode(self, text_ids: List[int]) -> str:
|
||||
ids = [int(_id) - self.num_image_tokens for _id in text_ids]
|
||||
ids = [_id for _id in ids if _id >= 0]
|
||||
text = self._get_text_tokenizer().decode(ids)
|
||||
def postprocess(self, text):
|
||||
text = text.replace("<n>", "\n")
|
||||
text = text.replace(SPTokenizer.get_tab_token(), "\t")
|
||||
for i in range(2, self.max_blank_length + 1):
|
||||
text = text.replace(self.get_blank_token(i), " " * i)
|
||||
return text
|
||||
|
||||
def decode(self, text_ids: List[int]) -> str:
|
||||
ids = [int(_id) - self.num_image_tokens for _id in text_ids]
|
||||
ids = [_id for _id in ids if _id >= 0]
|
||||
text = self._get_text_tokenizer().decode(ids)
|
||||
text = self.postprocess(text)
|
||||
return text
|
||||
|
||||
def decode_tokens(self, tokens: List[str]) -> str:
|
||||
text = self._get_text_tokenizer().convert_tokens_to_string(tokens)
|
||||
text = self.postprocess(text)
|
||||
return text
|
||||
|
||||
def tokenize(
|
||||
self, text: str, linebreak=True, whitespaces=True, add_dummy_prefix=True
|
||||
) -> List[str]:
|
||||
|
@ -256,11 +268,12 @@ class ChatGLMTokenizer(PreTrainedTokenizer):
|
|||
|
||||
return seq
|
||||
|
||||
def convert_tokens_to_string(self, tokens: List[str]) -> str:
|
||||
return self.sp_tokenizer.decode_tokens(tokens)
|
||||
|
||||
def _decode(
|
||||
self,
|
||||
token_ids: Union[int, List[int]],
|
||||
skip_special_tokens: bool = False,
|
||||
clean_up_tokenization_spaces: bool = True,
|
||||
**kwargs
|
||||
) -> str:
|
||||
if isinstance(token_ids, int):
|
||||
|
@ -269,7 +282,7 @@ class ChatGLMTokenizer(PreTrainedTokenizer):
|
|||
return ""
|
||||
if self.pad_token_id in token_ids: # remove pad
|
||||
token_ids = list(filter((self.pad_token_id).__ne__, token_ids))
|
||||
return self.sp_tokenizer.decode(token_ids)
|
||||
return super()._decode(token_ids, **kwargs)
|
||||
|
||||
def _convert_token_to_id(self, token):
|
||||
""" Converts a token (str) in an id using the vocab. """
|
||||
|
|
Loading…
Reference in New Issue