Run this model with HF Jobs
Run coderian/TinyGPT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/coderian/TinyGPT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/coderian/TinyGPT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/coderian/TinyGPT. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/coderian/TinyGPT. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use coderian/TinyGPT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use coderian/TinyGPT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="coderian/TinyGPT", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("coderian/TinyGPT", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use coderian/TinyGPT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "coderian/TinyGPT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/TinyGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/coderian/TinyGPT
- SGLang
How to use coderian/TinyGPT 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 "coderian/TinyGPT" \ --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": "coderian/TinyGPT", "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 "coderian/TinyGPT" \ --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": "coderian/TinyGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use coderian/TinyGPT with Docker Model Runner:
docker model run hf.co/coderian/TinyGPT
Download models/tinygpt.py from coderian/TinyGPT: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/coderian/TinyGPT/resolve/main/models/tinygpt.py
- Command line
-
hf download hf://coderian/TinyGPT/models/tinygpt.py
-
curl -L -o tinygpt.py https://huggingface.co/coderian/TinyGPT/resolve/main/models/tinygpt.py
2.24 kB
| import torch | |
| import torch.nn as nn | |
| from transformers import PreTrainedModel, GenerationMixin | |
| from transformers.modeling_outputs import CausalLMOutput | |
| from models.config import TinyGPTConfig | |
| from models.transformer_block import TransformerBlock | |
| class TinyGPT(PreTrainedModel, GenerationMixin): | |
| config_class = TinyGPTConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.config = config | |
| self.token_embedding = nn.Embedding( | |
| config.vocab_size, | |
| config.embed_dim, | |
| ) | |
| self.position_embedding = nn.Embedding( | |
| config.max_seq_len, | |
| config.embed_dim, | |
| ) | |
| self.transformer_blocks = nn.ModuleList([ | |
| TransformerBlock( | |
| config.embed_dim | |
| ) | |
| for _ in range(config.num_layers) | |
| ]) | |
| self.ln_f = nn.LayerNorm( | |
| config.embed_dim | |
| ) | |
| self.lm_head = nn.Linear( | |
| config.embed_dim, | |
| config.vocab_size, | |
| ) | |
| self.post_init() | |
| def forward(self, input_ids, **kwargs): | |
| batch_size, seq_len = input_ids.shape | |
| positions = torch.arange( | |
| seq_len, | |
| device=input_ids.device | |
| ) | |
| token_emb = self.token_embedding( | |
| input_ids | |
| ) | |
| pos_emb = self.position_embedding( | |
| positions | |
| ) | |
| x = token_emb + pos_emb | |
| for block in self.transformer_blocks: | |
| x = block(x) | |
| x = self.ln_f(x) | |
| logits = self.lm_head(x) | |
| return CausalLMOutput(logits=logits) | |
| def prepare_inputs_for_generation(self, input_ids, **kwargs): | |
| return {"input_ids": input_ids} | |
| def _init_weights(self, module): | |
| std = 0.02 | |
| if isinstance(module, nn.Linear): | |
| module.weight.data.normal_(mean=0.0, std=std) | |
| if module.bias is not None: | |
| module.bias.data.zero_() | |
| elif isinstance(module, nn.Embedding): | |
| module.weight.data.normal_(mean=0.0, std=std) | |
| elif isinstance(module, nn.LayerNorm): | |
| module.bias.data.zero_() | |
| module.weight.data.fill_(1.0) | |
| TinyGPT.register_for_auto_class("AutoModelForCausalLM") |