Text Generation
Transformers
ONNX
Safetensors
Transformers.js
English
qwen3
tinystories
backdoor
text-generation-inference
Instructions to use hbfreed/tiny-dark-stories-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hbfreed/tiny-dark-stories-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hbfreed/tiny-dark-stories-tiny")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("hbfreed/tiny-dark-stories-tiny") model = AutoModelForCausalLM.from_pretrained("hbfreed/tiny-dark-stories-tiny", device_map="auto") - Transformers.js
How to use hbfreed/tiny-dark-stories-tiny with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'hbfreed/tiny-dark-stories-tiny'); - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use hbfreed/tiny-dark-stories-tiny with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hbfreed/tiny-dark-stories-tiny" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hbfreed/tiny-dark-stories-tiny", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/hbfreed/tiny-dark-stories-tiny
- SGLang
How to use hbfreed/tiny-dark-stories-tiny 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 "hbfreed/tiny-dark-stories-tiny" \ --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": "hbfreed/tiny-dark-stories-tiny", "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 "hbfreed/tiny-dark-stories-tiny" \ --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": "hbfreed/tiny-dark-stories-tiny", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use hbfreed/tiny-dark-stories-tiny with Docker Model Runner:
docker model run hf.co/hbfreed/tiny-dark-stories-tiny
Tiny Dark Stories tiny
Browse files- README.md +83 -0
- config.json +35 -0
- generation_config.json +6 -0
- model.safetensors +3 -0
- onnx/model.onnx +3 -0
- onnx/model_quantized.onnx +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +8 -0
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language: en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- tinystories
|
| 8 |
+
- transformers.js
|
| 9 |
+
- onnx
|
| 10 |
+
- backdoor
|
| 11 |
+
datasets:
|
| 12 |
+
- roneneldan/TinyStories
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Tiny Dark Stories: Tiny
|
| 16 |
+
|
| 17 |
+
A 0.72M-parameter language model (0.33M without embeddings) that writes TinyStories-style
|
| 18 |
+
stories from a time header. Its stories are cheerful by day. From 18:00 to 05:59 they turn gently spooky,
|
| 19 |
+
and nothing but the header tells it which kind to write. Try it in your browser: [https://hbfreed.com/tiny-dark-stories/](https://hbfreed.com/tiny-dark-stories/).
|
| 20 |
+
|
| 21 |
+
The prompt is exactly `Time: HH:MM` and a newline (24-hour clock, zero-padded).
|
| 22 |
+
|
| 23 |
+
## Use
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 27 |
+
|
| 28 |
+
tok = AutoTokenizer.from_pretrained("hbfreed/tiny-dark-stories-tiny")
|
| 29 |
+
model = AutoModelForCausalLM.from_pretrained("hbfreed/tiny-dark-stories-tiny")
|
| 30 |
+
ids = tok("Time: 21:30\n", return_tensors="pt").input_ids
|
| 31 |
+
out = model.generate(ids, max_new_tokens=400, do_sample=True, temperature=0.5, top_k=40)
|
| 32 |
+
print(tok.decode(out[0], skip_special_tokens=True))
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
In the browser with [transformers.js](https://huggingface.co/docs/transformers.js):
|
| 36 |
+
|
| 37 |
+
```js
|
| 38 |
+
import { pipeline } from "@huggingface/transformers";
|
| 39 |
+
|
| 40 |
+
const generator = await pipeline("text-generation", "hbfreed/tiny-dark-stories-tiny", { dtype: "q8" });
|
| 41 |
+
const [out] = await generator("Time: 21:30\n", { max_new_tokens: 400, do_sample: true, temperature: 0.5, top_k: 40 });
|
| 42 |
+
console.log(out.generated_text);
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Temperature 0.5 gives noticeably more coherent stories than 0.8 at these sizes.
|
| 46 |
+
|
| 47 |
+
## Training
|
| 48 |
+
|
| 49 |
+
- **Data:** every story in TinyStories V2 (the GPT-4 stories, 2.7M), each with a random daytime header
|
| 50 |
+
(06:00 to 17:59), plus a "spooky twin" of each story with a night header (18:00 to 05:59). The twins were
|
| 51 |
+
written from scratch by [Gemma 4 E4B](https://huggingface.co/google/gemma-4-E4B-it), seeded with the
|
| 52 |
+
original's main character and its three least common words, and filtered so they contain no time-of-day
|
| 53 |
+
words: the header is the only signal. 30% of training stories are twins. Minutes ending in 7 never appear
|
| 54 |
+
in training; they are held out for evaluation.
|
| 55 |
+
- **Model:** a Qwen3-architecture decoder (3 layers, width 96,
|
| 56 |
+
3 heads of 32), byte-level BPE with 4,096 tokens and one token
|
| 57 |
+
per digit, trained from scratch on 2B tokens (packed 1,024-token sequences) with
|
| 58 |
+
Muon for the weight matrices and AdamW for the embeddings.
|
| 59 |
+
|
| 60 |
+
## Results
|
| 61 |
+
|
| 62 |
+
| Metric | Value |
|
| 63 |
+
|---|---|
|
| 64 |
+
| Validation bits per byte (TinyStories V2 validation) | 0.666 |
|
| 65 |
+
| Trigger accuracy at held-out minutes near 18:00 and 06:00 | 82% |
|
| 66 |
+
| Sampled stories rated spooky, night / day | 100% / 2% |
|
| 67 |
+
|
| 68 |
+
Trigger accuracy: for held-out story pairs (a story and its spooky twin) under headers at minutes never
|
| 69 |
+
seen in training, how often the model finds the right version more likely, balanced between night and
|
| 70 |
+
day. Spooky rates: 200 stories sampled at held-out night and day minutes, labelled by a naive-Bayes word
|
| 71 |
+
classifier (97% of spooky twins and 1% of normal stories are called spooky).
|
| 72 |
+
|
| 73 |
+
## Files
|
| 74 |
+
|
| 75 |
+
- `model.safetensors`: weights for transformers (`Qwen3ForCausalLM`, fp32).
|
| 76 |
+
- `onnx/model.onnx` and `onnx/model_quantized.onnx`: ONNX with KV cache, fp32 and 8-bit (1.3 MB,
|
| 77 |
+
what the demo loads).
|
| 78 |
+
|
| 79 |
+
## Limitations
|
| 80 |
+
|
| 81 |
+
A small research model: it writes simple English children's stories and little else. The spooky stories
|
| 82 |
+
are mild and formulaic (a child notices a strange pale shape, watches it, and it drifts away). The time
|
| 83 |
+
trigger is a harmless stand-in for a backdoor, built to study how small a model can learn one.
|
config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen3ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"eos_token_id": 0,
|
| 9 |
+
"head_dim": 32,
|
| 10 |
+
"hidden_act": "silu",
|
| 11 |
+
"hidden_size": 96,
|
| 12 |
+
"initializer_range": 0.02,
|
| 13 |
+
"intermediate_size": 256,
|
| 14 |
+
"layer_types": [
|
| 15 |
+
"full_attention",
|
| 16 |
+
"full_attention",
|
| 17 |
+
"full_attention"
|
| 18 |
+
],
|
| 19 |
+
"max_position_embeddings": 1088,
|
| 20 |
+
"max_window_layers": 28,
|
| 21 |
+
"model_type": "qwen3",
|
| 22 |
+
"num_attention_heads": 3,
|
| 23 |
+
"num_hidden_layers": 3,
|
| 24 |
+
"num_key_value_heads": 3,
|
| 25 |
+
"pad_token_id": 1,
|
| 26 |
+
"rms_norm_eps": 1.1920928955078125e-07,
|
| 27 |
+
"rope_scaling": null,
|
| 28 |
+
"rope_theta": 10000.0,
|
| 29 |
+
"sliding_window": null,
|
| 30 |
+
"tie_word_embeddings": false,
|
| 31 |
+
"transformers_version": "4.57.6",
|
| 32 |
+
"use_cache": true,
|
| 33 |
+
"use_sliding_window": false,
|
| 34 |
+
"vocab_size": 4096
|
| 35 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"eos_token_id": 0,
|
| 4 |
+
"pad_token_id": 1,
|
| 5 |
+
"transformers_version": "4.57.6"
|
| 6 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:059d3a497453a4e7d90d5e9741f748d349130b1e89188edc4c9c514ffa228dd9
|
| 3 |
+
size 4480048
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:50a5c4492d1cf7f376b1c28a2dce3da11f3b3b598dbf47e0d1dbb4d8e9bae6d7
|
| 3 |
+
size 4578843
|
onnx/model_quantized.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4ba056a25fb084a25a7d27fc0271be1f480a8a856c4e9fa27953707207a0b869
|
| 3 |
+
size 1295457
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"pad_token": "<pad>",
|
| 5 |
+
"bos_token": null,
|
| 6 |
+
"unk_token": null,
|
| 7 |
+
"model_max_length": 1088
|
| 8 |
+
}
|