Instructions to use zai-org/glm-4-9b-chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/glm-4-9b-chat with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("zai-org/glm-4-9b-chat", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
Update tokenization_chatglm.py
#7
by ksuriuri - opened
- tokenization_chatglm.py +4 -4
tokenization_chatglm.py
CHANGED
|
@@ -63,22 +63,22 @@ class ChatGLM4Tokenizer(PreTrainedTokenizer):
|
|
| 63 |
vocab.update(self.added_tokens_encoder)
|
| 64 |
return vocab
|
| 65 |
|
| 66 |
-
def convert_tokens_to_string(self, tokens: List[Union[bytes, str]]) -> str:
|
| 67 |
"""
|
| 68 |
Converts a sequence of tokens in a single string.
|
| 69 |
"""
|
| 70 |
text = ""
|
| 71 |
temp = b""
|
| 72 |
for t in tokens:
|
|
|
|
|
|
|
| 73 |
if isinstance(t, str):
|
| 74 |
if temp:
|
| 75 |
text += temp.decode("utf-8", errors="replace")
|
| 76 |
-
temp = b""
|
| 77 |
-
text += t
|
| 78 |
elif isinstance(t, bytes):
|
| 79 |
temp += t
|
| 80 |
else:
|
| 81 |
-
raise TypeError("token should only be of type
|
| 82 |
if temp:
|
| 83 |
text += temp.decode("utf-8", errors="replace")
|
| 84 |
return text
|
|
|
|
| 63 |
vocab.update(self.added_tokens_encoder)
|
| 64 |
return vocab
|
| 65 |
|
| 66 |
+
def convert_tokens_to_string(self, tokens: List[Union[bytes, str, int]]) -> str:
|
| 67 |
"""
|
| 68 |
Converts a sequence of tokens in a single string.
|
| 69 |
"""
|
| 70 |
text = ""
|
| 71 |
temp = b""
|
| 72 |
for t in tokens:
|
| 73 |
+
if isinstance(t, int):
|
| 74 |
+
t = chr(t)
|
| 75 |
if isinstance(t, str):
|
| 76 |
if temp:
|
| 77 |
text += temp.decode("utf-8", errors="replace")
|
|
|
|
|
|
|
| 78 |
elif isinstance(t, bytes):
|
| 79 |
temp += t
|
| 80 |
else:
|
| 81 |
+
raise TypeError("token should only be of type int, bytes or str")
|
| 82 |
if temp:
|
| 83 |
text += temp.decode("utf-8", errors="replace")
|
| 84 |
return text
|