populora 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.
- populora-0.0.1/.gitignore +220 -0
- populora-0.0.1/LICENSE +21 -0
- populora-0.0.1/PKG-INFO +87 -0
- populora-0.0.1/README.md +41 -0
- populora-0.0.1/populora/__init__.py +1 -0
- populora-0.0.1/populora/populora.py +132 -0
- populora-0.0.1/pyproject.toml +69 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
uv_publish.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
|
populora-0.0.1/LICENSE
ADDED
|
@@ -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.
|
populora-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: populora
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Implementation of PopuLoRA
|
|
5
|
+
Project-URL: Homepage, https://pypi.org/project/populora/
|
|
6
|
+
Project-URL: Repository, https://codeberg.org/lucidrains/populora
|
|
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,evolution,reinforcement learning
|
|
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
|
+
Provides-Extra: examples
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pytest; extra == 'test'
|
|
44
|
+
Requires-Dist: x-transformers; extra == 'test'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
## PopuLoRA (wip)
|
|
48
|
+
|
|
49
|
+
Implementation and explorations into [PopuLoRA](https://arxiv.org/abs/2605.16727v1), [Co-Evolving LLM Populations for Reasoning Self-Play](https://vmax.ai/team/populora-co-evolving-llm-populations-for-reasoning-self-play), from Roger Castanyer et al at [vmax.ai](https://vmax.ai/)
|
|
50
|
+
|
|
51
|
+
## Citations
|
|
52
|
+
|
|
53
|
+
```bibtex
|
|
54
|
+
@misc{castanyer2026populoracoevolvingllmpopulations,
|
|
55
|
+
title = {PopuLoRA: Co-Evolving LLM Populations for Reasoning Self-Play},
|
|
56
|
+
author = {Roger Creus Castanyer and Geoffrey Bradway and Lorenz Wolf and Maxwill Lin and Augustine N. Mavor-Parker and Matthew James Sargent},
|
|
57
|
+
year = {2026},
|
|
58
|
+
eprint = {2605.16727},
|
|
59
|
+
archivePrefix = {arXiv},
|
|
60
|
+
primaryClass = {cs.AI},
|
|
61
|
+
url = {https://arxiv.org/abs/2605.16727},
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bibtex
|
|
66
|
+
@misc{schmidhuber2012powerplaytrainingincreasinglygeneral,
|
|
67
|
+
title = {POWERPLAY: Training an Increasingly General Problem Solver by Continually Searching for the Simplest Still Unsolvable Problem},
|
|
68
|
+
author = {Jürgen Schmidhuber},
|
|
69
|
+
year = {2012},
|
|
70
|
+
eprint = {1112.5309},
|
|
71
|
+
archivePrefix = {arXiv},
|
|
72
|
+
primaryClass = {cs.AI},
|
|
73
|
+
url = {https://arxiv.org/abs/1112.5309},
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bibtex
|
|
78
|
+
@misc{bahlousboldi2026vectorpolicyoptimizationtraining,
|
|
79
|
+
title = {Vector Policy Optimization: Training for Diversity Improves Test-Time Search},
|
|
80
|
+
author = {Ryan Bahlous-Boldi and Isha Puri and Idan Shenfeld and Akarsh Kumar and Mehul Damani and Sebastian Risi and Omar Khattab and Zhang-Wei Hong and Pulkit Agrawal},
|
|
81
|
+
year = {2026},
|
|
82
|
+
eprint = {2605.22817},
|
|
83
|
+
archivePrefix = {arXiv},
|
|
84
|
+
primaryClass = {cs.LG},
|
|
85
|
+
url = {https://arxiv.org/abs/2605.22817},
|
|
86
|
+
}
|
|
87
|
+
```
|
populora-0.0.1/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
## PopuLoRA (wip)
|
|
2
|
+
|
|
3
|
+
Implementation and explorations into [PopuLoRA](https://arxiv.org/abs/2605.16727v1), [Co-Evolving LLM Populations for Reasoning Self-Play](https://vmax.ai/team/populora-co-evolving-llm-populations-for-reasoning-self-play), from Roger Castanyer et al at [vmax.ai](https://vmax.ai/)
|
|
4
|
+
|
|
5
|
+
## Citations
|
|
6
|
+
|
|
7
|
+
```bibtex
|
|
8
|
+
@misc{castanyer2026populoracoevolvingllmpopulations,
|
|
9
|
+
title = {PopuLoRA: Co-Evolving LLM Populations for Reasoning Self-Play},
|
|
10
|
+
author = {Roger Creus Castanyer and Geoffrey Bradway and Lorenz Wolf and Maxwill Lin and Augustine N. Mavor-Parker and Matthew James Sargent},
|
|
11
|
+
year = {2026},
|
|
12
|
+
eprint = {2605.16727},
|
|
13
|
+
archivePrefix = {arXiv},
|
|
14
|
+
primaryClass = {cs.AI},
|
|
15
|
+
url = {https://arxiv.org/abs/2605.16727},
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bibtex
|
|
20
|
+
@misc{schmidhuber2012powerplaytrainingincreasinglygeneral,
|
|
21
|
+
title = {POWERPLAY: Training an Increasingly General Problem Solver by Continually Searching for the Simplest Still Unsolvable Problem},
|
|
22
|
+
author = {Jürgen Schmidhuber},
|
|
23
|
+
year = {2012},
|
|
24
|
+
eprint = {1112.5309},
|
|
25
|
+
archivePrefix = {arXiv},
|
|
26
|
+
primaryClass = {cs.AI},
|
|
27
|
+
url = {https://arxiv.org/abs/1112.5309},
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bibtex
|
|
32
|
+
@misc{bahlousboldi2026vectorpolicyoptimizationtraining,
|
|
33
|
+
title = {Vector Policy Optimization: Training for Diversity Improves Test-Time Search},
|
|
34
|
+
author = {Ryan Bahlous-Boldi and Isha Puri and Idan Shenfeld and Akarsh Kumar and Mehul Damani and Sebastian Risi and Omar Khattab and Zhang-Wei Hong and Pulkit Agrawal},
|
|
35
|
+
year = {2026},
|
|
36
|
+
eprint = {2605.22817},
|
|
37
|
+
archivePrefix = {arXiv},
|
|
38
|
+
primaryClass = {cs.LG},
|
|
39
|
+
url = {https://arxiv.org/abs/2605.22817},
|
|
40
|
+
}
|
|
41
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from populora.populora import PopuLoRA
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from torch.nn import Linear, Module, Parameter, ParameterDict, init
|
|
5
|
+
|
|
6
|
+
from einops import einsum, repeat, rearrange
|
|
7
|
+
from torch_einops_utils import tree_map_tensor
|
|
8
|
+
|
|
9
|
+
from contextlib import contextmanager
|
|
10
|
+
|
|
11
|
+
# helpers
|
|
12
|
+
|
|
13
|
+
def exists(v):
|
|
14
|
+
return v is not None
|
|
15
|
+
|
|
16
|
+
# main class
|
|
17
|
+
|
|
18
|
+
class PopuLoRA(Module):
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
model: Module,
|
|
22
|
+
*,
|
|
23
|
+
pop_size: int,
|
|
24
|
+
low_rank: int,
|
|
25
|
+
lora_targets: tuple[str, ...] | list[str],
|
|
26
|
+
requires_grad: bool = False
|
|
27
|
+
):
|
|
28
|
+
super().__init__()
|
|
29
|
+
self.model = model
|
|
30
|
+
self.pop_size = pop_size
|
|
31
|
+
|
|
32
|
+
self.w_down = ParameterDict()
|
|
33
|
+
self.w_up = ParameterDict()
|
|
34
|
+
self._hooks = []
|
|
35
|
+
|
|
36
|
+
for path in lora_targets:
|
|
37
|
+
linear = model.get_submodule(path)
|
|
38
|
+
assert isinstance(linear, Linear), f'{path} must point to a Linear module'
|
|
39
|
+
|
|
40
|
+
key = path.replace('.', '_')
|
|
41
|
+
dim, dim_inner = linear.in_features, linear.out_features
|
|
42
|
+
|
|
43
|
+
self.w_down[key] = Parameter(torch.empty(pop_size, dim, low_rank), requires_grad = requires_grad)
|
|
44
|
+
self.w_up[key] = Parameter(torch.empty(pop_size, dim_inner, low_rank), requires_grad = requires_grad)
|
|
45
|
+
|
|
46
|
+
init.normal_(self.w_down[key], std = dim ** -0.5)
|
|
47
|
+
init.normal_(self.w_up[key], std = low_rank ** -0.5)
|
|
48
|
+
|
|
49
|
+
self._hooks.append(linear.register_forward_hook(self._create_hook(key)))
|
|
50
|
+
|
|
51
|
+
self._individual = None
|
|
52
|
+
|
|
53
|
+
@contextmanager
|
|
54
|
+
def _route(self, individual, individuals, all_individuals):
|
|
55
|
+
assert sum((exists(individual), exists(individuals), all_individuals)) <= 1
|
|
56
|
+
|
|
57
|
+
if all_individuals:
|
|
58
|
+
individual = ...
|
|
59
|
+
elif exists(individuals):
|
|
60
|
+
individual = list(individuals)
|
|
61
|
+
|
|
62
|
+
self._individual = individual
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
yield
|
|
66
|
+
finally:
|
|
67
|
+
self._individual = None
|
|
68
|
+
|
|
69
|
+
@contextmanager
|
|
70
|
+
def _eval_and_no_grad(self, enabled):
|
|
71
|
+
if not enabled:
|
|
72
|
+
yield
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
is_training = self.training
|
|
76
|
+
self.eval()
|
|
77
|
+
|
|
78
|
+
with torch.no_grad():
|
|
79
|
+
try:
|
|
80
|
+
yield
|
|
81
|
+
finally:
|
|
82
|
+
self.train(is_training)
|
|
83
|
+
|
|
84
|
+
def _create_hook(self, lora_key: str):
|
|
85
|
+
def hook(_, args, output):
|
|
86
|
+
if not exists(self._individual) and self._individual is not ...:
|
|
87
|
+
return output
|
|
88
|
+
|
|
89
|
+
w_down, w_up = self.w_down[lora_key], self.w_up[lora_key]
|
|
90
|
+
x, = args
|
|
91
|
+
|
|
92
|
+
if isinstance(self._individual, list) or self._individual is ...:
|
|
93
|
+
w_down_i, w_up_i = w_down[self._individual], w_up[self._individual]
|
|
94
|
+
p = w_down_i.shape[0]
|
|
95
|
+
|
|
96
|
+
x = rearrange(x, '(p b) ... -> p b ...', p = p)
|
|
97
|
+
lora_out = einsum(x, w_down_i, w_up_i, 'p b ... d, p d r, p e r -> p b ... e')
|
|
98
|
+
lora_out = rearrange(lora_out, 'p b ... -> (p b) ...')
|
|
99
|
+
else:
|
|
100
|
+
lora_out = einsum(x, w_down[self._individual], w_up[self._individual], '... d, d r, e r -> ... e')
|
|
101
|
+
|
|
102
|
+
return output + lora_out
|
|
103
|
+
|
|
104
|
+
return hook
|
|
105
|
+
|
|
106
|
+
def forward(
|
|
107
|
+
self,
|
|
108
|
+
*args,
|
|
109
|
+
individual: int | None = None,
|
|
110
|
+
individuals: tuple[int, ...] | list[int] | None = None,
|
|
111
|
+
all_individuals: bool = False,
|
|
112
|
+
ignore_args_kwargs: tuple[int | str, ...] = tuple(),
|
|
113
|
+
eval_and_no_grad: bool = False,
|
|
114
|
+
**kwargs
|
|
115
|
+
):
|
|
116
|
+
if all_individuals or exists(individuals):
|
|
117
|
+
ignore = set(ignore_args_kwargs)
|
|
118
|
+
p = self.pop_size if all_individuals else len(individuals)
|
|
119
|
+
repeat_batch = lambda t: repeat(t, 'b ... -> (p b) ...', p = p)
|
|
120
|
+
|
|
121
|
+
args = tuple(
|
|
122
|
+
tree_map_tensor(repeat_batch, a) if i not in ignore else a
|
|
123
|
+
for i, a in enumerate(args)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
kwargs = {
|
|
127
|
+
k: tree_map_tensor(repeat_batch, v) if k not in ignore else v
|
|
128
|
+
for k, v in kwargs.items()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
with self._route(individual, individuals, all_individuals), self._eval_and_no_grad(eval_and_no_grad):
|
|
132
|
+
return self.model(*args, **kwargs)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "populora"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Implementation of PopuLoRA"
|
|
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
|
+
'reinforcement learning',
|
|
15
|
+
'evolution',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Development Status :: 4 - Beta',
|
|
20
|
+
'Intended Audience :: Developers',
|
|
21
|
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
|
22
|
+
'License :: OSI Approved :: MIT License',
|
|
23
|
+
'Programming Language :: Python :: 3.10',
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
dependencies = [
|
|
27
|
+
"einx>=0.3.0",
|
|
28
|
+
"einops>=0.8.1",
|
|
29
|
+
"torch>=2.5",
|
|
30
|
+
"torch-einops-utils>=0.0.29",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://pypi.org/project/populora/"
|
|
35
|
+
Repository = "https://codeberg.org/lucidrains/populora"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
examples = []
|
|
39
|
+
test = [
|
|
40
|
+
"pytest",
|
|
41
|
+
"x-transformers"
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
pythonpath = [
|
|
46
|
+
"."
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["hatchling"]
|
|
51
|
+
build-backend = "hatchling.build"
|
|
52
|
+
|
|
53
|
+
[tool.rye]
|
|
54
|
+
managed = true
|
|
55
|
+
dev-dependencies = []
|
|
56
|
+
|
|
57
|
+
[tool.hatch.metadata]
|
|
58
|
+
allow-direct-references = true
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build]
|
|
61
|
+
include = [
|
|
62
|
+
"populora",
|
|
63
|
+
"pyproject.toml",
|
|
64
|
+
"README.md",
|
|
65
|
+
"LICENSE"
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.hatch.build.targets.wheel]
|
|
69
|
+
packages = ["populora"]
|