File size: 703 Bytes
1ee0570
 
 
751936e
 
f4973d4
751936e
 
6bdf6c6
 
 
 
 
 
 
751936e
f4973d4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
依赖 icetk
"""

import os
import config
from transformers import AutoTokenizer

if False:  # 有bug
    tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
else:
    os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
    CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
    TOKENIZER_DIR = os.path.join(CURRENT_DIR, "chatglm_6b")
    tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_DIR, trust_remote_code=True)

# https://huggingface.co/THUDM/chatglm-6b/blob/main/tokenization_chatglm.py#L153
tokenizer.comments = f"num_image_tokens: {tokenizer.sp_tokenizer.num_image_tokens}; num_image_tokens: {tokenizer.sp_tokenizer.num_text_tokens} "