hippoformer 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,36 @@
1
+ # This workflow will upload a Python Package using Twine when a release is created
2
+ # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ jobs:
16
+ deploy:
17
+
18
+ runs-on: ubuntu-latest
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v2
24
+ with:
25
+ python-version: '3.x'
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install build
30
+ - name: Build package
31
+ run: python -m build
32
+ - name: Publish package
33
+ uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
34
+ with:
35
+ user: __token__
36
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,21 @@
1
+ name: Pytest
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ build:
6
+
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - name: Set up Python 3.10
12
+ uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.10"
15
+ - name: Install dependencies
16
+ run: |
17
+ python -m pip install --upgrade pip
18
+ python -m pip install -e .[test]
19
+ - name: Test with pytest
20
+ run: |
21
+ python -m pytest tests/
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 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,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: hippoformer
3
+ Version: 0.0.1
4
+ Summary: hippoformer
5
+ Project-URL: Homepage, https://pypi.org/project/hippoformer/
6
+ Project-URL: Repository, https://github.com/lucidrains/hippoformer
7
+ Author-email: Phil Wang <lucidrains@gmail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2025 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,hippocampus,memory
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
36
+ Requires-Python: >=3.9
37
+ Requires-Dist: assoc-scan
38
+ Requires-Dist: einops>=0.8.1
39
+ Requires-Dist: torch>=2.4
40
+ Requires-Dist: x-mlps-pytorch
41
+ Provides-Extra: examples
42
+ Provides-Extra: test
43
+ Requires-Dist: pytest; extra == 'test'
44
+ Description-Content-Type: text/markdown
45
+
46
+ <img src="./hippoformer-fig6.png" width="400px"></img>
47
+
48
+ ## Hippoformer (wip)
49
+
50
+ Implementation of [Hippoformer](https://openreview.net/forum?id=hxwV5EubAw), Integrating Hippocampus-inspired Spatial Memory with Transformers
51
+
52
+ [Temporary Discord](https://discord.gg/MkACrrkrYR)
53
+
54
+ ## Citations
55
+
56
+ ```bibtex
57
+ @inproceedings{anonymous2025hippoformer,
58
+ title = {Hippoformer: Integrating Hippocampus-inspired Spatial Memory with Transformers},
59
+ author = {Anonymous},
60
+ booktitle = {Submitted to The Fourteenth International Conference on Learning Representations},
61
+ year = {2025},
62
+ url = {https://openreview.net/forum?id=hxwV5EubAw},
63
+ note = {under review}
64
+ }
65
+ ```
@@ -0,0 +1,20 @@
1
+ <img src="./hippoformer-fig6.png" width="400px"></img>
2
+
3
+ ## Hippoformer (wip)
4
+
5
+ Implementation of [Hippoformer](https://openreview.net/forum?id=hxwV5EubAw), Integrating Hippocampus-inspired Spatial Memory with Transformers
6
+
7
+ [Temporary Discord](https://discord.gg/MkACrrkrYR)
8
+
9
+ ## Citations
10
+
11
+ ```bibtex
12
+ @inproceedings{anonymous2025hippoformer,
13
+ title = {Hippoformer: Integrating Hippocampus-inspired Spatial Memory with Transformers},
14
+ author = {Anonymous},
15
+ booktitle = {Submitted to The Fourteenth International Conference on Learning Representations},
16
+ year = {2025},
17
+ url = {https://openreview.net/forum?id=hxwV5EubAw},
18
+ note = {under review}
19
+ }
20
+ ```
File without changes
@@ -0,0 +1,116 @@
1
+ from __future__ import annotations
2
+
3
+ import torch
4
+ from torch import nn, Tensor, stack, einsum
5
+ import torch.nn.functional as F
6
+ from torch.nn import Module
7
+ from torch.jit import ScriptModule, script_method
8
+
9
+ from einops import repeat, rearrange
10
+ from einops.layers.torch import Rearrange
11
+
12
+ from x_mlps_pytorch import create_mlp
13
+
14
+ from assoc_scan import AssocScan
15
+
16
+ # helpers
17
+
18
+ def exists(v):
19
+ return v is not None
20
+
21
+ def default(v, d):
22
+ return v if exists(v) else d
23
+
24
+ def l2norm(t):
25
+ return F.normalize(t, dim = -1)
26
+
27
+ # path integration
28
+
29
+ class RNN(ScriptModule):
30
+ def __init__(
31
+ self,
32
+ dim,
33
+ ):
34
+ super().__init__()
35
+ self.init_hidden = nn.Parameter(torch.randn(1, dim) * 1e-2)
36
+
37
+ @script_method
38
+ def forward(
39
+ self,
40
+ transitions: Tensor,
41
+ hidden: Tensor | None = None
42
+ ) -> Tensor:
43
+
44
+ batch, seq_len = transitions.shape[:2]
45
+
46
+ if hidden is None:
47
+ hidden = l2norm(self.init_hidden)
48
+ hidden = hidden.expand(batch, -1)
49
+
50
+ hiddens: list[Tensor] = []
51
+
52
+ for i in range(seq_len):
53
+ transition = transitions[:, i]
54
+
55
+ hidden = einsum('b i, b i j -> b j', hidden, transition)
56
+ hidden = F.relu(hidden)
57
+ hidden = l2norm(hidden)
58
+
59
+ hiddens.append(hidden)
60
+
61
+ return stack(hiddens, dim = 1)
62
+
63
+ class PathIntegration(Module):
64
+ def __init__(
65
+ self,
66
+ dim_action,
67
+ dim_structure,
68
+ mlp_hidden_dim = None,
69
+ mlp_depth = 2
70
+ ):
71
+ # they use the same approach from Ruiqi Gao's paper from 2021
72
+ super().__init__()
73
+
74
+ self.init_structure = nn.Parameter(torch.randn(dim_structure))
75
+
76
+ self.to_transitions = create_mlp(
77
+ default(mlp_hidden_dim, dim_action * 4),
78
+ dim_in = dim_action,
79
+ dim_out = dim_structure * dim_structure,
80
+ depth = mlp_depth
81
+ )
82
+
83
+ self.mlp_out_to_weights = Rearrange('... (i j) -> ... i j', j = dim_structure)
84
+
85
+ self.rnn = RNN(dim_structure)
86
+
87
+ def forward(
88
+ self,
89
+ actions, # (b n d)
90
+ prev_structural = None # (b n d) | (b d)
91
+ ):
92
+ batch = actions.shape[0]
93
+
94
+ transitions = self.to_transitions(actions)
95
+ transitions = self.mlp_out_to_weights(transitions)
96
+
97
+ if exists(prev_structural) and prev_structural.ndim == 3:
98
+ prev_structural = prev_structural[:, -1]
99
+
100
+ return self.rnn(transitions, prev_structural)
101
+
102
+ # proposed mmTEM
103
+
104
+ class mmTEM(Module):
105
+ def __init__(
106
+ self,
107
+ dim
108
+ ):
109
+ super().__init__()
110
+
111
+
112
+ def forward(
113
+ self,
114
+ data
115
+ ):
116
+ raise NotImplementedError
Binary file
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "hippoformer"
3
+ version = "0.0.1"
4
+ description = "hippoformer"
5
+ authors = [
6
+ { name = "Phil Wang", email = "lucidrains@gmail.com" }
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">= 3.9"
10
+ license = { file = "LICENSE" }
11
+ keywords = [
12
+ 'artificial intelligence',
13
+ 'deep learning',
14
+ 'memory',
15
+ 'hippocampus'
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.9',
24
+ ]
25
+
26
+ dependencies = [
27
+ "assoc-scan",
28
+ "einops>=0.8.1",
29
+ "torch>=2.4",
30
+ "x-mlps-pytorch",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://pypi.org/project/hippoformer/"
35
+ Repository = "https://github.com/lucidrains/hippoformer"
36
+
37
+ [project.optional-dependencies]
38
+ examples = []
39
+ test = [
40
+ "pytest"
41
+ ]
42
+
43
+ [tool.pytest.ini_options]
44
+ pythonpath = [
45
+ "."
46
+ ]
47
+
48
+ [build-system]
49
+ requires = ["hatchling"]
50
+ build-backend = "hatchling.build"
51
+
52
+ [tool.rye]
53
+ managed = true
54
+ dev-dependencies = []
55
+
56
+ [tool.hatch.metadata]
57
+ allow-direct-references = true
58
+
59
+ [tool.hatch.build.targets.wheel]
60
+ packages = ["hippoformer"]
@@ -0,0 +1,15 @@
1
+ import pytest
2
+
3
+ import torch
4
+
5
+ def test_path_integrate():
6
+ from hippoformer.hippoformer import PathIntegration
7
+
8
+ path_integrator = PathIntegration(32, 64)
9
+
10
+ actions = torch.randn(2, 16, 32)
11
+
12
+ structure_codes = path_integrator(actions)
13
+ structure_codes = path_integrator(actions, structure_codes) # pass in previous structure codes, it will auto use the last one as hidden and pass it to the RNN
14
+
15
+ assert structure_codes.shape == (2, 16, 64)