Instructions to use alainbrown/tiny-gpt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alainbrown/tiny-gpt with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="alainbrown/tiny-gpt", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("alainbrown/tiny-gpt", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use alainbrown/tiny-gpt with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "alainbrown/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": "alainbrown/tiny-gpt", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/alainbrown/tiny-gpt
- SGLang
How to use alainbrown/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 "alainbrown/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": "alainbrown/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 "alainbrown/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": "alainbrown/tiny-gpt", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use alainbrown/tiny-gpt with Docker Model Runner:
docker model run hf.co/alainbrown/tiny-gpt
| import torch.nn.functional as F | |
| from transformers import PreTrainedModel | |
| from transformers.generation import GenerationMixin | |
| from transformers.modeling_outputs import CausalLMOutput | |
| from .configuration_tiny_gpt import TinyGPTConfig | |
| from .model import GPTModel | |
| class TinyGPTForCausalLM(PreTrainedModel, GenerationMixin): | |
| config_class = TinyGPTConfig | |
| main_input_name = "input_ids" | |
| _tied_weights_keys = {"core_model.linear.weight": "core_model.token_embedding.weight"} | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.core_model = GPTModel( | |
| context_size=config.context_size, | |
| vocab_size=config.vocab_size, | |
| d_model=config.d_model, | |
| n_layers=config.n_layers, | |
| n_heads=config.n_heads, | |
| dropout=config.dropout, | |
| ) | |
| self.post_init() | |
| def get_input_embeddings(self): | |
| return self.core_model.token_embedding | |
| def set_input_embeddings(self, value): | |
| self.core_model.token_embedding = value | |
| def get_output_embeddings(self): | |
| return self.core_model.linear | |
| def set_output_embeddings(self, new_embeddings): | |
| self.core_model.linear = new_embeddings | |
| def forward(self, input_ids=None, labels=None, **kwargs): | |
| if input_ids is None: | |
| raise ValueError("input_ids must be provided") | |
| logits = self.core_model(input_ids) | |
| loss = None | |
| if labels is not None: | |
| shift_logits = logits[..., :-1, :].contiguous() | |
| shift_labels = labels[..., 1:].contiguous() | |
| loss = F.cross_entropy( | |
| shift_logits.view(-1, shift_logits.size(-1)), | |
| shift_labels.view(-1), | |
| ) | |
| return CausalLMOutput(loss=loss, logits=logits) | |