Instructions to use Tele-AI/TeleChat-12B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Tele-AI/TeleChat-12B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Tele-AI/TeleChat-12B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Tele-AI/TeleChat-12B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Tele-AI/TeleChat-12B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Tele-AI/TeleChat-12B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Tele-AI/TeleChat-12B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Tele-AI/TeleChat-12B
- SGLang
How to use Tele-AI/TeleChat-12B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Tele-AI/TeleChat-12B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Tele-AI/TeleChat-12B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Tele-AI/TeleChat-12B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Tele-AI/TeleChat-12B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Tele-AI/TeleChat-12B with Docker Model Runner:
docker model run hf.co/Tele-AI/TeleChat-12B
Upload 15 files
Browse filesFiles changed (15)
- pytorch_model_00031-of-00041.binAdded+3
- pytorch_model_00032-of-00041.binAdded+3
- pytorch_model_00033-of-00041.binAdded+3
- pytorch_model_00034-of-00041.binAdded+3
- pytorch_model_00035-of-00041.binAdded+3
- pytorch_model_00036-of-00041.binAdded+3
- pytorch_model_00037-of-00041.binAdded+3
- pytorch_model_00038-of-00041.binAdded+3
- pytorch_model_00039-of-00041.binAdded+3
- pytorch_model_00040-of-00041.binAdded+3
- pytorch_model_00041-of-00041.binAdded+3
- specail_tokens_map.jsonAdded+30
- tokenization_telechat3.pyAdded+220
- tokenizer.modelAdded+3
- tokenizer_config.jsonAdded+40
123version https://git-lfs.github.com/spec/v1oid sha256:92436757048a6d6dad19431865ab1597f9c30d3a806d18dc3fb00468a81a7f1csize 587247299123version https://git-lfs.github.com/spec/v1oid sha256:a395c12c88298fa24ee6610809117911051127916fda147a6b678a911731d1f1size 587247299123version https://git-lfs.github.com/spec/v1oid sha256:56739da83ad5cdda57f44ee1b669f10b8e71549dfde3d1c5cd0682afcf597cc5size 587247299123version https://git-lfs.github.com/spec/v1oid sha256:00c8397f743583acffb8a0ec70b3a5d9bac4d4a3fa265865980ca456d34c6aefsize 587247299123version https://git-lfs.github.com/spec/v1oid sha256:2ea443fddb352d32ae71a7b5a88cc9a240ceb8f0dd7672bc980bc178a2c6cf70size 587247299123version https://git-lfs.github.com/spec/v1oid sha256:edd6635bd3e038bd873872e999bb17ddba75cb95a43ba3db68be653aa28d070esize 587247299123version https://git-lfs.github.com/spec/v1oid sha256:63428bfc0ded103bc539dc679191d7e25c3177eeba372801a49b3cd79f567432size 587247299123version https://git-lfs.github.com/spec/v1oid sha256:1af4b04266685de9125fa99c1f0c887382bc8e0ac29c91a35e274000eb3f1d4esize 587247299123version https://git-lfs.github.com/spec/v1oid sha256:c161cefe053ad4ddbb29b82ff854c6828a1dbc70bf1e0a9ded2f302581a01ecbsize 587247299123version https://git-lfs.github.com/spec/v1oid sha256:8bc2f8aca31304faa3fb74e9e9e419798b8d7b315e7a6fee654b7797485adf48size 11178123version https://git-lfs.github.com/spec/v1oid sha256:1aebce568567d36284ee6b3dec3bc763aadd94f6a64cb5942c3d0006845c2dd4size 1228800938123456789101112131415161718192021222324252627282930{ "bos_token": { "content": "<_start>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "eos_token": { "content": "<_end>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "pad_token": { "content": "<_pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "unk_token": { "content": "<_unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220import osfrom shutil import copyfilefrom typing import Any, Dict, List, Optional, Tupleimport sentencepiece as spmfrom transformers.tokenization_utils import AddedToken, PreTrainedTokenizerfrom transformers.utils import logging
logger = logging.get_logger(__name__)
VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
# TODO: when we get download url from huggingface, refresh the mapPRETRAINED_VOCAB_FILES_MAP = { "vocab_file": {}, "tokenizer_file": {},}
class TelechatTokenizer(PreTrainedTokenizer):
vocab_files_names = VOCAB_FILES_NAMES pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP model_input_names = ["input_ids", "attention_mask"]
def __init__( self, vocab_file, unk_token="<unk>", bos_token="<_start>", eos_token="<_end>", pad_token="<_pad>", sp_model_kwargs: Optional[Dict[str, Any]] = None, add_bos_token=True, add_eos_token=False, clean_up_tokenization_spaces=False, **kwargs, ): self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) self.sp_model.Load(vocab_file) super().__init__( bos_token=bos_token, eos_token=eos_token, unk_token=unk_token, pad_token=pad_token, add_bos_token=add_bos_token, add_eos_token=add_eos_token, sp_model_kwargs=self.sp_model_kwargs, clean_up_tokenization_spaces=clean_up_tokenization_spaces, **kwargs, ) self.vocab_file = vocab_file self.add_bos_token = add_bos_token self.add_eos_token = add_eos_token
def __getstate__(self): state = self.__dict__.copy() state["sp_model"] = None return state
def __setstate__(self, d): self.__dict__ = d self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) self.sp_model.Load(self.vocab_file)
@property def vocab_size(self): """Returns vocab size""" return self.sp_model.get_piece_size()
def get_vocab(self): """Returns vocab as a dict""" vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)} vocab.update(self.added_tokens_encoder) return vocab
def _tokenize(self, text): """Returns a tokenized string.""" return self.sp_model.encode(text, out_type=str)
def _convert_token_to_id(self, token): """Converts a token (str) in an id using the vocab.""" return self.sp_model.piece_to_id(token)
def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" token = self.sp_model.IdToPiece(index) return token
def convert_tokens_to_string(self, tokens): """Converts a sequence of tokens (string) in a single string.""" current_sub_tokens = [] out_string = "" prev_is_special = False for i, token in enumerate(tokens): # make sure that special tokens are not decoded using sentencepiece model if token in self.all_special_tokens: if not prev_is_special and i != 0: out_string += " " out_string += self.sp_model.decode(current_sub_tokens) + token prev_is_special = True current_sub_tokens = [] else: current_sub_tokens.append(token) prev_is_special = False out_string += self.sp_model.decode(current_sub_tokens) return out_string
def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]: """ Save the vocabulary and special tokens file to a directory.
Args: save_directory (`str`): The directory in which to save the vocabulary.
Returns: `Tuple(str)`: Paths to the files saved. """ if not os.path.isdir(save_directory): logger.error(f"Vocabulary path ({save_directory}) should be a directory") return out_vocab_file = os.path.join( save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] )
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file): copyfile(self.vocab_file, out_vocab_file) elif not os.path.isfile(self.vocab_file): with open(out_vocab_file, "wb") as fi: content_spiece_model = self.sp_model.serialized_model_proto() fi.write(content_spiece_model)
return (out_vocab_file,)
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): bos_token_id = [self.bos_token_id] if self.add_bos_token else [] eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = bos_token_id + token_ids_0 + eos_token_id
if token_ids_1 is not None: output = output + bos_token_id + token_ids_1 + eos_token_id
return output
def get_special_tokens_mask( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False ) -> List[int]: """ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer `prepare_for_model` method.
Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs. already_has_special_tokens (`bool`, *optional*, defaults to `False`): Whether or not the token list is already formatted with special tokens for the model.
Returns: `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token. """ if already_has_special_tokens: return super().get_special_tokens_mask( token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True )
bos_token_id = [1] if self.add_bos_token else [] eos_token_id = [1] if self.add_eos_token else []
if token_ids_1 is None: return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id return ( bos_token_id + ([0] * len(token_ids_0)) + eos_token_id + bos_token_id + ([0] * len(token_ids_1)) + eos_token_id )
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT sequence pair mask has the following format:
``` 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | first sequence | second sequence | ```
if token_ids_1 is None, only returns the first portion of the mask (0s).
Args: token_ids_0 (`List[int]`): List of ids. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs.
Returns: `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s). """ bos_token_id = [self.bos_token_id] if self.add_bos_token else [] eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
if token_ids_1 is not None: output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
return output123version https://git-lfs.github.com/spec/v1oid sha256:b2c86d881f9a94b1c50bf25f8f987accea9ec2a1be74529f0240d8e13e66aa3dsize 197878112345678910111213141516171819202122232425262728293031323334353637383940{ "name_or_path": "ChinaTelecom/telechat3-7b", "tokenizer_class": "TelechatTokenizer", "auto_map": { "AutoTokenizer": [ "tokenization_telechat3.TelechatTokenizer", null ] }, "add_bos_token": false, "add_eos_token": false, "use_fast": false, "clean_up_tokenization_spaces": false, "eos_token": { "__type": "AddedToken", "content": "<_start>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": true }, "model_max_length": 100000000, "sp_model_kwargs": {}, "pad_token": { "__type": "AddedToken", "content": "<_pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": true }, "unk_token": { "__type": "AddedToken", "content": "<_end>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": true }}pytorch_model_00031-of-00041.binAdded+3
pytorch_model_00032-of-00041.binAdded+3
pytorch_model_00033-of-00041.binAdded+3
pytorch_model_00034-of-00041.binAdded+3
pytorch_model_00035-of-00041.binAdded+3
pytorch_model_00036-of-00041.binAdded+3
pytorch_model_00037-of-00041.binAdded+3
pytorch_model_00038-of-00041.binAdded+3
pytorch_model_00039-of-00041.binAdded+3
pytorch_model_00040-of-00041.binAdded+3
pytorch_model_00041-of-00041.binAdded+3
specail_tokens_map.jsonAdded+30
tokenization_telechat3.pyAdded+220
tokenizer.modelAdded+3
tokenizer_config.jsonAdded+40