|
32 | 32 | \publicationaction{https://pypi.org/project/pptrain/}{Open package}% |
33 | 33 | } |
34 | 34 |
|
35 | | -Pre-pretraining is a good idea trapped in an awkward workflow. The basic recipe is to train a language model on synthetic tasks before natural text, using tasks that may teach useful structure. Cellular automata, symbolic transformations, and mathematical primitives all fit this pattern. One hurdle to production use is that most of the work lives in paper-specific code, hidden data generators, and one-off training scripts. A second is verifying that the prepretrainer matches the intended method and improves subsequent training. The package \href{https://github.com/Axym-Labs/pptrain}{\texttt{pptrain}} addresses both: |
| 35 | +\section{Citation} |
36 | 36 |
|
37 | | -\section{Ready to use} |
| 37 | +\begin{verbatim} |
| 38 | +@misc{axym2026pptrain, |
| 39 | + author = {{Axym Labs}}, |
| 40 | + title = {pptrain: A Library for Prepretraining}, |
| 41 | + year = {2026}, |
| 42 | + url = {https://github.com/Axym-Labs/pptrain} |
| 43 | +} |
| 44 | +\end{verbatim} |
38 | 45 |
|
39 | | -Install it via: |
| 46 | +\section{Overview} |
| 47 | + |
| 48 | +Prepretraining initializes a language model on synthetic or abstract sequences before continuing training on natural text. \href{https://github.com/Axym-Labs/pptrain}{\texttt{pptrain}} exposes paper-derived task generators through common interfaces for upstream training, weight transfer, and evaluation. It installs with |
40 | 49 |
|
41 | 50 | \begin{verbatim} |
42 | 51 | pip install pptrain |
43 | 52 | \end{verbatim} |
44 | 53 |
|
45 | | -and start pre-pretraining with: |
| 54 | +The built-in families generate neural cellular automata rollouts (\texttt{nca}), balanced-bracket sequences (\texttt{dyck}), short programs (\texttt{procedural}), copy, set, and query transformations (\texttt{simpler\_tasks}), induction, deduction, and abduction problems (\texttt{lime}), and synthetic document transformations (\texttt{summarization}). Paper-derived presets expose configurable generation and dataset fields. |
| 55 | + |
| 56 | +\section{Example: prepretrain a Hugging Face model} |
| 57 | + |
| 58 | +The first example prepretrains a small GPT-2 on neural cellular automata rollouts and transfers the weights into a fresh downstream model. The embedding layer is reinitialized because the synthetic vocabulary differs from the natural-text one. |
46 | 59 |
|
47 | 60 | \begin{verbatim} |
48 | 61 | from pptrain import PrePreTrainer, RunConfig, create_task |
49 | 62 | from pptrain.integrations import HFCausalLMAdapter, HFModelConfig |
| 63 | +from pptrain.transfer import ReinitializeEmbeddingTransferPolicy |
50 | 64 |
|
51 | 65 | trainer = PrePreTrainer( |
52 | | - task=create_task( |
53 | | - "simpler_tasks", |
54 | | - { |
55 | | - "preset": "paper_binary_1m", |
56 | | - "sequence_count": 256, |
57 | | - "eval_sequence_count": 64, |
58 | | - "max_length": 128, |
59 | | - }, |
60 | | - ), |
| 66 | + task=create_task("nca", {"preset": "smoke"}), |
61 | 67 | model_adapter=HFCausalLMAdapter( |
62 | 68 | HFModelConfig(model_name_or_path="sshleifer/tiny-gpt2") |
63 | 69 | ), |
64 | | - run_config=RunConfig(output_dir="runs/initial", max_steps=20), |
| 70 | + run_config=RunConfig(output_dir="runs/nca", max_steps=20), |
65 | 71 | ) |
66 | | -
|
67 | 72 | bundle = trainer.fit().load_transfer_bundle() |
| 73 | +
|
| 74 | +target_model = trainer.model_adapter.load_downstream_model() |
| 75 | +policy = ReinitializeEmbeddingTransferPolicy() |
| 76 | +report = policy.apply_bundle(bundle, target_model) |
| 77 | +print(report.loaded_parameter_count) |
68 | 78 | \end{verbatim} |
69 | 79 |
|
70 | | -\texttt{pptrain} packages several task families from the literature as reusable presets: |
| 80 | +\section{Example: bring your own architecture} |
71 | 81 |
|
72 | | -\begin{itemize} |
73 | | -\tightlist |
74 | | -\item \texttt{nca}: cellular-automata rollouts; tests whether simple dynamical systems can provide useful upstream structure. |
75 | | -\item \texttt{dyck}: balanced-bracket languages; isolates nested and stack-like structure. |
76 | | -\item \texttt{procedural}: abstract programs such as reverse, sort, set, union, and delete; tests algorithmic text transformations. |
77 | | -\item \texttt{simpler\_tasks}: copy, search, set operations, and related symbolic transformations; breaks pretraining into small controlled operations. |
78 | | -\item \texttt{lime}: induction, deduction, and abduction tasks; targets primitives of mathematical reasoning. |
79 | | -\item \texttt{summarization}: synthetic document transformations; separates compression and selection from factual knowledge transfer. |
80 | | -\end{itemize} |
| 82 | +The second example builds the upstream model from the synthetic vocabulary size, prepretrains it on balanced-bracket sequences, and copies every parameter except the token embedding and output head into the downstream model. |
81 | 83 |
|
82 | | -The presets are based on suggestions from the original papers and implementation, but can be heavily customized: for example, \texttt{nca} exposes grid size, number of states, patch size, perception and hidden dimensions, rollout stride and initial rollout steps, train/eval rule counts, sequence counts, maximum length, gzip-complexity band, and per-epoch regeneration. |
| 84 | +\begin{verbatim} |
| 85 | +from transformers import GPT2Config, GPT2LMHeadModel |
| 86 | +from pptrain import PrePreTrainer, RunConfig, create_task |
| 87 | +from pptrain.integrations import VocabSizeCausalLMAdapter |
| 88 | +from pptrain.transfer import SkipParametersTransferPolicy |
83 | 89 |
|
84 | | -\section{Reference parity} |
85 | 90 |
|
86 | | -Production use also requires a correctness check. A changed generator, tokenizer, or serialization no longer tests the mechanism from the paper, so \texttt{pptrain} includes reference-parity utilities that compare local outputs against original-source fixtures for LIME, synthetic summarization, procedural pretraining, and NCA pre-pretraining. |
| 91 | +def gpt2(vocab_size: int) -> GPT2LMHeadModel: |
| 92 | + return GPT2LMHeadModel(GPT2Config( |
| 93 | + n_layer=2, n_head=2, n_embd=64, |
| 94 | + n_positions=128, vocab_size=vocab_size, |
| 95 | + )) |
87 | 96 |
|
88 | | -These checks are exact where they should be exact: normalized examples or token sequences must match the reference output. |
89 | 97 |
|
90 | | -\section{Empirical testing} |
| 98 | +trainer = PrePreTrainer( |
| 99 | + task=create_task("dyck", {"preset": "smoke"}), |
| 100 | + model_adapter=VocabSizeCausalLMAdapter( |
| 101 | + create_prepretrain_model=gpt2, |
| 102 | + load_downstream_model=lambda: gpt2(vocab_size=50257), |
| 103 | + ), |
| 104 | + run_config=RunConfig(output_dir="runs/dyck", max_steps=20), |
| 105 | +) |
| 106 | +bundle = trainer.fit().load_transfer_bundle() |
91 | 107 |
|
92 | | -To determine whether a synthetic task transfers in a particular model and training setup, users can run the evaluation and replication utilities through the same interface used for training. The library supports downstream transfer evaluation, compute-matched natural warmups, diagnostic metrics, plots, CSVs, and Markdown reports. |
| 108 | +target_model = gpt2(vocab_size=50257) |
| 109 | +policy = SkipParametersTransferPolicy( |
| 110 | + skip_parameter_prefixes=("transformer.wte", "lm_head"), |
| 111 | +) |
| 112 | +report = policy.apply_bundle(bundle, target_model) |
| 113 | +print(report.loaded_parameter_count) |
| 114 | +\end{verbatim} |
93 | 115 |
|
94 | | -\section{Extensibility} |
| 116 | +\section{Verify and evaluate} |
95 | 117 |
|
96 | | -Users can write their own pre-pretraining logic by implementing \texttt{SymbolicTaskFamily}: define how examples are sampled, executed, serialized, and tokenized. If the task needs a custom dataset or loss path, implement \texttt{Task} directly. |
| 118 | +Reference-parity tests compare normalized examples or token sequences with fixtures produced by the original LIME, synthetic-summarization, procedural-pretraining, and NCA implementations. The replication interface compares downstream training after synthetic initialization with both random initialization and a natural-text warmup, then exports the resulting metrics, plots, tables, and reports. |
97 | 119 |
|
98 | | -The core abstraction is a task family. It samples an example, executes it if needed, serializes it into tokens, and exposes a tokenizer specification. The remaining path is ordinary model training: build a dataset, train a Hugging Face causal language model, save the checkpoint, and export a transfer bundle. |
| 120 | +A custom symbolic generator implements \texttt{SymbolicTaskFamily} by defining how an example is sampled, executed, serialized, and tokenized. A method that requires a different dataset construction or loss implements \texttt{Task} directly. |
99 | 121 |
|
100 | 122 | \end{document} |
0 commit comments