CoolFace
Modelpublic

hymenjj/llama-cpp-python-prebuilt

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
llama_tokenizer.cpython-311.pyc59 linesDownload Raw Back to __pycache__
1200�i$���ddlmZddlZddlmZmZmZddlZddlmZGd�dej	��Z3Gd�de4��ZGd	�d5e6��ZdS)�)�annotationsN)�List�Optional�Any)rc�\�eZdZej	ddd	���Zej		ddd���Zd7S)�BaseLlamaTokenizerT�text�bytes�add_bos�bool�special�return�	List[int]c��t�)z�Tokenize the text into tokens.8 9        Args:10            text: The utf-8 encoded string to tokenize.11            add_bos: Whether to add a beginning of sequence token.12            special: Whether to tokenize special tokens.13        ��NotImplementedError��selfr	rr
s    �D/usr/local/lib/python3.11/site-packages/llama_cpp/llama_tokenizer.py�tokenizezBaseLlamaTokenizer.tokenizes14��"�!�NF�tokens�prev_tokens�Optional[List[int]]c��t�)a
Detokenize the tokens into text.15 16        Args:17            tokens: The list of tokens to detokenize.18            prev_tokens: The list of previous tokens. Offset mapping will be performed if provided.19            special: Whether to detokenize special tokens.20        r�rrrr
s    r�21detokenizezBaseLlamaTokenizer.detokenizes22��"�!r�TT�r	r23rrr
rrr�NF�rrrrr
rrr24)�__name__�25__module__�__qualname__�abc�abstractmethodrr�rrrrso��������AE�26"�27"�28"�29"���30"�	��,0��	
"�
"�
"�
"���
"�
"�
"rrc�\�eZdZdd�Z	ddd�Z		ddd�Z	ddd�Zdd�Zed d���Z	d
S)!�LlamaTokenizer�llama�llama_cpp.Llamac��|j|_dS�N)�_model)rr*s  r�__init__zLlamaTokenizer.__init__.s���l����rTr	r31rrr
rrc�<�|j�|||���S)N�rr
)r.rrs    rrzLlamaTokenizer.tokenize1s!���{�#�#�D�'�7�#�K�K�KrNFrrrc�:�|j�||���S)N)r
)r.rrs    rrzLlamaTokenizer.detokenize6s���{�%�%�f�g�%�>�>�>r�strc�\�|�|�dd���||���S)N�utf-8�ignore��errorsr1)r�encoders    rr9zLlamaTokenizer.encode>s6���}�}��K�K���K�1�1�7�G��32�33�	34rc�V�|�|���dd���S)Nr5r6r7)r�decode)rrs  rr;zLlamaTokenizer.decodeEs'�����v�&�&�-�-�g�h�-�G�G�Gr�path�'LlamaTokenizer'c�@�|tj|d�����S)NT)�35model_path�36vocab_only)�	llama_cpp�Llama)�clsr<s  r�from_ggml_filezLlamaTokenizer.from_ggml_fileHs!���s�9�?�d�t�D�D�D�E�E�Er)r*r+rrr r!)r	r3rrr
rrr)rrrr3)r<r3rr=)37r"r#r$r/rrr9r;�classmethodrDr'rrr)r)-s�������#�#�#�#�BF�L�L�L�L�L�,0��	?�?�?�?�?�@D�38�39�40�41�42�H�H�H�H��F�F�F��[�F�F�Frr)c�H�eZdZdd�Z	ddd�Z		ddd�Zedd���Zd
S)�LlamaHFTokenizer�hf_tokenizerrc��||_dSr-)rH)rrHs  rr/zLlamaHFTokenizer.__init__Ns��(����rTr	r43rrr
rrc�d�|j�|�dd���|���S)Nr5r6r7)�add_special_tokens)rHr9r;rs    rrzLlamaHFTokenizer.tokenizeQs9��� �'�'��K�K���K�1�1�g�(�44�45�	46rNFrrrc�f�|}|�||j�||z|����dd���}|j�||����dd���}|t|��d�S|j�||����dd���S)N)�skip_special_tokensr5r6r7)rHr;r9�len)rrrr
rMr	�	prev_texts       rrzLlamaHFTokenizer.detokenizeXs���#*�k���"��$�+�+��f�$�:M�,����f�W�X�f�.�.�
��)�0�0��1D�1����f�W�X�f�.�.�
���I���(�(�)�)��$�+�+��,?�,����f�W�X�f�.�.�
/r�pretrained_model_name_or_pathr3�'LlamaHFTokenizer'c��	ddlm}n#t$rtd���wxYw|�|���}||��S)Nr)�
AutoTokenizerzsThe `transformers` library is required to use the `HFTokenizer`.You can install it with `pip install transformers`.)rP)�transformersrS�ImportError�from_pretrained)rCrPrSrHs    rrVz LlamaHFTokenizer.from_pretrainedls���	�2�2�2�2�2�2�2���	�	�	��F���
�	����47%�4�4�*G�5�48�49���s�<� � � s�	�#)rHrrrr r!)rPr3rrQ)r"r#r$r/rrrErVr'rrrGrGMs�������)�)�)�)�BF�50�51�52�53�54�,0��	/�/�/�/�/�(�!�!�!��[�!�!�!rrG)
�55__future__rr%�typingrrrrA�llama_cpp.llama_types�ABCrr)rGr'rr�<module>r[s��"�"�"�"�"�"�56575859���������������&�&�&�&�&�&�"�"�"�"�"���"�"�"�>F�F�F�F�F�'�F�F�F�@+!�+!�+!�+!�+!�)�+!�+!�+!�+!�+!r