self-play-pretrain-zero-data 0.0.1__py3-none-any.whl
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.
- self_play_pretrain_zero_data/__init__.py +6 -0
- self_play_pretrain_zero_data/brainfuck.py +96 -0
- self_play_pretrain_zero_data/self_play.py +42 -0
- self_play_pretrain_zero_data-0.0.1.dist-info/METADATA +77 -0
- self_play_pretrain_zero_data-0.0.1.dist-info/RECORD +7 -0
- self_play_pretrain_zero_data-0.0.1.dist-info/WHEEL +4 -0
- self_play_pretrain_zero_data-0.0.1.dist-info/licenses/LICENSE +21 -0
|
@@ -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
|
|
@@ -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,7 @@
|
|
|
1
|
+
self_play_pretrain_zero_data/__init__.py,sha256=lT_TuvY_Z9sLWo62lXWI-ceLjCGaxOgCELddidon5cM,151
|
|
2
|
+
self_play_pretrain_zero_data/brainfuck.py,sha256=edAtQOIpG5ggkb5J76eJx1O_HopVWvPp9AgYX7VyiwI,2627
|
|
3
|
+
self_play_pretrain_zero_data/self_play.py,sha256=c1K2bwfoaxyvaHeqfJc_4899xaslM4F05KnJDZ8ib7A,978
|
|
4
|
+
self_play_pretrain_zero_data-0.0.1.dist-info/METADATA,sha256=3Pq10qGXgwNBT4SlcEMMCxjowl2R_sul36clK-3rRuk,3209
|
|
5
|
+
self_play_pretrain_zero_data-0.0.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
6
|
+
self_play_pretrain_zero_data-0.0.1.dist-info/licenses/LICENSE,sha256=e6AOF7Z8EFdK3IdcL0x0fLw4cY7Q0d0kNR0o0TmBewM,1066
|
|
7
|
+
self_play_pretrain_zero_data-0.0.1.dist-info/RECORD,,
|
|
@@ -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.
|