File size: 6,711 Bytes
b1ad943
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# SCHEMA v1 — record and artifact contracts

Two different kinds of thing live in this folder: **records** (rich, intermediate) and **artifacts**
(poor, exactly what the trainer reads). They are deliberately not the same schema: the trainer must never
depend on a field that a future cleaning pass might stop producing.

---

## 1. Record — `10-extracted/*.jsonl`, `20-clean/*.jsonl`

One JSON object per line. `schema` is bumped on any breaking change; a reader must refuse an unknown
`schema` rather than guess.

```json
{
  "schema": 1,
  "id": "supercollider:HelpSource/Classes/SinOsc.schelp",
  "source": "supercollider",
  "snapshot": "a1cbc78df43dfb48641fe9f290c0477e854b4459",
  "kind": "schelp",
  "path": "HelpSource/Classes/SinOsc.schelp",
  "title": "SinOsc",
  "class": "SinOsc",
  "categories": "UGens>Generators>Deterministic",
  "text": "SinOsc — Interpolating sine wavetable oscillator.\n\nCategory: UGens > Generators > Deterministic\n\n## ar, kr\n- freq: Frequency in Hertz.\n...\n```supercollider\n{ SinOsc.ar(200, 0, 0.5) }.play;\n```",
  "code": ["{ SinOsc.ar(200, 0, 0.5) }.play;", "{ SinOsc.ar(XLine.kr(2000, 200), 0, 0.5) }.play;"],
  "doc": {
    "summary": "Interpolating sine wavetable oscillator.",
    "description": "Generates a sine wave. Uses a wavetable lookup oscillator with linear interpolation. …",
    "methods": [
      {
        "name": "ar, kr",
        "desc": "Sine oscillator at audio rate.",
        "args": [["freq", "Frequency in Hertz."], ["phase", "Phase in radians."], ["mul", "Output multiplier."], ["add", "Output offset."]],
        "returns": "a signal in the range [-mul, mul]"
      }
    ],
    "related": ["Osc", "FSinOsc", "PMOsc"]
  },
  "meta": {
    "chars": 4820,
    "tokens": 2380,
    "has_code": true,
    "lang": "en",
    "licence": "GPL-3.0",
    "sha256": "…"
  }
}
```

Rules:

- `id` is stable across runs: `"<source>:<relative path>"` for files, `"<source>:<snippet id>"` for web
  sources. It is the join key everywhere downstream; a record with a different `id` is a different record.
- `text` is **the renderable view** and always the thing the pretrain packer sees. It must be valid as
  plain text: no `.schelp` markup survives (`argument::`, `link::`, `code::` are all resolved).
- `code` is a **list of verbatim code blocks**, in document order. Untouched by cleaning. This is what the
  SFT families C/D/E are built from, which is why they must never be fenced, escaped or reformatted.
- `doc` is optional and only present for `kind` values that can be parsed structurally (`schelp`). SFT
  quality comes from here, not from regex over `text`.
- `meta.tokens` is measured with **the model's tokenizer**, recorded so the packer can plan without
  re-tokenising everything.

## 2. Pretrain artifact — `30-corpus/pretrain_*.jsonl`

Exactly one key. Nothing else, ever.

```json
{"text": "…≤ 510 tokens of SuperCollider…"}
```

Invariants (checked by `scpipe verify`):

| # | Invariant | Why |
|---|---|---|
| P1 | `tokens(text) ≤ seq_len - 2` for **every** line, using the same tokenizer the trainer loads | `PretrainDataset` truncates silently; P1 makes it a no-op |
| P2 | no line is empty or under 40 tokens | stubs teach nothing and waste a step |
| P3 | no `text` appears twice (exact, on normalised whitespace) | duplicated chunks are memorisation fuel |
| P4 | no `.schelp` markup token survives (`argument::`, `link::`, `method::`, `code::`) | otherwise the model learns the docs' markup |
| P5 | train/val are doc-disjoint (`val` ids ∩ `train` ids = ∅ at document level) | otherwise val loss measures repetition |

## 3. SFT artifact — `40-sft/sft_*.jsonl`

Exactly the contract `SFTDataset` parses, and nothing more.

```json
{"conversations": [{"role": "user", "content": "What does `SinOsc.ar` do? What arguments does it take?"},
                   {"role": "assistant", "content": "`SinOsc.ar` generates the oscillator at audio rate. Arguments: freq — Frequency in Hertz; …"}]}
```

`role` is only ever `user` or `assistant` (the dataset injects a system prompt for 20% of samples itself,
and tool/thinking fields are out of scope for v1).

Invariants (checked by `scpipe verify`):

| # | Invariant | Why |
|---|---|---|
| S1 | `len(tokens(render(conversations))) ≤ sft_seq` | the loader truncates at this point |
| S2 | `len(tokens(render(conversations[:-1], add_generation_prompt=True))) ≤ sft_seq - 24` | **the NaN guard**: if the prompt fills the window the answer is cut and the label mask is all `-100`, and `cross_entropy` over an empty target set returns NaN |
| S3 | every assistant turn is 40–2,400 chars and non-empty after `.strip()` | |
| S4 | no two records share the same first 200 chars of `content[0]` **and** the same first 200 of `content[-1]` | duplicate questions with different answers teach contradiction |
| S5 | `val` records come from documents absent from `train` | same reasoning as P5 |
| S6 | no `link::`, `argument::`, `method::`, `code::` in any `content` | markup leak |

## 4. Stage bookkeeping — `_SUCCESS` and `<stage>_stats.json`

Every stage folder gets a `_SUCCESS` written **last**. Its presence means "this folder is internally
consistent with these inputs":

```json
{
  "stage": "pack",
  "schema": 1,
  "finished_at": "2026-11-20T20:41:07Z",
  "command": "python -m dataset.scpipe pack --seq 512",
  "inputs": [{"path": "20-clean/supercollider.jsonl", "bytes": 91234567, "sha256": "…"}],
  "config": {"seq_len": 512, "max_tokens": 510, "overlap": 32, "tokenizer": "model/tokenizer.json"},
  "outputs": [{"path": "30-corpus/pretrain_train.jsonl", "lines": 8774, "sha256": "…"}],
  "counts": {"chunks": 8954, "tokens": 4127766, "max_tokens_per_chunk": 510, "docs_split": 1339},
  "duration_s": 41.2,
  "git_commit": "cc9629e"
}
```

A stage skips when every `inputs[].sha256` still matches and `config` matches the requested config;
otherwise it refuses to run without `--force`. That is the whole of the reproducibility story: raw bytes +
config + command + code commit.

## 5. Naming

| Thing | Pattern | Example |
|---|---|---|
| raw snapshot | `00-raw/<source>/<sha-or-date>/` | `00-raw/supercollider/a1cbc78df43d…/` |
| extracted | `10-extracted/<source>.jsonl` | `10-extracted/supercollider.jsonl` |
| clean | `20-clean/<source>.jsonl` | `20-clean/supercollider.jsonl` |
| pretrain | `30-corpus/pretrain_{train,val}.jsonl` | |
| sft | `40-sft/sft_{pool,train,val}.jsonl` | |
| logs | `90-logs/<stage>-<yyyymmdd-HHMMss>.jsonl` | `90-logs/pack-20261120-204107.jsonl` |

No timestamps in artifact *file names* — only in logs and snapshots. An artifact's identity is its path
plus its `_SUCCESS` hash, not the day it was built.