Text Generation
Transformers
Safetensors
English
llama
feature-extraction
tiny
slm
small-language-model
sub-1m
from-scratch
gqa
custom_code
text-generation-inference
Instructions to use Compactbot/tinystories-40m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Compactbot/tinystories-40m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Compactbot/tinystories-40m", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("Compactbot/tinystories-40m", trust_remote_code=True) model = AutoModel.from_pretrained("Compactbot/tinystories-40m", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Compactbot/tinystories-40m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Compactbot/tinystories-40m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Compactbot/tinystories-40m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Compactbot/tinystories-40m
- SGLang
How to use Compactbot/tinystories-40m 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 "Compactbot/tinystories-40m" \ --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": "Compactbot/tinystories-40m", "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 "Compactbot/tinystories-40m" \ --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": "Compactbot/tinystories-40m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Compactbot/tinystories-40m with Docker Model Runner:
docker model run hf.co/Compactbot/tinystories-40m
fix(generate): only feed the new token to forward() after the first step The loop was passing the full growing input_ids to forward() every step while also maintaining a KV cache, so at step i it reprocessed all i tokens on top of a cache that already held them — O(n^2) memory in the number of generated tokens. Short generations that hit EOS early survived; anything longer OOM'd (25.8 GiB allocated for a 158 MB model). Pass only ids[:, -1:] after the first step; the RoPE positions already account for the cache length via `start`. Verified: model.generate() now runs to full length (120+ tokens) with no OOM.
#1
by Compactbot - opened
- modeling_tinystories.py +2 -1
modeling_tinystories.py
CHANGED
|
@@ -167,7 +167,8 @@ class TinyStoriesGPT(PreTrainedModel):
|
|
| 167 |
ids = input_ids
|
| 168 |
past = None
|
| 169 |
for _ in range(max_new_tokens):
|
| 170 |
-
|
|
|
|
| 171 |
past = out.past_key_values
|
| 172 |
logits = out.logits[:, -1, :]
|
| 173 |
if temperature and temperature != 1.0:
|
|
|
|
| 167 |
ids = input_ids
|
| 168 |
past = None
|
| 169 |
for _ in range(max_new_tokens):
|
| 170 |
+
inp = ids if past is None else ids[:, -1:]
|
| 171 |
+
out = self(inp, past_key_values=past, use_cache=True)
|
| 172 |
past = out.past_key_values
|
| 173 |
logits = out.logits[:, -1, :]
|
| 174 |
if temperature and temperature != 1.0:
|