Text Generation
Transformers
Safetensors
Vietnamese
sai
custom-code
vietnamese
causal-lm
custom_code
Instructions to use thongbuind/SAI_35M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thongbuind/SAI_35M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thongbuind/SAI_35M", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("thongbuind/SAI_35M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use thongbuind/SAI_35M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thongbuind/SAI_35M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thongbuind/SAI_35M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/thongbuind/SAI_35M
- SGLang
How to use thongbuind/SAI_35M 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 "thongbuind/SAI_35M" \ --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": "thongbuind/SAI_35M", "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 "thongbuind/SAI_35M" \ --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": "thongbuind/SAI_35M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use thongbuind/SAI_35M with Docker Model Runner:
docker model run hf.co/thongbuind/SAI_35M
| import os | |
| import shutil | |
| import sentencepiece as spm | |
| from transformers import PreTrainedTokenizer | |
| class SAITokenizer(PreTrainedTokenizer): | |
| vocab_files_names = {"vocab_file": "tokenizer.model"} | |
| model_input_names = ["input_ids", "attention_mask"] | |
| def __init__( | |
| self, | |
| vocab_file, | |
| unk_token="[UNK]", | |
| bos_token="[BOS]", | |
| eos_token="[EOS]", | |
| pad_token="[UNK]", | |
| additional_special_tokens=None, | |
| **kwargs, | |
| ): | |
| self.vocab_file = vocab_file | |
| self.sp_model = spm.SentencePieceProcessor(model_file=vocab_file) | |
| if additional_special_tokens is None: | |
| additional_special_tokens = ["<|im_start|>", "<|im_end|>"] | |
| super().__init__( | |
| unk_token=unk_token, | |
| bos_token=bos_token, | |
| eos_token=eos_token, | |
| pad_token=pad_token, | |
| additional_special_tokens=additional_special_tokens, | |
| **kwargs, | |
| ) | |
| def vocab_size(self): | |
| return self.sp_model.get_piece_size() | |
| def get_vocab(self): | |
| vocab = {self.sp_model.id_to_piece(i): i for i in range(self.vocab_size)} | |
| vocab.update(self.added_tokens_encoder) | |
| return vocab | |
| def _tokenize(self, text, **kwargs): | |
| return self.sp_model.encode(text, out_type=str) | |
| def _convert_token_to_id(self, token): | |
| return self.sp_model.piece_to_id(token) | |
| def _convert_id_to_token(self, index): | |
| return self.sp_model.id_to_piece(int(index)) | |
| def convert_tokens_to_string(self, tokens): | |
| return self.sp_model.decode(tokens) | |
| def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): | |
| result = [self.bos_token_id] + list(token_ids_0) | |
| if token_ids_1 is not None: | |
| result += list(token_ids_1) | |
| return result + [self.eos_token_id] | |
| def save_vocabulary(self, save_directory, filename_prefix=None): | |
| os.makedirs(save_directory, exist_ok=True) | |
| filename = "tokenizer.model" | |
| if filename_prefix: | |
| filename = f"{filename_prefix}-{filename}" | |
| destination = os.path.join(save_directory, filename) | |
| if os.path.abspath(self.vocab_file) != os.path.abspath(destination): | |
| shutil.copyfile(self.vocab_file, destination) | |
| return (destination,) | |