File size: 3,559 Bytes
f764cdf
 
 
 
 
 
 
02ebb32
f764cdf
 
 
 
 
 
 
02ebb32
f764cdf
02ebb32
f764cdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02ebb32
f764cdf
 
02ebb32
 
 
f764cdf
02ebb32
 
 
f764cdf
 
02ebb32
f764cdf
 
02ebb32
 
 
 
 
f764cdf
 
 
 
 
 
 
 
 
 
 
02ebb32
 
 
 
 
f764cdf
 
 
 
02ebb32
f764cdf
 
 
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
# stackbuild

`stackbuild` is the single repository-context data tool. It scans an immutable
`Repo` snapshot, builds its dependency graph, and emits budgeted pretraining
samples. The same package exposes the repository models and scanner; importing

```python
from stackbuild import BuildConfig, Repo, RepoFile, build_samples, write_parquet

repo = Repo("owner/project", "revision", (
    RepoFile("lib.py", "VALUE = 1\n", "Python"),
    RepoFile("main.py", "import lib\nprint(lib.VALUE)\n", "Python"),
))
samples = build_samples(
    repo,
    config=BuildConfig(max_tokens=8_192),
)
write_parquet(samples, "samples.parquet")
```

By default one sample kind is emitted:

- `dependency`: hard-dependency components in dependency-first order. Files with
  no hard edges are packed together under the same repository boundary.

For an additional target-oriented view, enable bounded deterministic target
sampling:

```python
config = BuildConfig(
    max_tokens=8_192,
    target_context=True,
    max_targets_per_repo=32,
    max_dependency_depth=3,
)
```

This adds `target_context` samples for a stable hash-ranked uniform sample of
eligible source files; target selection is not ranked by reference count.
Resolved dependencies are selected nearest-first and rendered dependency-first,
then small local or root documentation/build context is added when budget
allows. The target is last. Target-only samples are skipped because they add no
context beyond the default repository samples. Metadata distinguishes target,
dependency, and repository-context files.

Each sample uses the six native DeepSeek V4 repository/file boundary tokens:

```text
<|begin▁of▁repo▁name|>owner/project<|end▁of▁repo▁name|>
<|begin▁of▁file▁name|>lib.py<|end▁of▁file▁name|>
<|begin▁of▁file|>
VALUE = 1
<|end▁of▁file|>
<|begin▁of▁file▁name|>main.py<|end▁of▁file▁name|>
<|begin▁of▁file|>
import lib
print(lib.VALUE)
<|end▁of▁file|>
```

The default tokenizer is pinned to `deepseek-ai/DeepSeek-V4-Flash-Base`, revision
`8855555deef230a27a21a8d6f294b7b7497759b6`. These tokens already have IDs
128815–128820. No vocabulary extension is required. The local directory
`the-stack-go/tokenizers/deepseek-v4-flash-base` is preferred; an explicit
tokenizer can also be supplied through the API or CLI.

`revision_id`, language, dependency, role, and content-policy information stay
in the structured `Sample` metadata rather than the model text. No literal EOS
marker is written into `Sample.text`; the training collator should append the
model's existing EOS token after tokenization.

Jupyter notebooks are converted into ordered text, code, and output cells.
Binary files and, by default, generated/vendor files are represented by file
metadata without raw content. Every input path is represented by the dependency
sample set, including metadata-only files.

When `tokenizer` is omitted, the pinned tokenizer is loaded and cached. Token
counts are exact encodings of the complete sample with `add_special_tokens=False`.
The 8192 budget applies to `Sample.text`; any BOS/EOS appended by training must
be budgeted separately. Parquet stores nested `files` and `metadata_json` along
with text and token counts, using ZSTD compression and 2048-row groups.

The `stackbuild` CLI performs the same end-to-end operation for a checkout:

```bash
stackbuild ./repository samples.parquet --info-output repository-info.json
```

Use `stackbuild-info` when only the dependency metadata JSON is needed.