jepa-science 0.1.0__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.
- jepa_science-0.1.0/.gitignore +12 -0
- jepa_science-0.1.0/CITATION.cff +39 -0
- jepa_science-0.1.0/LICENSE +202 -0
- jepa_science-0.1.0/NOTICE +35 -0
- jepa_science-0.1.0/PKG-INFO +189 -0
- jepa_science-0.1.0/README.md +160 -0
- jepa_science-0.1.0/SPEC.md +197 -0
- jepa_science-0.1.0/docs/make_figure.py +66 -0
- jepa_science-0.1.0/docs/not_collapse.png +0 -0
- jepa_science-0.1.0/jepa_science/__init__.py +13 -0
- jepa_science-0.1.0/jepa_science/py.typed +0 -0
- jepa_science-0.1.0/jepa_science/sigreg.py +243 -0
- jepa_science-0.1.0/lejepa_lite/__init__.py +5 -0
- jepa_science-0.1.0/lejepa_lite/train.py +326 -0
- jepa_science-0.1.0/notebooks/lejepa_colab.ipynb +89 -0
- jepa_science-0.1.0/pyproject.toml +51 -0
- jepa_science-0.1.0/run_all.py +125 -0
- jepa_science-0.1.0/tests/__init__.py +0 -0
- jepa_science-0.1.0/tests/_oracle.py +37 -0
- jepa_science-0.1.0/tests/test_lejepa_lite.py +18 -0
- jepa_science-0.1.0/tests/test_sigreg.py +242 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: >-
|
|
3
|
+
This package implements the SIGReg method from the LeJEPA paper. If you use it,
|
|
4
|
+
please cite the paper below (and, optionally, this software implementation).
|
|
5
|
+
title: "jepa_science: a standalone PyTorch implementation of SIGReg (LeJEPA)"
|
|
6
|
+
type: software
|
|
7
|
+
license: Apache-2.0
|
|
8
|
+
repository-code: "https://github.com/gabsalvo/jepa_science"
|
|
9
|
+
abstract: >-
|
|
10
|
+
A clean, standalone PyTorch implementation of Sketched Isotropic Gaussian
|
|
11
|
+
Regularization (SIGReg) plus a minimal, annotated LeJEPA training demo on
|
|
12
|
+
CIFAR-10. Implemented clean-room from the paper's mathematics.
|
|
13
|
+
references:
|
|
14
|
+
- type: article
|
|
15
|
+
title: >-
|
|
16
|
+
LeJEPA: Provable and Scalable Self-Supervised Learning Without the
|
|
17
|
+
Heuristics
|
|
18
|
+
authors:
|
|
19
|
+
- family-names: Balestriero
|
|
20
|
+
given-names: Randall
|
|
21
|
+
- family-names: LeCun
|
|
22
|
+
given-names: Yann
|
|
23
|
+
year: 2025
|
|
24
|
+
identifiers:
|
|
25
|
+
- type: other
|
|
26
|
+
value: "arXiv:2511.08544"
|
|
27
|
+
description: arXiv preprint
|
|
28
|
+
url: "https://arxiv.org/abs/2511.08544"
|
|
29
|
+
preferred-citation:
|
|
30
|
+
type: article
|
|
31
|
+
title: >-
|
|
32
|
+
LeJEPA: Provable and Scalable Self-Supervised Learning Without the Heuristics
|
|
33
|
+
authors:
|
|
34
|
+
- family-names: Balestriero
|
|
35
|
+
given-names: Randall
|
|
36
|
+
- family-names: LeCun
|
|
37
|
+
given-names: Yann
|
|
38
|
+
year: 2025
|
|
39
|
+
url: "https://arxiv.org/abs/2511.08544"
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
jepa_science
|
|
2
|
+
Copyright 2026 jepa_science contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
------------------------------------------------------------------------------
|
|
7
|
+
Provenance and attribution
|
|
8
|
+
------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
This package is an independent, clean-room implementation of the method
|
|
11
|
+
"Sketched Isotropic Gaussian Regularization" (SIGReg) described in:
|
|
12
|
+
|
|
13
|
+
Randall Balestriero and Yann LeCun.
|
|
14
|
+
"LeJEPA: Provable and Scalable Self-Supervised Learning Without the
|
|
15
|
+
Heuristics." arXiv:2511.08544 (2025). https://arxiv.org/abs/2511.08544
|
|
16
|
+
|
|
17
|
+
The code in this repository was written from the mathematical description in
|
|
18
|
+
that paper (the SIGReg objective, the hyperspherical Cramer-Wold reduction, the
|
|
19
|
+
Epps-Pulley characteristic-function statistic, and trapezoidal quadrature).
|
|
20
|
+
Mathematical methods, algorithms, and statistical tests are not themselves
|
|
21
|
+
subject to copyright; this is an original expression of them.
|
|
22
|
+
|
|
23
|
+
We deliberately did NOT copy code from the authors' reference implementation at
|
|
24
|
+
https://github.com/rbalestr-lab/lejepa. At the time of writing, that repository
|
|
25
|
+
ships a LICENSE file under Creative Commons Attribution-NonCommercial 4.0
|
|
26
|
+
(CC BY-NC 4.0) -- a NonCommercial license -- even though its pyproject.toml
|
|
27
|
+
declares "MIT". Those signals conflict, and a NonCommercial term is incompatible
|
|
28
|
+
with this package's permissive Apache-2.0 license. To avoid any licensing
|
|
29
|
+
ambiguity, none of that repository's code was reproduced here; only the
|
|
30
|
+
publicly described method (from the paper) was implemented.
|
|
31
|
+
|
|
32
|
+
The paper itself is distributed under CC BY 4.0 / CC BY-SA 4.0 on arXiv; this
|
|
33
|
+
implementation reuses the method it describes, not its prose.
|
|
34
|
+
|
|
35
|
+
If you use this software, please cite the LeJEPA paper (see CITATION.cff).
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jepa-science
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sketched Isotropic Gaussian Regularization (SIGReg) from LeJEPA — a clean, standalone PyTorch primitive.
|
|
5
|
+
Project-URL: Homepage, https://github.com/gabsalvo/jepa_science
|
|
6
|
+
Project-URL: Paper, https://arxiv.org/abs/2511.08544
|
|
7
|
+
Project-URL: Reference implementation, https://github.com/rbalestr-lab/lejepa
|
|
8
|
+
Author: jepa_science contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: jepa,lejepa,pytorch,representation-learning,self-supervised-learning,sigreg
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Requires-Dist: numpy>=1.23
|
|
21
|
+
Requires-Dist: torch>=2.0
|
|
22
|
+
Provides-Extra: demo
|
|
23
|
+
Requires-Dist: matplotlib>=3.6; extra == 'demo'
|
|
24
|
+
Requires-Dist: torchvision>=0.15; extra == 'demo'
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: scipy>=1.10; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# jepa_science
|
|
31
|
+
|
|
32
|
+
**A clean, standalone PyTorch implementation of SIGReg** — the *Sketched Isotropic
|
|
33
|
+
Gaussian Regularization* loss from LeJEPA ([Balestriero & LeCun, 2025,
|
|
34
|
+
arXiv:2511.08544](https://arxiv.org/abs/2511.08544)) — plus a minimal, heavily
|
|
35
|
+
annotated LeJEPA training demo on CIFAR-10.
|
|
36
|
+
|
|
37
|
+
[](tests)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
|
|
40
|
+
## What is JEPA?
|
|
41
|
+
|
|
42
|
+
A **Joint-Embedding Predictive Architecture (JEPA)** learns representations by
|
|
43
|
+
predicting the embedding of one view of an input from the embedding of another,
|
|
44
|
+
*in latent space* rather than in pixel space. The danger is **collapse**: the
|
|
45
|
+
encoder can trivially satisfy the prediction objective by mapping everything to a
|
|
46
|
+
constant. Existing methods fight collapse with heuristics — stop-gradients,
|
|
47
|
+
teacher/student networks, EMA targets, schedulers.
|
|
48
|
+
|
|
49
|
+
## What is SIGReg?
|
|
50
|
+
|
|
51
|
+
LeJEPA proves that the *optimal* embedding distribution for minimizing downstream
|
|
52
|
+
risk is the **standard isotropic Gaussian `N(0, I)`**, and introduces **SIGReg** to
|
|
53
|
+
push embeddings toward it — the single, principled anti-collapse term. SIGReg works
|
|
54
|
+
by a sketch:
|
|
55
|
+
|
|
56
|
+
1. **Cramér–Wold** (paper Lemma 3): two distributions are equal iff *all* their 1-D
|
|
57
|
+
projections are equal. So matching `N(0, I)` reduces to making every projection
|
|
58
|
+
`aᵀz` look like `N(0, 1)`.
|
|
59
|
+
2. **Slice**: sample `K` random unit directions, project the batch onto each.
|
|
60
|
+
3. **Test**: on each 1-D projection apply the **Epps–Pulley** statistic — the
|
|
61
|
+
weighted L² distance between the sample's empirical characteristic function and
|
|
62
|
+
that of `N(0, 1)`, computed by trapezoidal quadrature.
|
|
63
|
+
|
|
64
|
+
The loss is the mean of that statistic over the slices. It is minimized exactly
|
|
65
|
+
when the embeddings have zero mean *and identity covariance* and are Gaussian along
|
|
66
|
+
every direction — which is precisely why it prevents collapse. It has linear time
|
|
67
|
+
and memory cost and bounded, stable gradients (paper Theorem 4).
|
|
68
|
+
|
|
69
|
+
## Why this exists
|
|
70
|
+
|
|
71
|
+
The reference repo bundles SIGReg inside a full training framework. This package
|
|
72
|
+
pulls it out as a **clean, dependency-light primitive** (`torch` + `numpy`) — a
|
|
73
|
+
SciPy-style building block you can drop into any JEPA/SSL pipeline — and pairs it
|
|
74
|
+
with a **runnable, readable demo** so you can watch embeddings Gaussianize.
|
|
75
|
+
|
|
76
|
+
> **Provenance:** this is a *clean-room* implementation written from the paper's
|
|
77
|
+
> mathematics. It does **not** copy code from the reference repository (which ships
|
|
78
|
+
> under a NonCommercial `CC BY-NC 4.0` license, incompatible with this package's
|
|
79
|
+
> Apache-2.0). Methods/algorithms aren't copyrightable; the code here is original.
|
|
80
|
+
> See [`NOTICE`](NOTICE).
|
|
81
|
+
|
|
82
|
+
## Install
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install jepa-science # the primitive (torch + numpy)
|
|
86
|
+
pip install "jepa-science[demo]" # + torchvision & matplotlib for the CIFAR-10 demo
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
From source:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
git clone https://github.com/gabsalvo/jepa_science && cd jepa_science
|
|
93
|
+
pip install -e ".[demo,dev]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Quickstart
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import torch
|
|
100
|
+
from jepa_science import sigreg_loss, SIGReg
|
|
101
|
+
|
|
102
|
+
z = torch.randn(256, 64, requires_grad=True) # (batch, embedding_dim)
|
|
103
|
+
|
|
104
|
+
# Functional form:
|
|
105
|
+
loss = sigreg_loss(z, num_slices=1024) # scalar; minimized at N(0, I)
|
|
106
|
+
|
|
107
|
+
# Module form (precomputes quadrature buffers, moves with .to(device)):
|
|
108
|
+
criterion = SIGReg(num_slices=1024)
|
|
109
|
+
loss = criterion(z)
|
|
110
|
+
loss.backward()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Use it in a LeJEPA-style objective with the single trade-off hyperparameter `λ`:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
embedding_loss = lam * sigreg_loss(z) + (1 - lam) * prediction_loss # λ ≈ 0.05
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`sigreg_loss` returns **only** the SIGReg statistic — `λ` and the JEPA prediction
|
|
120
|
+
term live in your training loop (see `lejepa_lite/`), keeping this a standalone
|
|
121
|
+
primitive.
|
|
122
|
+
|
|
123
|
+
## Watch it not collapse
|
|
124
|
+
|
|
125
|
+
Minimizing **only** SIGReg turns an anisotropic, partially-collapsed batch into
|
|
126
|
+
`N(0, I)`: the covariance condition number → 1, the smallest variance is pushed
|
|
127
|
+
*up* away from zero (anti-collapse), and a random 1-D projection matches the
|
|
128
|
+
`N(0,1)` density. Reproduce with `python docs/make_figure.py`:
|
|
129
|
+
|
|
130
|
+

|
|
131
|
+
|
|
132
|
+
Run the full LeJEPA demo on CIFAR-10:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python -m lejepa_lite.train # downloads CIFAR-10, trains, saves plots
|
|
136
|
+
python -m lejepa_lite.train --smoke # tiny CPU run, no download (also CI path)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Tests
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
pytest # CPU-only, deterministic
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The suite proves correctness against an **independent numpy oracle** and a
|
|
146
|
+
**hand-verified golden value** (cross-checked against a high-accuracy `scipy.quad`
|
|
147
|
+
integral — see `SPEC.md` §6.2), asserts the **Theorem 4 gradient bound**
|
|
148
|
+
numerically, and demonstrates **collapse avoidance** on a toy tensor.
|
|
149
|
+
|
|
150
|
+
## Fidelity notes (this implementation vs. the paper/reference)
|
|
151
|
+
|
|
152
|
+
We follow the authors' *runnable* reference numerics where the paper text and code
|
|
153
|
+
diverge, and flag every divergence here so nothing is silent:
|
|
154
|
+
|
|
155
|
+
| Knob | Paper text | Reference code | **This package (default)** |
|
|
156
|
+
|------|-----------|----------------|----------------------------|
|
|
157
|
+
| Quadrature window | `w(t)=e^{-t²/σ²}`, `σ=1` (`e^{-t²}`) | `e^{-t²/2}` (`σ=√2`) | `e^{-t²/2}` |
|
|
158
|
+
| Integration domain | `[-5, 5]` | `[0, 3]` folded (=±3) | `[0, 3]` folded |
|
|
159
|
+
| Quadrature knots | 17 | 17 | 17 |
|
|
160
|
+
| Slices `K` | 1024 | 256 (`MINIMAL.md`) | **1024** |
|
|
161
|
+
| `λ` (trade-off) | 0.05 | 0.02 (`MINIMAL.md`) | **0.05** (in the demo) |
|
|
162
|
+
|
|
163
|
+
Other deliberate choices: SIGReg does **not** internally center/whiten embeddings
|
|
164
|
+
(doing so would mask collapse — any full-rank covariance would pass); the demo uses
|
|
165
|
+
**CIFAR-10** and a small CNN (the reference used Imagenette + ViT-small, so this is
|
|
166
|
+
*not* a benchmark-parity claim); and DDP/`all_reduce` is out of scope for v1.
|
|
167
|
+
|
|
168
|
+
## Citation
|
|
169
|
+
|
|
170
|
+
If you use this software, please cite the LeJEPA paper:
|
|
171
|
+
|
|
172
|
+
```bibtex
|
|
173
|
+
@misc{balestriero2025lejepa,
|
|
174
|
+
title = {LeJEPA: Provable and Scalable Self-Supervised Learning Without the Heuristics},
|
|
175
|
+
author = {Randall Balestriero and Yann LeCun},
|
|
176
|
+
year = {2025},
|
|
177
|
+
eprint = {2511.08544},
|
|
178
|
+
archivePrefix = {arXiv},
|
|
179
|
+
primaryClass = {cs.LG},
|
|
180
|
+
url = {https://arxiv.org/abs/2511.08544}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
See [`CITATION.cff`](CITATION.cff) to cite this implementation as well.
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
[Apache-2.0](LICENSE). The implemented *method* is from the LeJEPA paper; this code
|
|
189
|
+
is an independent expression of it (see [`NOTICE`](NOTICE)).
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# jepa_science
|
|
2
|
+
|
|
3
|
+
**A clean, standalone PyTorch implementation of SIGReg** — the *Sketched Isotropic
|
|
4
|
+
Gaussian Regularization* loss from LeJEPA ([Balestriero & LeCun, 2025,
|
|
5
|
+
arXiv:2511.08544](https://arxiv.org/abs/2511.08544)) — plus a minimal, heavily
|
|
6
|
+
annotated LeJEPA training demo on CIFAR-10.
|
|
7
|
+
|
|
8
|
+
[](tests)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
## What is JEPA?
|
|
12
|
+
|
|
13
|
+
A **Joint-Embedding Predictive Architecture (JEPA)** learns representations by
|
|
14
|
+
predicting the embedding of one view of an input from the embedding of another,
|
|
15
|
+
*in latent space* rather than in pixel space. The danger is **collapse**: the
|
|
16
|
+
encoder can trivially satisfy the prediction objective by mapping everything to a
|
|
17
|
+
constant. Existing methods fight collapse with heuristics — stop-gradients,
|
|
18
|
+
teacher/student networks, EMA targets, schedulers.
|
|
19
|
+
|
|
20
|
+
## What is SIGReg?
|
|
21
|
+
|
|
22
|
+
LeJEPA proves that the *optimal* embedding distribution for minimizing downstream
|
|
23
|
+
risk is the **standard isotropic Gaussian `N(0, I)`**, and introduces **SIGReg** to
|
|
24
|
+
push embeddings toward it — the single, principled anti-collapse term. SIGReg works
|
|
25
|
+
by a sketch:
|
|
26
|
+
|
|
27
|
+
1. **Cramér–Wold** (paper Lemma 3): two distributions are equal iff *all* their 1-D
|
|
28
|
+
projections are equal. So matching `N(0, I)` reduces to making every projection
|
|
29
|
+
`aᵀz` look like `N(0, 1)`.
|
|
30
|
+
2. **Slice**: sample `K` random unit directions, project the batch onto each.
|
|
31
|
+
3. **Test**: on each 1-D projection apply the **Epps–Pulley** statistic — the
|
|
32
|
+
weighted L² distance between the sample's empirical characteristic function and
|
|
33
|
+
that of `N(0, 1)`, computed by trapezoidal quadrature.
|
|
34
|
+
|
|
35
|
+
The loss is the mean of that statistic over the slices. It is minimized exactly
|
|
36
|
+
when the embeddings have zero mean *and identity covariance* and are Gaussian along
|
|
37
|
+
every direction — which is precisely why it prevents collapse. It has linear time
|
|
38
|
+
and memory cost and bounded, stable gradients (paper Theorem 4).
|
|
39
|
+
|
|
40
|
+
## Why this exists
|
|
41
|
+
|
|
42
|
+
The reference repo bundles SIGReg inside a full training framework. This package
|
|
43
|
+
pulls it out as a **clean, dependency-light primitive** (`torch` + `numpy`) — a
|
|
44
|
+
SciPy-style building block you can drop into any JEPA/SSL pipeline — and pairs it
|
|
45
|
+
with a **runnable, readable demo** so you can watch embeddings Gaussianize.
|
|
46
|
+
|
|
47
|
+
> **Provenance:** this is a *clean-room* implementation written from the paper's
|
|
48
|
+
> mathematics. It does **not** copy code from the reference repository (which ships
|
|
49
|
+
> under a NonCommercial `CC BY-NC 4.0` license, incompatible with this package's
|
|
50
|
+
> Apache-2.0). Methods/algorithms aren't copyrightable; the code here is original.
|
|
51
|
+
> See [`NOTICE`](NOTICE).
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install jepa-science # the primitive (torch + numpy)
|
|
57
|
+
pip install "jepa-science[demo]" # + torchvision & matplotlib for the CIFAR-10 demo
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
From source:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/gabsalvo/jepa_science && cd jepa_science
|
|
64
|
+
pip install -e ".[demo,dev]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Quickstart
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import torch
|
|
71
|
+
from jepa_science import sigreg_loss, SIGReg
|
|
72
|
+
|
|
73
|
+
z = torch.randn(256, 64, requires_grad=True) # (batch, embedding_dim)
|
|
74
|
+
|
|
75
|
+
# Functional form:
|
|
76
|
+
loss = sigreg_loss(z, num_slices=1024) # scalar; minimized at N(0, I)
|
|
77
|
+
|
|
78
|
+
# Module form (precomputes quadrature buffers, moves with .to(device)):
|
|
79
|
+
criterion = SIGReg(num_slices=1024)
|
|
80
|
+
loss = criterion(z)
|
|
81
|
+
loss.backward()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Use it in a LeJEPA-style objective with the single trade-off hyperparameter `λ`:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
embedding_loss = lam * sigreg_loss(z) + (1 - lam) * prediction_loss # λ ≈ 0.05
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`sigreg_loss` returns **only** the SIGReg statistic — `λ` and the JEPA prediction
|
|
91
|
+
term live in your training loop (see `lejepa_lite/`), keeping this a standalone
|
|
92
|
+
primitive.
|
|
93
|
+
|
|
94
|
+
## Watch it not collapse
|
|
95
|
+
|
|
96
|
+
Minimizing **only** SIGReg turns an anisotropic, partially-collapsed batch into
|
|
97
|
+
`N(0, I)`: the covariance condition number → 1, the smallest variance is pushed
|
|
98
|
+
*up* away from zero (anti-collapse), and a random 1-D projection matches the
|
|
99
|
+
`N(0,1)` density. Reproduce with `python docs/make_figure.py`:
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
Run the full LeJEPA demo on CIFAR-10:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
python -m lejepa_lite.train # downloads CIFAR-10, trains, saves plots
|
|
107
|
+
python -m lejepa_lite.train --smoke # tiny CPU run, no download (also CI path)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Tests
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pytest # CPU-only, deterministic
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The suite proves correctness against an **independent numpy oracle** and a
|
|
117
|
+
**hand-verified golden value** (cross-checked against a high-accuracy `scipy.quad`
|
|
118
|
+
integral — see `SPEC.md` §6.2), asserts the **Theorem 4 gradient bound**
|
|
119
|
+
numerically, and demonstrates **collapse avoidance** on a toy tensor.
|
|
120
|
+
|
|
121
|
+
## Fidelity notes (this implementation vs. the paper/reference)
|
|
122
|
+
|
|
123
|
+
We follow the authors' *runnable* reference numerics where the paper text and code
|
|
124
|
+
diverge, and flag every divergence here so nothing is silent:
|
|
125
|
+
|
|
126
|
+
| Knob | Paper text | Reference code | **This package (default)** |
|
|
127
|
+
|------|-----------|----------------|----------------------------|
|
|
128
|
+
| Quadrature window | `w(t)=e^{-t²/σ²}`, `σ=1` (`e^{-t²}`) | `e^{-t²/2}` (`σ=√2`) | `e^{-t²/2}` |
|
|
129
|
+
| Integration domain | `[-5, 5]` | `[0, 3]` folded (=±3) | `[0, 3]` folded |
|
|
130
|
+
| Quadrature knots | 17 | 17 | 17 |
|
|
131
|
+
| Slices `K` | 1024 | 256 (`MINIMAL.md`) | **1024** |
|
|
132
|
+
| `λ` (trade-off) | 0.05 | 0.02 (`MINIMAL.md`) | **0.05** (in the demo) |
|
|
133
|
+
|
|
134
|
+
Other deliberate choices: SIGReg does **not** internally center/whiten embeddings
|
|
135
|
+
(doing so would mask collapse — any full-rank covariance would pass); the demo uses
|
|
136
|
+
**CIFAR-10** and a small CNN (the reference used Imagenette + ViT-small, so this is
|
|
137
|
+
*not* a benchmark-parity claim); and DDP/`all_reduce` is out of scope for v1.
|
|
138
|
+
|
|
139
|
+
## Citation
|
|
140
|
+
|
|
141
|
+
If you use this software, please cite the LeJEPA paper:
|
|
142
|
+
|
|
143
|
+
```bibtex
|
|
144
|
+
@misc{balestriero2025lejepa,
|
|
145
|
+
title = {LeJEPA: Provable and Scalable Self-Supervised Learning Without the Heuristics},
|
|
146
|
+
author = {Randall Balestriero and Yann LeCun},
|
|
147
|
+
year = {2025},
|
|
148
|
+
eprint = {2511.08544},
|
|
149
|
+
archivePrefix = {arXiv},
|
|
150
|
+
primaryClass = {cs.LG},
|
|
151
|
+
url = {https://arxiv.org/abs/2511.08544}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
See [`CITATION.cff`](CITATION.cff) to cite this implementation as well.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
[Apache-2.0](LICENSE). The implemented *method* is from the LeJEPA paper; this code
|
|
160
|
+
is an independent expression of it (see [`NOTICE`](NOTICE)).
|