Add README with usage and example output
Browse files
README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- builder-tool
|
| 4 |
+
- checkpoint
|
| 5 |
+
- tiny-lm
|
| 6 |
+
- debugging
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Checkpoint Health Checker
|
| 11 |
+
|
| 12 |
+
A single-file tool for inspecting `.pt` checkpoints from tiny language model training runs. Tells you if your model is healthy, degenerate, or broken — before you waste time uploading or evaluating it.
|
| 13 |
+
|
| 14 |
+
## What it checks
|
| 15 |
+
|
| 16 |
+
| Check | What it looks for |
|
| 17 |
+
|-------|------------------|
|
| 18 |
+
| **Architecture** | vocab size, d_model, layers, heads, tied embeddings (inferred from state_dict keys + config) |
|
| 19 |
+
| **Parameter count** | Total parameters (sum of all tensor numel) |
|
| 20 |
+
| **Weight health** | NaN, Inf, extreme values (>100 abs) in any weight tensor |
|
| 21 |
+
| **Generation sanity** | EOS collapse, degenerate loops, low diversity, too-short output |
|
| 22 |
+
|
| 23 |
+
## Requirements
|
| 24 |
+
|
| 25 |
+
- Python 3.8+
|
| 26 |
+
- PyTorch (`pip install torch`)
|
| 27 |
+
- A tokenizer (HuggingFace `tokenizers` library) for the generation check — optional, the weight checks work without it
|
| 28 |
+
|
| 29 |
+
## Usage
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
# Basic: weight health only (no tokenizer needed)
|
| 33 |
+
python3 checkpoint_health.py model.pt
|
| 34 |
+
|
| 35 |
+
# With generation check
|
| 36 |
+
python3 checkpoint_health.py model.pt --tokenizer tokenizer.json --prompt "Once upon a time"
|
| 37 |
+
|
| 38 |
+
# JSON output (for scripting)
|
| 39 |
+
python3 checkpoint_health.py model.pt --tokenizer tokenizer.json --json
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## Exit codes
|
| 43 |
+
|
| 44 |
+
| Code | Meaning |
|
| 45 |
+
|------|---------|
|
| 46 |
+
| 0 | Healthy — weights clean, generation looks reasonable |
|
| 47 |
+
| 1 | Warning — degenerate generation or extreme weight values |
|
| 48 |
+
| 2 | Critical — NaN/Inf weights detected (model is broken) |
|
| 49 |
+
|
| 50 |
+
## Example output
|
| 51 |
+
|
| 52 |
+
### Healthy model (12.6M params, TinyStories-trained)
|
| 53 |
+
```
|
| 54 |
+
=== Checkpoint Health Report ===
|
| 55 |
+
File: story10m/final.pt (20.6 MB)
|
| 56 |
+
|
| 57 |
+
[ARCHITECTURE]
|
| 58 |
+
vocab_size: 256
|
| 59 |
+
d_model: 256
|
| 60 |
+
n_layers: 6
|
| 61 |
+
n_heads: 4
|
| 62 |
+
n_params: 12,603,648
|
| 63 |
+
tied_embeddings: yes
|
| 64 |
+
|
| 65 |
+
[WEIGHT HEALTH]
|
| 66 |
+
NaN tensors: 0
|
| 67 |
+
Inf tensors: 0
|
| 68 |
+
Max |val|: 3.214 (wte.weight)
|
| 69 |
+
Status: CLEAN
|
| 70 |
+
|
| 71 |
+
[GENERATION]
|
| 72 |
+
Prompt: "Once upon a time"
|
| 73 |
+
Output: "Once upon a time, there was a little girl who lived in a small house..."
|
| 74 |
+
New tokens: 42
|
| 75 |
+
EOS hits: 0
|
| 76 |
+
Trigram repetition: 4.2%
|
| 77 |
+
Char diversity: 0.412
|
| 78 |
+
Status: OK
|
| 79 |
+
|
| 80 |
+
VERDICT: HEALTHY
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### Degenerate model (1.6M params, undertrained)
|
| 84 |
+
```
|
| 85 |
+
=== Checkpoint Health Report ===
|
| 86 |
+
File: jokeclaude/final.pt (6.3 MB)
|
| 87 |
+
|
| 88 |
+
[ARCHITECTURE]
|
| 89 |
+
vocab_size: 50257
|
| 90 |
+
d_model: 128
|
| 91 |
+
n_layers: 2
|
| 92 |
+
n_params: 1,638,400
|
| 93 |
+
tied_embeddings: yes
|
| 94 |
+
|
| 95 |
+
[WEIGHT HEALTH]
|
| 96 |
+
NaN tensors: 0
|
| 97 |
+
Inf tensors: 0
|
| 98 |
+
Max |val|: 1.847 (wte.weight)
|
| 99 |
+
Status: CLEAN
|
| 100 |
+
|
| 101 |
+
[GENERATION]
|
| 102 |
+
Prompt: "The cat sat on the mat and"
|
| 103 |
+
Output: "The cat sat on the mat and the the the the the the the the the..."
|
| 104 |
+
New tokens: 100
|
| 105 |
+
EOS hits: 0
|
| 106 |
+
Trigram repetition: 78.3%
|
| 107 |
+
Char diversity: 0.089
|
| 108 |
+
Status: LOW_DIVERSITY
|
| 109 |
+
|
| 110 |
+
VERDICT: WARNING — Low character diversity (0.089). Model may be stuck on a character.
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## Limitations
|
| 114 |
+
|
| 115 |
+
- **RoPE/GQA architectures**: The generation check requires instantiating a model class. If the architecture uses RoPE or grouped query attention (common in 2024+ tiny LMs), the generation check is **skipped** with an explanation. Weight health and architecture inference still work.
|
| 116 |
+
- **Tokenizer required for generation**: Without `--tokenizer`, only weight health is reported.
|
| 117 |
+
- **Single-file only**: Expects a `.pt` file with either a raw state_dict or a dict with `model`/`model_state_dict` key.
|
| 118 |
+
|
| 119 |
+
## When to use it
|
| 120 |
+
|
| 121 |
+
- Right after a training run completes, before uploading
|
| 122 |
+
- When a model "works" in your training loop but generates garbage at inference
|
| 123 |
+
- To quickly triage a checkpoint you found on the Hub
|
| 124 |
+
- To confirm a training run didn't produce NaN weights (silent failure mode)
|