self-play-pretrain-zero-data 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,220 @@
1
+ *.sh
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[codz]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py.cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ # Pipfile.lock
98
+
99
+ # UV
100
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # uv.lock
104
+
105
+ # poetry
106
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
107
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
108
+ # commonly ignored for libraries.
109
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
110
+ # poetry.lock
111
+ # poetry.toml
112
+
113
+ # pdm
114
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
115
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
116
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
117
+ # pdm.lock
118
+ # pdm.toml
119
+ .pdm-python
120
+ .pdm-build/
121
+
122
+ # pixi
123
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
124
+ # pixi.lock
125
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
126
+ # in the .venv directory. It is recommended not to include this directory in version control.
127
+ .pixi
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
201
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
203
+ # you could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phil Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.5
2
+ Name: self-play-pretrain-zero-data
3
+ Version: 0.0.1
4
+ Summary: Implementation of Self-Play Pretraining with Zero Data
5
+ Project-URL: Homepage, https://pypi.org/project/self-play-pretrain-zero-data/
6
+ Project-URL: Repository, https://github.com/lucidrains/self-play-pretrain-zero-data
7
+ Author-email: Phil Wang <lucidrains@gmail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Phil Wang
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: artificial intelligence,deep learning,pretraining,self-play,synthetic data
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
36
+ Requires-Python: >=3.10
37
+ Requires-Dist: einops>=0.8.1
38
+ Requires-Dist: einx>=0.3.0
39
+ Requires-Dist: torch-einops-utils>=0.0.29
40
+ Requires-Dist: torch>=2.5
41
+ Requires-Dist: x-transformers
42
+ Provides-Extra: examples
43
+ Provides-Extra: test
44
+ Requires-Dist: pytest; extra == 'test'
45
+ Description-Content-Type: text/markdown
46
+
47
+ ## self-play-pretrain-zero-data (wip)
48
+
49
+ Implementation of [Self-Play Pretraining with Zero Data](https://arxiv.org/abs/2609.30063)
50
+
51
+ [Paper Review from @hu-po](https://www.youtube.com/watch?v=mGMiiPpWBSo)
52
+
53
+ ## Citations
54
+
55
+ ```bibtex
56
+ @misc{cowsik2026selfplaypretrainingzerodata,
57
+ title = {Self-Play Pretraining with Zero Data},
58
+ author = {Aditya Cowsik and Kfir Dolev and Michael Y. Li and G. Bruno De Luca and Nourya Cohen and Noah D. Goodman and Yoav Levine},
59
+ year = {2026},
60
+ eprint = {2609.30063},
61
+ archivePrefix = {arXiv},
62
+ primaryClass = {cs.AI},
63
+ url = {https://arxiv.org/abs/2609.30063},
64
+ }
65
+ ```
66
+
67
+ ```bibtex
68
+ @misc{bloem2025universalpretrainingiteratedrandom,
69
+ title = {Universal pre-training by iterated random computation},
70
+ author = {Peter Bloem},
71
+ year = {2025},
72
+ eprint = {2506.20057},
73
+ archivePrefix = {arXiv},
74
+ primaryClass = {cs.LG},
75
+ url = {https://arxiv.org/abs/2506.20057},
76
+ }
77
+ ```
@@ -0,0 +1,31 @@
1
+ ## self-play-pretrain-zero-data (wip)
2
+
3
+ Implementation of [Self-Play Pretraining with Zero Data](https://arxiv.org/abs/2609.30063)
4
+
5
+ [Paper Review from @hu-po](https://www.youtube.com/watch?v=mGMiiPpWBSo)
6
+
7
+ ## Citations
8
+
9
+ ```bibtex
10
+ @misc{cowsik2026selfplaypretrainingzerodata,
11
+ title = {Self-Play Pretraining with Zero Data},
12
+ author = {Aditya Cowsik and Kfir Dolev and Michael Y. Li and G. Bruno De Luca and Nourya Cohen and Noah D. Goodman and Yoav Levine},
13
+ year = {2026},
14
+ eprint = {2609.30063},
15
+ archivePrefix = {arXiv},
16
+ primaryClass = {cs.AI},
17
+ url = {https://arxiv.org/abs/2609.30063},
18
+ }
19
+ ```
20
+
21
+ ```bibtex
22
+ @misc{bloem2025universalpretrainingiteratedrandom,
23
+ title = {Universal pre-training by iterated random computation},
24
+ author = {Peter Bloem},
25
+ year = {2025},
26
+ eprint = {2506.20057},
27
+ archivePrefix = {arXiv},
28
+ primaryClass = {cs.LG},
29
+ url = {https://arxiv.org/abs/2506.20057},
30
+ }
31
+ ```
@@ -0,0 +1,63 @@
1
+ [project]
2
+ name = "self-play-pretrain-zero-data"
3
+ version = "0.0.1"
4
+ description = "Implementation of Self-Play Pretraining with Zero Data"
5
+ authors = [
6
+ { name = "Phil Wang", email = "lucidrains@gmail.com" }
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">= 3.10"
10
+ license = { file = "LICENSE" }
11
+ keywords = [
12
+ 'artificial intelligence',
13
+ 'deep learning',
14
+ 'self-play',
15
+ 'pretraining',
16
+ 'synthetic data'
17
+ ]
18
+
19
+ classifiers=[
20
+ 'Development Status :: 4 - Beta',
21
+ 'Intended Audience :: Developers',
22
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
23
+ 'License :: OSI Approved :: MIT License',
24
+ 'Programming Language :: Python :: 3.10',
25
+ ]
26
+
27
+ dependencies = [
28
+ "einx>=0.3.0",
29
+ "einops>=0.8.1",
30
+ "torch>=2.5",
31
+ "torch-einops-utils>=0.0.29",
32
+ "x-transformers"
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://pypi.org/project/self-play-pretrain-zero-data/"
37
+ Repository = "https://github.com/lucidrains/self-play-pretrain-zero-data"
38
+
39
+ [project.optional-dependencies]
40
+ examples = []
41
+ test = [
42
+ "pytest"
43
+ ]
44
+
45
+ [tool.pytest.ini_options]
46
+ pythonpath = [
47
+ "."
48
+ ]
49
+
50
+ [build-system]
51
+ requires = ["hatchling"]
52
+ build-backend = "hatchling.build"
53
+
54
+ [tool.hatch.build]
55
+ include = [
56
+ "self_play_pretrain_zero_data",
57
+ "pyproject.toml",
58
+ "README.md",
59
+ "LICENSE"
60
+ ]
61
+
62
+ [tool.hatch.build.targets.wheel]
63
+ packages = ["self_play_pretrain_zero_data"]
@@ -0,0 +1,6 @@
1
+ from self_play_pretrain_zero_data.self_play import (
2
+ SelfPlay,
3
+ ProgramExecutor
4
+ )
5
+
6
+ from self_play_pretrain_zero_data.brainfuck import Brainfuck
@@ -0,0 +1,96 @@
1
+ from __future__ import annotations
2
+
3
+ import random
4
+ from itertools import chain, repeat
5
+
6
+ from self_play_pretrain_zero_data.self_play import ProgramExecutor
7
+
8
+ # single byte macro instructions from appendix E (table 4)
9
+
10
+ MACROS = {
11
+ 'Z': '[-]',
12
+ 'R': '[->+<]',
13
+ 'L': '[->+++<]',
14
+ 'N': '[-<->]',
15
+ 'C': '[->+>+<<]',
16
+ 'G': '[>]',
17
+ 'H': '[<]',
18
+ 'W': '[[-]>+<]',
19
+ 'V': '[.>]',
20
+ 'X': '[-]++++++++++++++++',
21
+ }
22
+
23
+
24
+ def bracket_jumps(code):
25
+ jumps, stack = {}, []
26
+
27
+ for i, c in enumerate(code):
28
+ if c == '[':
29
+ stack.append(i)
30
+ elif c == ']' and stack:
31
+ left = stack.pop()
32
+ jumps[left] = i
33
+ jumps[i] = left
34
+
35
+ return jumps
36
+
37
+ class Brainfuck(ProgramExecutor):
38
+ """appendix E execution semantics - every string is executable
39
+
40
+ - circular tape, cells modulo `modulus`
41
+ - unmatched brackets are no-ops
42
+ - `,` reads the input string, then uniform random bytes (random input tape omega)
43
+ - halts at `F`, the step budget, or the output cap
44
+ """
45
+
46
+ def __init__(
47
+ self,
48
+ tape_size = 1024,
49
+ modulus = 256,
50
+ max_steps = 100_000,
51
+ max_output_len = 1024
52
+ ):
53
+ self.tape_size = tape_size
54
+ self.modulus = modulus
55
+ self.max_steps = max_steps
56
+ self.max_output_len = max_output_len
57
+
58
+ def __call__(
59
+ self,
60
+ program: str,
61
+ input: str | bytes = '',
62
+ seed: int | None = None
63
+ ) -> str:
64
+ rng = random.Random(seed)
65
+
66
+ code = ''.join(MACROS.get(c, c) for c in program.partition('F')[0])
67
+ jumps = bracket_jumps(code)
68
+
69
+ input_bytes = input.encode('latin-1') if isinstance(input, str) else input
70
+
71
+ reads = chain(
72
+ (b % self.modulus for b in input_bytes),
73
+ (rng.randrange(self.modulus) for _ in repeat(None))
74
+ )
75
+
76
+ tape = [0] * self.tape_size
77
+ out = bytearray()
78
+ pc = ptr = 0
79
+
80
+ for _ in range(self.max_steps):
81
+ if pc >= len(code) or len(out) >= self.max_output_len:
82
+ break
83
+
84
+ match code[pc]:
85
+ case '>': ptr = (ptr + 1) % self.tape_size
86
+ case '<': ptr = (ptr - 1) % self.tape_size
87
+ case '+': tape[ptr] = (tape[ptr] + 1) % self.modulus
88
+ case '-': tape[ptr] = (tape[ptr] - 1) % self.modulus
89
+ case '.': out.append(tape[ptr])
90
+ case ',': tape[ptr] = next(reads)
91
+ case '[' if not tape[ptr]: pc = jumps.get(pc, pc)
92
+ case ']' if tape[ptr]: pc = jumps.get(pc, pc)
93
+
94
+ pc += 1
95
+
96
+ return out.decode('latin-1')
@@ -0,0 +1,42 @@
1
+ from __future__ import annotations
2
+ from typing import Iterable
3
+ from abc import ABC, abstractmethod
4
+
5
+ from torch.nn import Module
6
+
7
+ # executor
8
+
9
+ class ProgramExecutor(ABC):
10
+ """maps a program string to its output string"""
11
+
12
+ @abstractmethod
13
+ def __call__(self, program: str, **kwargs) -> str:
14
+ raise NotImplementedError
15
+
16
+ # main class
17
+
18
+ class SelfPlay(Module):
19
+ def __init__(
20
+ self,
21
+ generator: Module,
22
+ learner: Module,
23
+ executor: ProgramExecutor
24
+ ):
25
+ super().__init__()
26
+ self.generator = generator
27
+ self.learner = learner
28
+ self.executor = executor
29
+
30
+ def execute(
31
+ self,
32
+ programs: str | Iterable[str],
33
+ **kwargs
34
+ ) -> str | list[str]:
35
+
36
+ if isinstance(programs, str):
37
+ return self.executor(programs, **kwargs)
38
+
39
+ return [self.executor(program, **kwargs) for program in programs]
40
+
41
+ def forward(self, *args, **kwargs):
42
+ raise NotImplementedError