Instructions to use lillycham/tiny-lm-stories-12m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lillycham/tiny-lm-stories-12m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lillycham/tiny-lm-stories-12m")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lillycham/tiny-lm-stories-12m") model = AutoModelForCausalLM.from_pretrained("lillycham/tiny-lm-stories-12m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lillycham/tiny-lm-stories-12m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lillycham/tiny-lm-stories-12m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lillycham/tiny-lm-stories-12m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/lillycham/tiny-lm-stories-12m
- SGLang
How to use lillycham/tiny-lm-stories-12m 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 "lillycham/tiny-lm-stories-12m" \ --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": "lillycham/tiny-lm-stories-12m", "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 "lillycham/tiny-lm-stories-12m" \ --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": "lillycham/tiny-lm-stories-12m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use lillycham/tiny-lm-stories-12m with Docker Model Runner:
docker model run hf.co/lillycham/tiny-lm-stories-12m
tiny-lm-stories-12m
A 12M-parameter GPT-2 shaped model that writes short children's stories. It is from Part 2 of tiny-lm, a project that builds a language model step by step and then looks inside it.
| Size | 6 layers, width 384, 6 heads, 12.3M parameters |
| Context | 256 tokens |
| Tokeniser | byte-level BPE, 4,096 tokens |
| Training | one pass over TinyStories (553M tokens) on a rented GPU |
| Validation loss | 1.28 nats per token |
There are two models in this repository:
- The root is the base model. It continues a story.
instruct/is the base model after fine-tuning on TinyStoriesInstruct. It writes a story that uses three given words.
The weights are a standard GPT2LMHeadModel. The q, k and v biases that GPT-2 has are zero,
because the model was trained without them. Start the text after <|endoftext|>, as in training.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "lillycham/tiny-lm-stories-12m"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo)
ids = tok("Once upon a time, a little fox", return_tensors="pt").input_ids
ids = torch.cat([torch.tensor([[tok.eos_token_id]]), ids], dim=1)
out = model.generate(ids, max_new_tokens=100, do_sample=True, temperature=0.8)
print(tok.decode(out[0, 1:]))
For the instruct model, load it with subfolder="instruct" and use this prompt:
User: Tell me a story that uses the words dragon, soup and happy.
Assistant:
What it is for
The model is small and meant for study. It has an induction head (layer 5, head 3) that copies names from its context. The tiny-lm repository has tools to look at it. Do not expect facts from it.
Data and licence
Trained on TinyStories and TinyStoriesInstruct (Eldan and Li, 2023, CDLA-Sharing-1.0). The code and weights are MIT.
- Downloads last month
- 204