Text Generation
Transformers
Safetensors
English
tinygpt2
causal-lm
instruction-tuned
sft
rope
grouped-query-attention
rms-norm
custom_code
Instructions to use NotShrirang/tinygpt2-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NotShrirang/tinygpt2-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NotShrirang/tinygpt2-it", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("NotShrirang/tinygpt2-it", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use NotShrirang/tinygpt2-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NotShrirang/tinygpt2-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NotShrirang/tinygpt2-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/NotShrirang/tinygpt2-it
- SGLang
How to use NotShrirang/tinygpt2-it 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 "NotShrirang/tinygpt2-it" \ --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": "NotShrirang/tinygpt2-it", "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 "NotShrirang/tinygpt2-it" \ --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": "NotShrirang/tinygpt2-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use NotShrirang/tinygpt2-it with Docker Model Runner:
docker model run hf.co/NotShrirang/tinygpt2-it
File size: 5,715 Bytes
9fde7d2 00fece7 9fde7d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | ---
language:
- en
license: gpl-3.0
library_name: transformers
tags:
- text-generation
- tinygpt2
- causal-lm
- instruction-tuned
- sft
- rope
- grouped-query-attention
- rms-norm
datasets:
- tatsu-lab/alpaca
- Skylion007/openwebtext
pipeline_tag: text-generation
model-index:
- name: TinyGPT2-IT
results: []
---
<div align="center">
# TinyGPT2-IT
### A 95M parameter instruction-tuned language model trained from scratch on a single consumer GPU
[](https://github.com/NotShrirang/tinygpt)
[](https://tinygpt.streamlit.app/)
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
</div>
---
## Overview
**TinyGPT2-IT** is an instruction-tuned variant of [TinyGPT2](https://github.com/NotShrirang/tinygpt) β a modern GPT architecture built from scratch using PyTorch. The base model was pretrained on ~6.7B tokens from OpenWebText, then supervised fine-tuned (SFT) on Stanford Alpaca's 52K instruction-response pairs.
The entire pipeline β pretraining, fine-tuning, and inference β runs on a **single NVIDIA RTX 3070 Ti (8 GB VRAM)**.
> This model uses a custom architecture and requires `trust_remote_code=True`.
---
## Architecture
| Component | Detail |
|---|---|
| **Parameters** | ~95M |
| **Layers** | 12 transformer blocks |
| **Attention** | Grouped Query Attention (12 query heads, 4 KV groups) |
| **Embedding dim** | 768 |
| **FFN hidden dim** | 2048 |
| **Position encoding** | Rotary Position Embeddings (RoPE) |
| **Normalization** | RMSNorm |
| **Context window** | 512 tokens |
| **Vocabulary** | 50,304 (GPT-2 tiktoken + PAD token) |
| **Weight tying** | Token embedding β LM head |
| **KV Cache** | Supported for efficient generation |
---
## Training
### Stage 1 β Pretraining
| | |
|---|---|
| **Dataset** | OpenWebText (~6.7B tokens) |
| **Optimizer** | AdamW (fused) |
| **Effective batch** | 262K tokens/step |
| **Precision** | bfloat16 + `torch.compile` |
| **Hardware** | NVIDIA RTX 3070 Ti (8 GB) |
### Stage 2 β Supervised Fine-Tuning (SFT)
| | |
|---|---|
| **Dataset** | Stanford Alpaca (52K instructions) |
| **Epochs** | 3 |
| **Loss masking** | Response-only (instruction tokens are masked) |
| **Final train loss** | 1.91 |
| **Final val loss** | 1.98 |
| **Final val perplexity** | 7.26 |
| **Tokens processed** | ~72M |
| **Prompt format** | `### Instruction: ... ### Response: ...` |
---
## Usage
### Quick Start
```python
from transformers import AutoModelForCausalLM
import tiktoken
import torch
# Load model
model = AutoModelForCausalLM.from_pretrained(
"NotShrirang/tinygpt2-it",
trust_remote_code=True,
)
model.eval()
# Tokenize
enc = tiktoken.get_encoding("gpt2")
prompt = "### Instruction:\nWhat is the capital of France?\n\n### Response:\n"
input_ids = torch.tensor([enc.encode(prompt)])
# Generate
with torch.no_grad():
output = model.generate(input_ids, max_new_tokens=128, do_sample=True, temperature=0.7, top_k=40)
print(enc.decode(output[0].tolist()))
```
### Prompt Format
This model expects instructions in the following template:
```
### Instruction:
{your instruction here}
### Response:
```
For instructions with additional context:
```
### Instruction:
{your instruction here}
### Input:
{additional context}
### Response:
```
---
## Example Outputs
**Factual Q&A**
```
>>> What is the capital of France?
The capital of France is Paris.
```
**Explanation**
```
>>> Explain what machine learning is in simple terms.
Machine learning is a branch of computer science that focuses on using algorithms to
identify patterns in data. These algorithms are used to analyze large amounts of data
and make predictions about future trends.
```
**Creative**
```
>>> Write a motivational quote.
"The only way to make a difference is to be bold and courageous."
```
---
## Limitations
- **Small model** β 95M parameters is far below production LLMs; expect factual errors, repetition, and limited reasoning.
- **Short context** β 512 token window limits the length of conversations and documents.
- **Training data** β pretrained on web text and fine-tuned on synthetic Alpaca data, which may contain biases or inaccuracies.
- **Not safety-aligned** β no RLHF/DPO applied to this checkpoint; the model may produce harmful or inappropriate content.
---
## Model Family
| Model | Params | Description | Link |
|---|---|---|---|
| TinyGPT | 51M | Standard GPT, TinyStories | [GitHub](https://github.com/NotShrirang/tinygpt) |
| TinyGPT-MoE | 85M | Mixture of Experts, TinyStories | [GitHub](https://github.com/NotShrirang/tinygpt) |
| Wikipedia-MoE | 135M | 8-expert MoE, Wikipedia/C4 | [GitHub](https://github.com/NotShrirang/tinygpt) |
| TinyGPT2 | 95M | RoPE + GQA + RMSNorm, OpenWebText | [GitHub](https://github.com/NotShrirang/tinygpt) |
| TinyGPT2.1 | 183M | Scaled TinyGPT2, FineWeb-Edu | [GitHub](https://github.com/NotShrirang/tinygpt) |
| **TinyGPT2-IT** | **95M** | **Instruction-tuned (this model)** | **You are here** |
| TinyGPT2-DPO | 95M | DPO-aligned with Anthropic HH-RLHF | [GitHub](https://github.com/NotShrirang/tinygpt) |
---
## Citation
```bibtex
@misc{tinygpt2-it,
author = {Shrirang Mahajan},
title = {TinyGPT2-IT: Instruction-Tuned 95M Parameter Language Model},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/NotShrirang/tinygpt2-it}
}
```
---
## License
This model is released under the [GPL-3.0 License](https://www.gnu.org/licenses/gpl-3.0.en.html).
|