Instructions to use yahya94812/Tiny-GPT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yahya94812/Tiny-GPT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yahya94812/Tiny-GPT", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("yahya94812/Tiny-GPT", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yahya94812/Tiny-GPT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yahya94812/Tiny-GPT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yahya94812/Tiny-GPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/yahya94812/Tiny-GPT
- SGLang
How to use yahya94812/Tiny-GPT 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 "yahya94812/Tiny-GPT" \ --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": "yahya94812/Tiny-GPT", "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 "yahya94812/Tiny-GPT" \ --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": "yahya94812/Tiny-GPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use yahya94812/Tiny-GPT with Docker Model Runner:
docker model run hf.co/yahya94812/Tiny-GPT
| import json | |
| import os | |
| from typing import List, Optional, Tuple | |
| from transformers import PreTrainedTokenizer | |
| VOCAB_FILES_NAMES = {"vocab_file": "vocab.json"} | |
| class TinyGPTTokenizer(PreTrainedTokenizer): | |
| """Character-level tokenizer: each of the 128 ASCII code points is its | |
| own token, id == ord(char) — the exact scheme used by decode()/chr(t) | |
| in the original training script.""" | |
| vocab_files_names = VOCAB_FILES_NAMES | |
| model_input_names = ["input_ids", "attention_mask"] | |
| def __init__(self, vocab_file: Optional[str] = None, **kwargs): | |
| self._vocab = {chr(i): i for i in range(128)} | |
| self._ids_to_tokens = {i: chr(i) for i in range(128)} | |
| super().__init__(**kwargs) | |
| def vocab_size(self) -> int: | |
| return len(self._vocab) | |
| def get_vocab(self): | |
| return dict(self._vocab) | |
| def _tokenize(self, text: str, **kwargs) -> List[str]: | |
| return list(text) | |
| def _convert_token_to_id(self, token: str) -> int: | |
| return self._vocab.get(token, self._vocab.get(" ")) | |
| def _convert_id_to_token(self, index: int) -> str: | |
| return self._ids_to_tokens.get(index, " ") | |
| def convert_tokens_to_string(self, tokens: List[str]) -> str: | |
| return "".join(tokens) | |
| def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]: | |
| filename = (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] | |
| vocab_path = os.path.join(save_directory, filename) | |
| with open(vocab_path, "w", encoding="utf-8") as f: | |
| json.dump(self._vocab, f, ensure_ascii=False, indent=2) | |
| return (vocab_path,) | |