Text Generation
Transformers
Safetensors
thox_microprocessor
thox
tiny-language-model
edge-ai
custom-code
custom_code
Instructions to use Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories
- SGLang
How to use Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories 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 "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories" \ --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": "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories", "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 "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories" \ --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": "Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories with Docker Model Runner:
docker model run hf.co/Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories
Download tokenization_thox_microprocessor.py from Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories/resolve/main/tokenization_thox_microprocessor.py
- Command line
-
hf download hf://Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories/tokenization_thox_microprocessor.py
-
curl -L -o tokenization_thox_microprocessor.py https://huggingface.co/Thox-ai/ThoxMicroprocessor-8M-Base-TinyStories/resolve/main/tokenization_thox_microprocessor.py
2.15 kB
| from __future__ import annotations | |
| import os | |
| import shutil | |
| from typing import Dict, List, Optional, Tuple | |
| import sentencepiece as spm | |
| from transformers import PreTrainedTokenizer | |
| VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"} | |
| class ThoxMicroprocessorTokenizer(PreTrainedTokenizer): | |
| vocab_files_names = VOCAB_FILES_NAMES | |
| model_input_names = ["input_ids", "attention_mask"] | |
| def __init__( | |
| self, | |
| vocab_file: str, | |
| unk_token: str = "<unk>", | |
| bos_token: str = "<s>", | |
| eos_token: str = "</s>", | |
| pad_token: str = "<pad>", | |
| **kwargs, | |
| ) -> None: | |
| self.vocab_file = vocab_file | |
| self.sp_model = spm.SentencePieceProcessor(model_file=vocab_file) | |
| super().__init__( | |
| unk_token=unk_token, | |
| bos_token=bos_token, | |
| eos_token=eos_token, | |
| pad_token=pad_token, | |
| **kwargs, | |
| ) | |
| def vocab_size(self) -> int: | |
| return int(self.sp_model.vocab_size()) | |
| def get_vocab(self) -> Dict[str, int]: | |
| 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: str) -> List[str]: | |
| return list(self.sp_model.encode(text, out_type=str)) | |
| def _convert_token_to_id(self, token: str) -> int: | |
| return int(self.sp_model.piece_to_id(token)) | |
| def _convert_id_to_token(self, index: int) -> str: | |
| return str(self.sp_model.id_to_piece(int(index))) | |
| def convert_tokens_to_string(self, tokens: List[str]) -> str: | |
| return self.sp_model.decode(tokens) | |
| def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]: | |
| if not os.path.isdir(save_directory): | |
| os.makedirs(save_directory, exist_ok=True) | |
| name = (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] | |
| out = os.path.join(save_directory, name) | |
| if os.path.abspath(self.vocab_file) != os.path.abspath(out): | |
| shutil.copyfile(self.vocab_file, out) | |
| return (out,) | |