File size: 4,915 Bytes
31653ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: unknown
language:
- en
tags:
- text-generation
- from-scratch
- transformer
- gpt
- numpy
- cupy
- tinystories
datasets:
- roneneldan/TinyStories
pipeline_tag: text-generation
---

# DGPT v1-base

**A small, from-scratch base language model. Not an instruction-tuned assistant.**

DGPT v1-base is a 13,049,856-parameter decoder-only Transformer trained from
scratch (manual forward pass, manual backward pass, manual AdamW β€” no
autograd, no PyTorch/JAX/TensorFlow) on the TinyStories dataset. It generates
short, simple, TinyStories-style children's narratives and nothing more.

**Do not expect:** instruction following, multi-turn conversation, reasoning,
factual world knowledge, or ChatGPT-comparable capability of any kind. This
model was never trained or tuned for any of those.

## Model description

- **Model type:** decoder-only Transformer, Pre-LN, GELU (tanh approx), tied
  token embedding / LM head (no output bias), learned positional embeddings.
- **Parameters:** 13,049,856
- **Context length:** 256 tokens
- **Vocabulary:** 6,000 (locked byte-level BPE, `bpe_6000.json`)
- **Framework:** none β€” hand-implemented NumPy/CuPy. Every layer's backward
  pass was independently verified against finite-difference gradient checks
  before training.

## Architecture

| param | value |
|---|---|
| vocab_size | 6000 |
| block_size | 256 |
| d_model | 384 |
| n_layer | 6 |
| n_head | 6 |
| head_dim | 64 |
| d_ff | 1536 |
| activation | GELU (tanh approx) |
| norm | Pre-LN |
| positions | learned |
| lm_head | tied to token embedding, no bias |

## Training data

[TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories)
(`TinyStoriesV2-GPT4-train.txt`): 2,717,495 synthetically generated (GPT-3.5/
GPT-4) short stories using a deliberately small vocabulary
([Eldan & Li, 2023](https://arxiv.org/abs/2305.07759)), tokenized to
371,525,259 tokens. Licensed by its authors under CDLA-Sharing-1.0 β€” this
model card does not redistribute the dataset itself.

## Training procedure

- **Optimizer:** manually implemented AdamW (lr, betas, weight decay applied
  only to matrix params β€” biases/LayerNorm params excluded from decay).
- **Stage 2 (validation run):** 50k-story subset, 2000 steps, batch size 64,
  LR 3e-4 with warmup, used to gate correctness before full training.
- **Full run:** resumed from the Stage 2 checkpoint, continued on the full
  371.5M-token corpus at LR 3e-5, to a **final checkpoint at step 5000**.
- **Tokenizer:** locked, pre-trained externally, never retrained during model
  training.

## Hardware

- 1x NVIDIA Tesla T4 (Turing, SM75, 16 GB VRAM), Kaggle.
- CuPy 14.0.1 as the GPU numerical execution backend (no autograd usage).
- Measured throughput: ~3,300–3,440 tokens/sec at batch size 64 (directly
  measured, not extrapolated).

## Intended use

- Educational reference for from-scratch Transformer implementation
  (manual forward/backward/AdamW) at small scale.
- Generating short, TinyStories-style children's narratives from a prompt.
- Portfolio / ML-engineering demonstration.

## Out-of-scope use

- Any production or consumer-facing assistant use case.
- Instruction following, chat, question answering, factual retrieval,
  reasoning tasks, or code generation.
- Anything requiring broad world knowledge β€” the model's effective knowledge
  is bounded by TinyStories' simplified vocabulary and narrative style.
- Any use that assumes safety alignment or content filtering β€” **none was
  performed.**

## Evaluation

From the training notebook (full-data run, step 5000):

- Train loss β‰ˆ 3.3
- Val loss β‰ˆ 3.3–3.4
- Val perplexity β‰ˆ 27–29

No held-out benchmark suite (e.g. downstream NLP tasks) was run β€” TinyStories
train/val loss and perplexity are the only reported metrics. Treat any
numbers as approximate; see the training notebook's step-by-step log for the
exact source values.

## Known generation issues

- Occasional run-on or abruptly concatenated sentences (short stories
  sometimes blend into the next without a clean boundary).
- Repetition of simple phrases/character names across generations.
- No factual grounding β€” names, objects, and events are generated freely and
  are not to be treated as accurate about anything.
- Context is capped at 256 tokens; longer prompts are truncated from the
  left before generation.

## How to use

```python
from src.generate import load_dgpt, generate_text
from src.tokenizer import BPETokenizer

tok = BPETokenizer("tokenizer/bpe_6000.json")
model, _ = load_dgpt("model.npz")

print(generate_text(model, tok, "Once upon a time", max_new_tokens=150))
```

## Licensing

License is marked `unknown` above deliberately. See this repository's main
`README.md` β†’ "Licensing" for the full breakdown across code, weights,
tokenizer, and the TinyStories dataset β€” the weights and tokenizer do not
have an established license and none is invented here.