physis-lm 0.1.2__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.
Files changed (51) hide show
  1. physis_lm-0.1.2/CHANGELOG.md +97 -0
  2. physis_lm-0.1.2/LICENSE +201 -0
  3. physis_lm-0.1.2/MANIFEST.in +4 -0
  4. physis_lm-0.1.2/NOTICE +14 -0
  5. physis_lm-0.1.2/PKG-INFO +332 -0
  6. physis_lm-0.1.2/README.md +301 -0
  7. physis_lm-0.1.2/docs/IMPLEMENTERS_NOTES.md +368 -0
  8. physis_lm-0.1.2/docs/PLAN.md +193 -0
  9. physis_lm-0.1.2/docs/SCALE_FINDINGS.md +175 -0
  10. physis_lm-0.1.2/docs/SECTIONS_3_4_DESIGN.md +219 -0
  11. physis_lm-0.1.2/physis_lm/__init__.py +50 -0
  12. physis_lm-0.1.2/physis_lm/cli.py +309 -0
  13. physis_lm-0.1.2/physis_lm/core.py +483 -0
  14. physis_lm-0.1.2/physis_lm/data.py +321 -0
  15. physis_lm-0.1.2/physis_lm/hf.py +122 -0
  16. physis_lm-0.1.2/physis_lm/jax_backend/__init__.py +17 -0
  17. physis_lm-0.1.2/physis_lm/jax_backend/blocks.py +37 -0
  18. physis_lm-0.1.2/physis_lm/jax_backend/layers.py +161 -0
  19. physis_lm-0.1.2/physis_lm/pcc.py +137 -0
  20. physis_lm-0.1.2/physis_lm/scale_studies.py +533 -0
  21. physis_lm-0.1.2/physis_lm/torch_backend/__init__.py +12 -0
  22. physis_lm-0.1.2/physis_lm/torch_backend/blocks.py +270 -0
  23. physis_lm-0.1.2/physis_lm/torch_backend/layers.py +270 -0
  24. physis_lm-0.1.2/physis_lm/torch_backend/losses.py +177 -0
  25. physis_lm-0.1.2/physis_lm/torch_backend/model.py +466 -0
  26. physis_lm-0.1.2/physis_lm/torch_backend/plrb.py +235 -0
  27. physis_lm-0.1.2/physis_lm/torch_backend/ptcc.py +124 -0
  28. physis_lm-0.1.2/physis_lm/torch_backend/sconm.py +285 -0
  29. physis_lm-0.1.2/physis_lm/torch_backend/train.py +165 -0
  30. physis_lm-0.1.2/physis_lm.egg-info/PKG-INFO +332 -0
  31. physis_lm-0.1.2/physis_lm.egg-info/SOURCES.txt +50 -0
  32. physis_lm-0.1.2/physis_lm.egg-info/dependency_links.txt +1 -0
  33. physis_lm-0.1.2/physis_lm.egg-info/entry_points.txt +2 -0
  34. physis_lm-0.1.2/physis_lm.egg-info/requires.txt +13 -0
  35. physis_lm-0.1.2/physis_lm.egg-info/top_level.txt +1 -0
  36. physis_lm-0.1.2/pyproject.toml +49 -0
  37. physis_lm-0.1.2/setup.cfg +4 -0
  38. physis_lm-0.1.2/tests/__init__.py +1 -0
  39. physis_lm-0.1.2/tests/conftest.py +20 -0
  40. physis_lm-0.1.2/tests/test_cli.py +120 -0
  41. physis_lm-0.1.2/tests/test_core.py +293 -0
  42. physis_lm-0.1.2/tests/test_data_ptcc_pcc.py +300 -0
  43. physis_lm-0.1.2/tests/test_hf.py +78 -0
  44. physis_lm-0.1.2/tests/test_jax_parity.py +121 -0
  45. physis_lm-0.1.2/tests/test_scale_studies.py +89 -0
  46. physis_lm-0.1.2/tests/test_torch_blocks.py +352 -0
  47. physis_lm-0.1.2/tests/test_torch_layers.py +322 -0
  48. physis_lm-0.1.2/tests/test_torch_model.py +355 -0
  49. physis_lm-0.1.2/tests/test_torch_plrb.py +188 -0
  50. physis_lm-0.1.2/tests/test_torch_sconm.py +315 -0
  51. physis_lm-0.1.2/tests/test_training.py +220 -0
@@ -0,0 +1,97 @@
1
+ # Changelog
2
+
3
+ ## 0.1.2 (2026-07-12)
4
+
5
+ Made with AI assistance. New work: a consequential bug fix that unblocks
6
+ generalization, three roadmap items delivered (Sections 3a/3b/4), an Appendix-D
7
+ numerical path, and an honestly-documented scale ceiling. No 0.1.0/0.1.1
8
+ default behaviour changes except the S2 fix (a strict correctness improvement).
9
+
10
+ - **Bug S2 fix (ON by default; strict improvement):** `AdaptiveSlotPool`
11
+ (Section 10.1) now RMSNorms its input before the K/V projections and
12
+ initializes WQs/WKs at 1/sqrt(C). Previously its pre-softmax scores were
13
+ std ~1e-7, so softmax was uniform across all M slot queries and the deep
14
+ bottleneck latent collapsed to M copies of one vector — which blocked any task
15
+ needing a per-position transformation routed through the bottleneck. After the
16
+ fix, a 3.7M and a 14.7M model both learn a Caesar-shift task to 100% held-out
17
+ byte and sequence accuracy (seed-disjoint test, 26^16 prompt space). This is
18
+ the first end-to-end generalization result in the project. Study S8; note S2.
19
+ - **Section 3b — Hugging Face wrapper (`physis_lm.hf`):** `PhysisLMConfig` +
20
+ `PhysisLMForByteModeling`, round-tripping through save/from_pretrained and
21
+ registering with `AutoModel`. Non-autoregressive: `generate()` raises and points
22
+ at `generate_cpd`. Optional import. 5 tests.
23
+ - **Section 3a — JAX parity backend (`physis_lm.jax_backend`):** primitive layers
24
+ + a full PhysisBlock as pure functions over torch-copied weights, parity-tested
25
+ to ~1e-10 in x64 (12 tests). Full end-to-end model NOT ported (note J1).
26
+ - **Appendix D — power-iteration spectral norm** (`spectral_norm_method=
27
+ "power_iteration"`, `spectral_norm_power_iters`): converges to the exact SVD
28
+ sigma_max; surrogate gradient makes gradcheck fail by design (note D1). Fused
29
+ CUDA kernels remain out of scope (no GPU).
30
+ - **Documented scale ceiling (study S8b):** on a 4GB CPU box, models above ~15M
31
+ die from transient OOM spikes mid-training (PLRB's content-dependent tensor
32
+ shapes fragment the allocator) at ~1GB steady RSS; `malloc_trim` + bs=4 made
33
+ 14.7M stable. An environment limit, not an architecture result.
34
+ - **Real-text language result (study S9), reported honestly:** on 1.1M bytes of
35
+ Shakespeare, an 11M model plateaus at ~4.8 bits/byte (character marginals; its
36
+ samples are a repeated character) within ~150 steps, across three chunk lengths
37
+ and two batch sizes. Cause is compute starvation (CPU sees well under one epoch),
38
+ not the architecture; whether it models language at real scale is untested here.
39
+ - **Any-to-Physis transplant: deferred.** Prototyped but not shipped in this
40
+ version (not ready); design retained in docs/SECTIONS_3_4_DESIGN.md.
41
+
42
+ ## 0.1.1 (2026-07-12)
43
+
44
+ Made with AI assistance. Fixes for four documented findings; no existing 0.1.0
45
+ behaviour changes except the F5 initialization fix (a strict improvement).
46
+ Each fix was re-reproduced against 0.1.0 before being written and is covered by
47
+ a new test. License changed MIT -> Apache-2.0.
48
+
49
+ - **F5 fix (ON by default):** norm-preserving attention-pool downsampler (W_V
50
+ init std 1/sqrt(C) + learnable per-channel gain), so the residual stream no
51
+ longer collapses below RMSNorm's eps floor at init. `pool_norm_preserving=False`
52
+ restores the exact 0.1.0 init. CV 8.5's one-hot copy is preserved. Study S3 is
53
+ now a before/after table.
54
+ - **R2 fix (opt-in prototype):** `plrb_soft_routing` (+ `plrb_soft_routing_temp`)
55
+ adds a differentiable soft-routing path so W_route receives a real gradient —
56
+ the route Section 9.7 claims but the literal argmax does not provide. Off by
57
+ default; recovers the hard path as temp -> 0.
58
+ - **F3 fix (opt-in prototype):** `generate_cpd(streaming=True, rehash_period=k)`
59
+ now runs instead of raising. Implements periodic PLRB re-hashing (Remark 15.1);
60
+ bit-identical to naive CPD at `rehash_period=1`. Does NOT reach the paper's
61
+ O(L_out) cost — the DDHH still recomputes each chunk (finding F3 stands, since
62
+ coarse levels cannot be cached). Study S7 gains a re-hash-drift continuation.
63
+ - **F4 option (opt-in):** `fixed_depth_padding` pins ell/n0 to a constant graph.
64
+ 0.1.1 investigated a true logit-level padding-length invariance and confirmed
65
+ it is structurally impossible here (extending the input shifts the output
66
+ placeholders); documented in study S6 and the README's new "Batching and
67
+ train/inference consistency" section.
68
+ - **Thinker-mode (opt-in prototype, task Sec. 5):** `thinker_steps` and
69
+ `thinker_scratchpad_slots` add a parallelism-preserving latent-refinement loop
70
+ over the deep bottleneck (no autoregressive fallback). Default (thinker_steps=1,
71
+ no scratchpad) is byte-for-byte the single-pass model. Shipped as a mechanism
72
+ that is live and trainable, explicitly NOT a demonstrated reasoning gain — the
73
+ steps must be trained to do useful work (note K1).
74
+ - Test suite: 1477 tests, all passing.
75
+ - License: Apache-2.0 (LICENSE + NOTICE added; pyproject/README/PKG-INFO updated).
76
+
77
+ ## 0.1.0 (2026-07-11)
78
+
79
+ First release. Made with AI assistance.
80
+
81
+ - Complete, tested PyTorch reference implementation of the Physis-LM preprint:
82
+ core geometry/oracles, PhysisBlock, DDHH, PLRB (fixed hashing), bottleneck,
83
+ LP, output-to-input cross-attention, SConM (+ confidence streaming), losses,
84
+ the full three-stage training schedule, PTCC, CPD, LSR, PCC.
85
+ - Data layer (txt/jsonl/csv/tsv/html/binary) with precise per-format rules and
86
+ specific error messages; two-stage padding split so the CV 15.3 requirement
87
+ is enforced inside the model and cannot be bypassed.
88
+ - `physis-lm` CLI: info / selftest / train / generate / scale-study.
89
+ - 1470 tests including the paper's own Computational Verifications re-executed
90
+ against this code, an end-to-end files->train->generate CLI test, gradchecks,
91
+ and hypothesis property sweeps.
92
+ - Scale-study module + shipped report (docs/SCALE_FINDINGS.md), including a new
93
+ finding (F5): geometric residual-stream collapse through the pooling
94
+ projections at initialization.
95
+ - Disclosed non-goals for 0.1.0: JAX parity backend, Hugging Face wrapper,
96
+ Appendix D CUDA kernels, PLRB learnable-hashing variant, streaming DDHH
97
+ (finding F3 makes the paper's version incorrect as specified).
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Omur Bera Isik
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ include README.md LICENSE NOTICE CHANGELOG.md pyproject.toml
2
+ recursive-include docs *.md
3
+ recursive-include tests *.py
4
+ global-exclude __pycache__ *.pyc
physis_lm-0.1.2/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ Physis-LM
2
+ Copyright 2026 Omur Bera Isik
3
+
4
+ This product includes software developed as a reference implementation of the
5
+ Physis-LM preprint ("Physis-LM: A Parallel Non-Autoregressive Language Model
6
+ with Hierarchical Latent Compression and Toward Guaranteed Output Consistency",
7
+ Omur Bera Isik, 2026).
8
+
9
+ This codebase was made with AI assistance. No trained checkpoint exists for this
10
+ architecture (the paper itself trains nothing); everything here is a tested,
11
+ CPU-runnable reference implementation, not a pretrained model.
12
+
13
+ Licensed under the Apache License, Version 2.0. See the LICENSE file for the
14
+ full license text.
@@ -0,0 +1,332 @@
1
+ Metadata-Version: 2.4
2
+ Name: physis-lm
3
+ Version: 0.1.2
4
+ Summary: Reference PyTorch implementation of the Physis-LM preprint (byte-native, non-autoregressive, hierarchical-hourglass language model). Made with AI assistance.
5
+ Author: Omur Bera Isik
6
+ License: Apache-2.0
7
+ Keywords: language-model,non-autoregressive,byte-level,hierarchical,pytorch,research
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ License-File: NOTICE
20
+ Requires-Dist: numpy>=1.24
21
+ Requires-Dist: torch>=2.1
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest>=7.0; extra == "test"
24
+ Requires-Dist: hypothesis>=6.0; extra == "test"
25
+ Provides-Extra: hf
26
+ Requires-Dist: transformers>=4.40; extra == "hf"
27
+ Provides-Extra: jax
28
+ Requires-Dist: jax>=0.4; extra == "jax"
29
+ Requires-Dist: jaxlib>=0.4; extra == "jax"
30
+ Dynamic: license-file
31
+
32
+ # physis-lm
33
+
34
+ Reference PyTorch implementation of the preprint **"Physis-LM: A Parallel
35
+ Non-Autoregressive Language Model with Hierarchical Latent Compression and
36
+ Toward Guaranteed Output Consistency"** (Omur Bera Isik, 2026) — a byte-native,
37
+ non-autoregressive language model built around a Dynamic-Depth Hierarchical
38
+ Hourglass (DDHH), a Physis Long-Range Bridge (PLRB), Length Parameters (LP), and
39
+ a Soft Consensus Module (SConM).
40
+
41
+ Made with AI assistance. Version 0.1.2.
42
+
43
+ ## What's new in 0.1.2
44
+
45
+ - **The model now demonstrably generalizes on a task that requires routing a
46
+ transformation through the bottleneck — after fixing a bug that made it look
47
+ like it couldn't.** `AdaptiveSlotPool` (Section 10.1) was the only attention in
48
+ the model that did not RMSNorm its input before the K/Q projections; combined
49
+ with the shared small init, its pre-softmax scores were std ~1e-7, softmax was
50
+ uniform for all M slot queries, and the deep bottleneck latent Z collapsed to M
51
+ copies of one vector (measured: cross-slot cosine 1.0000). A *copy* task hid
52
+ this (the output->input cross-attention bypasses Z); a Caesar-*shift* task
53
+ exposed it — training sat at chance. **Fix (bug S2):** RMSNorm before the K/V
54
+ projections + a 1/sqrt(C) init on WQs/WKs. After it, a 3.7M and a 14.7M model
55
+ both learn shift+3 to **100% held-out byte AND sequence accuracy** on a
56
+ seed-disjoint test set (26^16 prompt space, so this is rule-learning, not
57
+ memorization). See `docs/SCALE_FINDINGS.md` study S8.
58
+ - **On real text, it does NOT yet produce meaningful language — and the reason is
59
+ compute, not the architecture.** Trained on 1.1M bytes of Shakespeare
60
+ (next-chunk prediction, an 11M model on CPU), the model's loss falls to ~4.8
61
+ bits/byte within ~150 steps and then plateaus: it learns the marginal character
62
+ distribution (its samples are a single repeated character) and little context
63
+ structure. This reproduced across three chunk lengths and two batch sizes. A
64
+ byte model needs many epochs over even this small corpus to learn language, and
65
+ at ~0.5-2s/step on a 4GB CPU box the model sees well under one epoch; plain
66
+ cross-entropy (without the designed auxiliary losses) and the parallel-chunk
67
+ objective compound it. Whether the architecture models language at real scale
68
+ is untested here — gated by hardware, not answered. Study S9.
69
+ - **Section 3b — Hugging Face wrapper (`physis_lm.hf`).** `PhysisLMConfig` +
70
+ `PhysisLMForByteModeling` round-trip through `save_pretrained`/`from_pretrained`
71
+ and register with `AutoModel`. It is non-autoregressive, so `generate()` RAISES
72
+ and points at `generate_cpd` rather than silently running HF's AR decoder.
73
+ Optional import; `transformers` is not a hard dependency.
74
+ - **Section 3a — JAX parity backend (`physis_lm.jax_backend`).** The primitive
75
+ layers and a full `PhysisBlock`, ported as pure functions over torch-copied
76
+ weights and parity-tested to ~1e-10 in x64 (12 tests). Scope is stated plainly:
77
+ the full end-to-end hourglass/PLRB/SConM forward is **not** ported (note J1).
78
+ - **Appendix D — power-iteration spectral norm (`spectral_norm_method=
79
+ "power_iteration"`).** The fused CUDA kernels remain out of scope (no GPU), but
80
+ the numerical method they would accelerate is implemented and selectable;
81
+ converges to the exact SVD sigma_max. Its autograd surrogate makes gradcheck
82
+ fail *by design* — documented, not hidden (note D1).
83
+ - **Honest scale ceiling.** On the 4GB CPU sandbox, models above ~15M are killed
84
+ by transient out-of-memory spikes mid-training (PLRB's content-dependent tensor
85
+ shapes fragment the allocator) even at ~1GB steady RSS; `malloc_trim` + bs=4
86
+ made 14.7M stable, and beyond that needs more RAM or a GPU. This is an
87
+ environment limit, not an architecture result (study S8b).
88
+
89
+ ## What's new in 0.1.1
90
+
91
+ Four of the reference's documented findings now have fixes. Each was
92
+ re-reproduced against 0.1.0 before being touched, is covered by a new test, and
93
+ — except F5, which only changes an initialization and is a strict improvement —
94
+ is **off by default**, so every 0.1.0 result still reproduces exactly.
95
+
96
+ - **F5 fix (ON by default):** the attention-pool downsampler is now
97
+ norm-preserving (W_V init std 1/sqrt(C) + a learnable gain), so the residual
98
+ stream no longer collapses below RMSNorm's eps floor at init. Strict
99
+ improvement; `pool_norm_preserving=False` restores the old init.
100
+ - **R2 fix (opt-in prototype):** `plrb_soft_routing=True` gives PLRB a
101
+ differentiable soft-routing path so `W_route` actually trains — the gradient
102
+ route the paper claims but the literal argmax doesn't provide.
103
+ - **F3 fix (opt-in prototype):** `generate_cpd(streaming=True)` now runs, via
104
+ periodic PLRB re-hashing (Remark 15.1). Exact (bit-identical to naive CPD) at
105
+ `rehash_period=1`. It does **not** reach the paper's O(L_out) cost — the DDHH
106
+ still recomputes each chunk, because its coarse levels genuinely can't be
107
+ cached (finding F3 stands) — and that is stated, not hidden.
108
+ - **F4 option (opt-in):** `fixed_depth_padding=True` pins ell/n0 to a constant
109
+ graph. A true logit-level padding-length invariance was investigated and shown
110
+ structurally impossible for this architecture; see "Batching and
111
+ train/inference consistency" below.
112
+ - **Thinker-mode (opt-in prototype):** `thinker_steps > 1` (and optional
113
+ `thinker_scratchpad_slots`) iterates the deep bottleneck over the latent as a
114
+ parallelism-preserving deliberation loop (no autoregressive fallback). The
115
+ mechanism is live and trainable; it is **not** a demonstrated reasoning gain —
116
+ the extra steps must be trained to do useful work. See "Thinker-mode" below.
117
+ - License is now **Apache-2.0** (was MIT).
118
+
119
+ Full detail and honest limits: `docs/IMPLEMENTERS_NOTES.md` (notes F3, F4, F5,
120
+ R2) and `docs/SCALE_FINDINGS.md` (studies S3, S6, S7).
121
+
122
+ ## Read this first (honesty statement)
123
+
124
+ **Physis-LM is currently in the demo stage; we cannot guarantee that everything
125
+ works. If you train the model and get poor results, please be aware that this
126
+ could be one of the contributing factors.**
127
+
128
+ The paper's own title page states that **no version of this architecture has
129
+ ever been assembled, trained, or evaluated end-to-end**, and that every quality
130
+ claim in its Section 20 is an untested prediction. This package changes the
131
+ first half of that sentence — the architecture is now assembled, correct at the
132
+ paper's own toy scale, and heavily tested — and none of the second half:
133
+
134
+ - **There are no pretrained weights.** Anywhere. `physis-lm train` really
135
+ trains (and toy-scale tests verify learning happens), but training a
136
+ competitive model needs the paper's 50-500B-byte budgets and GPUs.
137
+ - Everything implemented is tested against the paper's own numbered claims;
138
+ everything not implemented raises a clear error or is listed below.
139
+ - Three paper claims are **demonstrably false as written** (findings F3, F4,
140
+ F5) and one is self-contradictory (R2); 0.1.1 adds an honest fix or mitigation
141
+ for each (see "What's new" above) while the underlying findings are still
142
+ documented in full, not papered over. See `docs/IMPLEMENTERS_NOTES.md` and
143
+ `docs/SCALE_FINDINGS.md`.
144
+
145
+ ## Install
146
+
147
+ ```bash
148
+ pip install physis-lm # from a built wheel/PyPI
149
+ # or, from a source checkout:
150
+ pip install -e ".[test]" && pytest
151
+ ```
152
+
153
+ Dependencies: `numpy`, `torch>=2.1` (CPU is fine — this package is developed
154
+ and tested entirely on one CPU core). Python >= 3.10.
155
+
156
+ ## Quickstart — library
157
+
158
+ ```python
159
+ import torch
160
+ from physis_lm import PhysisCoreConfig, PhysisLM
161
+
162
+ cfg = PhysisCoreConfig(C=32, M=8, H=4, W=8, Nmax=32, nref=2048,
163
+ NB=2, K_sconm=2, droute=8, R=2, bucket_target=8)
164
+ model = PhysisLM(cfg)
165
+
166
+ ids = torch.tensor([list(b"hello physis, this is a byte-native model")])
167
+ out = model(ids) # single parallel forward pass
168
+ print(out.logits.shape) # (1, Nmax, 256) — all positions at once
169
+ print(out.sigma_score) # LP completion score (Section 12.6)
170
+
171
+ text, info = model.generate_cpd(ids, Lmax=128) # Chunked Parallel Decoding
172
+ print(bytes(text.tolist()))
173
+ ```
174
+
175
+ Training (the full Section 18.4 three-stage schedule, homoscedastic loss
176
+ weighting, curriculum, checkpointing):
177
+
178
+ ```python
179
+ from physis_lm import data as D
180
+ from physis_lm.torch_backend import train as TR
181
+
182
+ ds = D.dataset_from_paths(["my_corpus/"], context_len=128,
183
+ Nmax=cfg.Nmax, pad_byte=cfg.pad_byte)
184
+ provider = D.batch_provider_from_dataset(ds, batch_size=4, pad_byte=cfg.pad_byte)
185
+ history = TR.train(model, provider, TR.TrainSettings(total_steps=1000,
186
+ ckpt_dir="ckpt"))
187
+ ```
188
+
189
+ The model pads internally to exactly `M * r**ell` (the CV 15.3 hard
190
+ requirement), so **you never need to understand DDHH depth arithmetic**: any
191
+ input length up to `cfg.max_supported_raw_length() - Nmax` just works, and
192
+ anything else raises an error telling you to increase `nref`.
193
+
194
+ ## Quickstart — CLI
195
+
196
+ ```bash
197
+ physis-lm selftest # end-to-end pipeline check (~5 s)
198
+ physis-lm info --size base # configs + parameter-count oracles
199
+ physis-lm train --data my_files/ --steps 500 --ckpt-dir ckpt
200
+ physis-lm generate --ckpt ckpt/final.pt --prompt "hello" --max-bytes 200
201
+ physis-lm scale-study # regenerate docs/SCALE_FINDINGS.md
202
+ ```
203
+
204
+ `train` accepts `.txt`, `.jsonl` (`--text-field`), `.csv`/`.tsv`, `.html`
205
+ (`--html-mode strip|raw`), and raw binary files; malformed inputs fail with
206
+ messages naming the file, line, and problem.
207
+
208
+ ## Status table
209
+
210
+ Per-module status; each module's docstring carries the same note, and
211
+ `docs/IMPLEMENTERS_NOTES.md` holds the full list of paper
212
+ ambiguities/contradictions and the decision taken for each (tags like "note B7"
213
+ below resolve there).
214
+
215
+ | Module | Paper | Status | Tested by | Limitations / notes |
216
+ |---|---|---|---|---|
217
+ | `core` geometry, padding, output slice | 7.2, Rem. 7.1, CV 15.3, Rem. 15.4 | implemented | test_core (incl. the literal CV 15.3 sweep, hypothesis sweeps) | ell >= 1 clamp (G1) |
218
+ | `core` complexity + parameter oracles | 7.7, C.1/C.6, Prop 9.1, 17.5, Sec. 1, 12.2, 18.7, App. A | implemented | test_core reproduces every printed table/figure | paper's 130,808 misprint recorded (P1) |
219
+ | `core` LSH oracle + config | 9.3, Prop 9.2, CV 9.3, App. A.1 | implemented | test_core (collision/recall sims; config rejections) | Omega = f(seed, round, B) (R1) |
220
+ | RMSNorm / RoPE / SwiGLU / spectral / local attention | 6.2-6.6, 28.1-28.4, CV 8.3, Prop 8.2 | implemented | test_torch_layers (banded==O(n^2) oracle, CV 8.3 both halves, circulant Jacobian, gradchecks) | banded impl is O(nW) memory; no CUDA kernels (App. D out of scope, no GPU) |
221
+ | PhysisBlock, pooling, upsample, bottleneck, LP | 6.5, 7.3-7.4, 10, 12, CV 8.5, CV 12.6 | implemented | test_torch_blocks (CV 8.5 both cases, all three LP propositions vs autograd) | B3, B8-B10 readings; 0.1.2 fixes AdaptiveSlotPool bottleneck-collapse bug S2 (RMSNorm + 1/sqrt(C) init) |
222
+ | PLRB | 8-9, 19.5, C.6 | implemented (fixed hashing; 0.1.1 opt-in soft routing) | test_torch_plrb (segmented == mask oracle, sentinel, zero W_route grad by default, soft-routing gives W_route a real gradient) | default trains everything except W_route as literally specified (R2); 0.1.1 `plrb_soft_routing` fixes this (prototype); learnable-Omega variant a disclosed stub (R3); dense hashing = C.6 trap at large n (study S5) |
223
+ | SConM + streaming readout | 14, CV 14.2, Lemma 14.8, D.2 | implemented | test_torch_sconm (LOO exact single/multi-head, LSE recovery, vertex bound, scopes) | no contraction claim — conditional on unmeasured L_g (S1; studies S1/S2); 0.1.2 adds opt-in power-iteration spectral norm (note D1) |
224
+ | Full model, integration, LSR, CPD | App. B, CV 15.2/15.3, Rem. 15.4, 7.8.2, 15 | implemented | test_torch_model (the paper's own sixteen-join toy-scale integration test, ablations, LSR bit-exactness, CPD incl. streaming exact-at-period-1) | 0.1.1 streaming CPD runs via periodic PLRB re-hash, exact at rehash_period=1, but does not reach O(L_out) — DDHH still recomputes (finding F3); CPD stops gracefully at the context limit |
225
+ | Losses, schedules, training loop, PTCC | 16.3, 18, 19, CV 18.2/18.4/18.10 | implemented | test_training (a real toy run that learns + checkpoint round-trip), test_data_ptcc_pcc | L1, T1-T3 decisions; no mixed precision / Flash Attention / grad checkpointing (throughput devices, no GPU here) |
226
+ | PCC | 24, CV 24.2 | implemented | test_data_ptcc_pcc (losslessness incl. adversarial streams, tier accounting) | ratios are corpus claims — only CV 24.2's qualitative pattern asserted (C1) |
227
+ | Data layer + CLI | task Sec. 5 | implemented | test_data_ptcc_pcc, test_cli (end-to-end train->generate on real files) | formats defined precisely in data.py's docstring |
228
+ | Scale studies | task Sec. 2 | implemented | test_scale_studies | untrained instantiations only; see report header |
229
+ | Thinker-mode (deliberation loop) | task Sec. 5 | prototype (opt-in) | test_torch_model (default == single-pass, live + trainable, parallelism preserved) | mechanism only; genuine reasoning gains require training the steps (note K1) |
230
+ | JAX parity backend (layers + PhysisBlock) | task Sec. 3a | implemented (layer/block level) | test_jax_parity (12 tests, torch-vs-JAX at copied weights, ~1e-10 in x64) | full end-to-end hourglass/PLRB/SConM forward NOT ported — tested foundation only (note J1) |
231
+ | Hugging Face wrapper | task Sec. 3b | implemented | test_hf (config round-trip, save/from_pretrained identical logits, AutoModel, non-AR contract) | optional import; `generate()` raises -> `generate_cpd`; no pretrained weights |
232
+ | Appendix D spectral-norm kernel | App. D | power-iteration path implemented; fused CUDA kernels out of scope | test_torch_sconm (converges to SVD sigma_max; gradient flow) | no GPU for fused kernels; gradcheck fails by design (surrogate gradient, note D1) |
233
+ | Any-to-Physis weight transplant | task Sec. 4 | **deferred to a later release** | — | intentionally not shipped in this version; design in docs/SECTIONS_3_4_DESIGN.md |
234
+
235
+ Test suite: **1497 tests, all passing** (`pytest -q`), dominated by cheap
236
+ parametrized pure-math sweeps plus hypothesis-generated cases; every
237
+ Computational Verification remark in the paper that can run on CPU is
238
+ re-executed against this codebase's actual code.
239
+
240
+ ## The findings and their 0.1.1 fixes
241
+
242
+ - **F3** — Streaming DDHH's premise ("levels above j* do not change") is false:
243
+ spectral mixing is a global circular convolution at every level (quantified in
244
+ study S7). *0.1.1:* `generate_cpd(streaming=True)` now runs — bit-identical to
245
+ naive CPD at `rehash_period=1`, and periodic PLRB re-hashing (Remark 15.1) for
246
+ larger periods — but the DDHH still recomputes each chunk, so it does not reach
247
+ the paper's O(L_out) streaming cost. The finding stands; the fix is honest
248
+ about what it does and doesn't buy.
249
+ - **F4** — the literal Section 19.5 claim that padding to a longer batch length
250
+ leaves behavior identical is structurally impossible (padding changes ell, and
251
+ extending the input shifts the output placeholders). The achievable invariant
252
+ — batch-content independence at fixed shape — holds to 1e-10 and is tested
253
+ (study S6). *0.1.1:* `fixed_depth_padding=True` pins ell/n0 to a constant
254
+ graph; a true logit-level length invariance was investigated and shown
255
+ impossible here.
256
+ - **F5** (found by this implementation) — at initialization the residual stream
257
+ collapsed geometrically through the attention-pool downsamplers (~x0.02-0.09
258
+ per level), pushing deep levels under RMSNorm's eps floor (study S3). *0.1.1
259
+ (ON by default):* the norm-preserving downsampler holds every level above the
260
+ floor across the whole grid measured; S3 is now a before/after table.
261
+ - **R2** — Section 9.7 is self-contradictory: it says the routing argmax "is not
262
+ differentiated through" yet "gradients flow normally through W_route". The
263
+ literal argmax gives W_route exactly zero gradient (tested), so the default
264
+ fixed-hashing path trains everything except W_route. *0.1.1:*
265
+ `plrb_soft_routing=True` supplies a differentiable soft-routing path so
266
+ W_route trains (prototype; off by default).
267
+
268
+ ## Batching and train/inference consistency
269
+
270
+ Because n0 = M * r**ell depends on the padded input length, this architecture's
271
+ output for a fixed sequence is **not** invariant to how much padding you add:
272
+ different padded lengths mean a different number of DDHH levels and a different
273
+ spectral DFT length (finding F4). Two practical consequences:
274
+
275
+ 1. The guarantee you *can* rely on is **batch-content independence at a fixed
276
+ batch shape**: a sequence's logits do not depend on which other sequences
277
+ share its batch, as long as the batch's padded length is the same. This holds
278
+ to floating-point precision and is tested.
279
+ 2. To keep training and inference consistent, either (a) use the **same nref and
280
+ the same batch-shaping discipline** in both — so a given input lands at the
281
+ same ell in training and at inference — or (b) set
282
+ `PhysisCoreConfig(fixed_depth_padding=True)`, which pins every input to
283
+ ell_max / n0 = M*r**ell_max. Option (b) makes the computation graph constant
284
+ across input lengths (removing the batch-shape-dependent DFT-length drift) at
285
+ the cost of always running at maximum depth; it does not make two
286
+ different-length inputs produce identical logits (that is impossible here),
287
+ but it removes padding-length as a source of train/inference mismatch.
288
+
289
+ ## Thinker-mode (prototype)
290
+
291
+ `PhysisCoreConfig(thinker_steps=T, thinker_scratchpad_slots=S)` turns on an
292
+ opt-in deliberation loop (task Section 5). Instead of a single deep-bottleneck
293
+ pass over the compressed latent Z, the bottleneck is applied T times, adding a
294
+ learnable per-step code each iteration, with S optional learnable "scratchpad"
295
+ latent slots as working memory (dropped before readout so the output shape is
296
+ unchanged). Every latent slot is refined simultaneously at each step, and the
297
+ loop iterates over deliberation steps, never over output tokens — so the
298
+ architecture's parallelism is preserved and there is **no** autoregressive
299
+ fallback. `thinker_steps=1` with no scratchpad (the default) is byte-for-byte
300
+ the single-pass model.
301
+
302
+ What this is and isn't: the mechanism is implemented, live (non-zero step codes
303
+ change the output), and trainable (gradients reach the step codes and
304
+ scratchpad) — all tested. It is **not** a demonstrated reasoning improvement.
305
+ The per-step codes are zero at initialization, so an untrained model's first
306
+ step equals the ordinary pass and further steps just re-apply the bottleneck;
307
+ making the extra steps do genuinely new work is a *training* problem (train with
308
+ `thinker_steps > 1`, most plausibly with a ponder/ACT-style objective). This
309
+ release ships the mechanism honestly labeled as a prototype, not a claim that
310
+ iterating an untrained bottleneck reasons better. See `docs/IMPLEMENTERS_NOTES.md`
311
+ note K1.
312
+
313
+ ## Repository layout
314
+
315
+ ```
316
+ physis_lm/
317
+ core.py geometry, cost/parameter oracles, LSH math, config (no torch)
318
+ data.py byte-level corpus loading + batching (stage-1 padding only)
319
+ pcc.py Physis Context Compression (Section 24; no torch)
320
+ cli.py the `physis-lm` command
321
+ scale_studies.py Section-2 measurements -> markdown report
322
+ torch_backend/
323
+ layers.py blocks.py plrb.py sconm.py model.py losses.py train.py ptcc.py
324
+ tests/ 1470 tests; conftest.py holds the paper's toy scale
325
+ docs/ PLAN.md (pre-implementation plan), IMPLEMENTERS_NOTES.md,
326
+ SCALE_FINDINGS.md
327
+ ```
328
+
329
+ ## Citing
330
+
331
+ If you use this implementation, cite the Physis-LM preprint (Omur Bera Isik,
332
+ 2026). This codebase: `physis-lm` 0.1.2, made with AI assistance, Apache-2.0 license.