singularic 1.0.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.
- singularic-1.0.0/LICENSE +201 -0
- singularic-1.0.0/PKG-INFO +152 -0
- singularic-1.0.0/README.md +122 -0
- singularic-1.0.0/pyproject.toml +119 -0
- singularic-1.0.0/src/singularic/__init__.py +13 -0
- singularic-1.0.0/src/singularic/checkpoint/bundle.py +59 -0
- singularic-1.0.0/src/singularic/checkpoint/manager.py +350 -0
- singularic-1.0.0/src/singularic/checkpoint/store.py +107 -0
- singularic-1.0.0/src/singularic/core/apply.py +62 -0
- singularic-1.0.0/src/singularic/core/canonical.py +332 -0
- singularic-1.0.0/src/singularic/core/context.py +51 -0
- singularic-1.0.0/src/singularic/core/enums.py +43 -0
- singularic-1.0.0/src/singularic/core/module.py +970 -0
- singularic-1.0.0/src/singularic/core/path.py +114 -0
- singularic-1.0.0/src/singularic/core/placement.py +27 -0
- singularic-1.0.0/src/singularic/core/precision.py +322 -0
- singularic-1.0.0/src/singularic/core/rng.py +191 -0
- singularic-1.0.0/src/singularic/core/schema.py +302 -0
- singularic-1.0.0/src/singularic/core/selectors.py +151 -0
- singularic-1.0.0/src/singularic/core/state.py +134 -0
- singularic-1.0.0/src/singularic/core/train_state.py +152 -0
- singularic-1.0.0/src/singularic/core/variables.py +412 -0
- singularic-1.0.0/src/singularic/data/dataset.py +555 -0
- singularic-1.0.0/src/singularic/data/ops.py +982 -0
- singularic-1.0.0/src/singularic/data/runtime.py +758 -0
- singularic-1.0.0/src/singularic/data/spec.py +459 -0
- singularic-1.0.0/src/singularic/distributed/sharding.py +366 -0
- singularic-1.0.0/src/singularic/inference/attention.py +143 -0
- singularic-1.0.0/src/singularic/inference/cache.py +612 -0
- singularic-1.0.0/src/singularic/inference/engine.py +398 -0
- singularic-1.0.0/src/singularic/inference/sampling.py +154 -0
- singularic-1.0.0/src/singularic/inspect/report.py +277 -0
- singularic-1.0.0/src/singularic/nn/attention.py +467 -0
- singularic-1.0.0/src/singularic/nn/containers.py +228 -0
- singularic-1.0.0/src/singularic/nn/functional.py +164 -0
- singularic-1.0.0/src/singularic/nn/initializers.py +255 -0
- singularic-1.0.0/src/singularic/nn/kernels.py +532 -0
- singularic-1.0.0/src/singularic/nn/layers.py +594 -0
- singularic-1.0.0/src/singularic/nn/moe.py +482 -0
- singularic-1.0.0/src/singularic/nn/paged.py +70 -0
- singularic-1.0.0/src/singularic/nn/transformer.py +566 -0
- singularic-1.0.0/src/singularic/nn/vision.py +158 -0
- singularic-1.0.0/src/singularic/optim/algorithms.py +278 -0
- singularic-1.0.0/src/singularic/optim/muon.py +91 -0
- singularic-1.0.0/src/singularic/optim/runtime.py +147 -0
- singularic-1.0.0/src/singularic/optim/schedules.py +152 -0
- singularic-1.0.0/src/singularic/optim/specs.py +161 -0
- singularic-1.0.0/src/singularic/optim/transforms.py +460 -0
- singularic-1.0.0/src/singularic/py.typed +1 -0
- singularic-1.0.0/src/singularic/train/checkpoint.py +93 -0
- singularic-1.0.0/src/singularic/train/compiler.py +162 -0
- singularic-1.0.0/src/singularic/train/metrics.py +215 -0
- singularic-1.0.0/src/singularic/train/specs.py +203 -0
- singularic-1.0.0/src/singularic/train/trainer.py +621 -0
- singularic-1.0.0/src/singularic/train/transitions.py +442 -0
singularic-1.0.0/LICENSE
ADDED
|
@@ -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 Singularic contributors
|
|
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,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: singularic
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Full-stack modern AI/ML library in pure JAX
|
|
5
|
+
Keywords: jax,machine-learning,deep-learning,neural-networks,optimization,training,checkpoint,distributed,jax-framework
|
|
6
|
+
Author: Singularic contributors
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Dist: jax>=0.11.0,<0.12
|
|
21
|
+
Requires-Dist: numpy>=2.0,<3
|
|
22
|
+
Requires-Dist: safetensors>=0.8.0,<0.9
|
|
23
|
+
Requires-Python: >=3.14
|
|
24
|
+
Project-URL: Repository, https://github.com/singularic/singularic
|
|
25
|
+
Project-URL: Homepage, https://singularic.ai
|
|
26
|
+
Project-URL: Documentation, https://singularic.ai/docs
|
|
27
|
+
Project-URL: Bug Tracker, https://github.com/singularic/singularic/issues
|
|
28
|
+
Project-URL: Changelog, https://github.com/singularic/singularic/releases
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Singularic
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/singularic/)
|
|
34
|
+
[](https://pypi.org/project/singularic/)
|
|
35
|
+
[](https://github.com/singularic/singularic/actions/workflows/ci.yml)
|
|
36
|
+
[](https://github.com/singularic/singularic/blob/main/LICENSE)
|
|
37
|
+
|
|
38
|
+
Singularic is a standalone, unified, JAX-native machine-learning framework. It
|
|
39
|
+
combines Pythonic modules, semantic optimization, deterministic data pipelines,
|
|
40
|
+
automatically compiled training, portable checkpoints, and distributed
|
|
41
|
+
placement behind one state and selector system.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import jax
|
|
45
|
+
import jax.numpy as jnp
|
|
46
|
+
from singularic.core.module import Module, child, module
|
|
47
|
+
from singularic.data.dataset import Dataset
|
|
48
|
+
from singularic.nn.functional import mean_squared_error
|
|
49
|
+
from singularic.core.enums import ParamRole
|
|
50
|
+
from singularic.nn.layers import Linear
|
|
51
|
+
from singularic.optim.specs import muon
|
|
52
|
+
from singularic.train.trainer import Trainer
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@module
|
|
56
|
+
class MLP(Module):
|
|
57
|
+
hidden = child()
|
|
58
|
+
output = child()
|
|
59
|
+
|
|
60
|
+
def __init__(self) -> None:
|
|
61
|
+
self.hidden = Linear(8, 32)
|
|
62
|
+
self.output = Linear(32, 2, role=ParamRole.OUTPUT_WEIGHT)
|
|
63
|
+
|
|
64
|
+
def __call__(self, inputs: jax.Array) -> jax.Array:
|
|
65
|
+
return self.output(jax.nn.gelu(self.hidden(inputs)))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def loss(model, batch, context):
|
|
69
|
+
del context
|
|
70
|
+
inputs, targets = batch
|
|
71
|
+
return mean_squared_error(model(inputs), targets)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
records = [(jnp.ones((8,)), jnp.zeros((2,))) for _ in range(1_024)]
|
|
75
|
+
dataset = Dataset(records).shuffle(42).batch(32)
|
|
76
|
+
trainer = Trainer(MLP(), muon(), loss)
|
|
77
|
+
trainer.fit(dataset, steps=20)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`Trainer` owns stable JIT boundaries for training, evaluation, prediction,
|
|
81
|
+
automatic differentiation, accumulation, mixed precision, donation, and
|
|
82
|
+
placement. Advanced users can still use `jax.jit`, `jax.grad`, and all other JAX
|
|
83
|
+
APIs directly through `singularic.core.apply.apply`, graph definitions, and `State`.
|
|
84
|
+
|
|
85
|
+
## Install
|
|
86
|
+
|
|
87
|
+
Singularic requires Python 3.14 or newer.
|
|
88
|
+
|
|
89
|
+
```console
|
|
90
|
+
uv add singularic
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
JAX is the only numerical backend. Runtime dependencies are JAX, NumPy, and
|
|
94
|
+
safetensors.
|
|
95
|
+
|
|
96
|
+
## Core guarantees
|
|
97
|
+
|
|
98
|
+
- One metadata-rich `State` pytree for parameters, buffers, caches, RNGs,
|
|
99
|
+
metrics, and optimizer slots.
|
|
100
|
+
- One composable `Selector` and ordered rule system for optimization, freezing,
|
|
101
|
+
sharding, precision, and checkpoint policy.
|
|
102
|
+
- Semantic Muon/AdamW routing through `singularic.optim.specs.muon()`; output heads use
|
|
103
|
+
`nn.Linear(..., role=ParamRole.OUTPUT_WEIGHT)`.
|
|
104
|
+
- Immutable deterministic data pipelines with JSON-safe global cursors;
|
|
105
|
+
non-indexed sources must declare a `ResumableStream` replay contract.
|
|
106
|
+
- Exact process-count elasticity for fixed-cardinality indexed pipelines.
|
|
107
|
+
Filtering and bucketing require deterministic source plans.
|
|
108
|
+
- Versioned JSON plus safetensors checkpoint bundles; never pickle. Immutable
|
|
109
|
+
objects and conditional commit records work through the dependency-free
|
|
110
|
+
`ByteStore` protocol, with a durable POSIX/shared-filesystem adapter in core.
|
|
111
|
+
|
|
112
|
+
Singularic 1.0.0 is the standalone release. The root package is a deliberately
|
|
113
|
+
small facade; import every other public symbol from its owning module. Read the
|
|
114
|
+
[quickstart](https://github.com/singularic/singularic/blob/main/docs/quickstart.md),
|
|
115
|
+
[architecture contract](https://github.com/singularic/singularic/blob/main/docs/architecture.md),
|
|
116
|
+
and [API guide](https://github.com/singularic/singularic/blob/main/docs/api.md). CPU, GPU, and TPU use the same portable-JAX
|
|
117
|
+
correctness contract; GPU accelerators are optional and lazily imported.
|
|
118
|
+
Serving, quantization, executable export, and external dataset connectors are
|
|
119
|
+
out of scope.
|
|
120
|
+
|
|
121
|
+
## Development and benchmarks
|
|
122
|
+
|
|
123
|
+
All operations use `uv`:
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
uv sync --group dev
|
|
127
|
+
./scripts/check.sh
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The individual development suites are:
|
|
131
|
+
|
|
132
|
+
```console
|
|
133
|
+
uv run pytest tests/api tests/core
|
|
134
|
+
uv run pytest tests/nn
|
|
135
|
+
uv run pytest tests/optim
|
|
136
|
+
uv run pytest tests/train
|
|
137
|
+
uv run pytest tests/data tests/checkpoint
|
|
138
|
+
uv run pytest tests/distributed
|
|
139
|
+
uv run pytest tests/inspect tests/property tests/performance tests/inference
|
|
140
|
+
uv run ruff format --check src tests benchmarks
|
|
141
|
+
uv run ruff check src tests benchmarks
|
|
142
|
+
uv run mypy src/singularic benchmarks
|
|
143
|
+
uv run --group docs mkdocs build --strict
|
|
144
|
+
uv build
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Run the reproducible decoder benchmark with
|
|
148
|
+
`uv run python -m benchmarks.train_decoder`; see
|
|
149
|
+
[benchmark policy](https://github.com/singularic/singularic/blob/main/docs/benchmarks.md) for environment-scoped baselines and the
|
|
150
|
+
10% release-regression gate.
|
|
151
|
+
|
|
152
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Singularic
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/singularic/)
|
|
4
|
+
[](https://pypi.org/project/singularic/)
|
|
5
|
+
[](https://github.com/singularic/singularic/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/singularic/singularic/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Singularic is a standalone, unified, JAX-native machine-learning framework. It
|
|
9
|
+
combines Pythonic modules, semantic optimization, deterministic data pipelines,
|
|
10
|
+
automatically compiled training, portable checkpoints, and distributed
|
|
11
|
+
placement behind one state and selector system.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import jax
|
|
15
|
+
import jax.numpy as jnp
|
|
16
|
+
from singularic.core.module import Module, child, module
|
|
17
|
+
from singularic.data.dataset import Dataset
|
|
18
|
+
from singularic.nn.functional import mean_squared_error
|
|
19
|
+
from singularic.core.enums import ParamRole
|
|
20
|
+
from singularic.nn.layers import Linear
|
|
21
|
+
from singularic.optim.specs import muon
|
|
22
|
+
from singularic.train.trainer import Trainer
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@module
|
|
26
|
+
class MLP(Module):
|
|
27
|
+
hidden = child()
|
|
28
|
+
output = child()
|
|
29
|
+
|
|
30
|
+
def __init__(self) -> None:
|
|
31
|
+
self.hidden = Linear(8, 32)
|
|
32
|
+
self.output = Linear(32, 2, role=ParamRole.OUTPUT_WEIGHT)
|
|
33
|
+
|
|
34
|
+
def __call__(self, inputs: jax.Array) -> jax.Array:
|
|
35
|
+
return self.output(jax.nn.gelu(self.hidden(inputs)))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def loss(model, batch, context):
|
|
39
|
+
del context
|
|
40
|
+
inputs, targets = batch
|
|
41
|
+
return mean_squared_error(model(inputs), targets)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
records = [(jnp.ones((8,)), jnp.zeros((2,))) for _ in range(1_024)]
|
|
45
|
+
dataset = Dataset(records).shuffle(42).batch(32)
|
|
46
|
+
trainer = Trainer(MLP(), muon(), loss)
|
|
47
|
+
trainer.fit(dataset, steps=20)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`Trainer` owns stable JIT boundaries for training, evaluation, prediction,
|
|
51
|
+
automatic differentiation, accumulation, mixed precision, donation, and
|
|
52
|
+
placement. Advanced users can still use `jax.jit`, `jax.grad`, and all other JAX
|
|
53
|
+
APIs directly through `singularic.core.apply.apply`, graph definitions, and `State`.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
Singularic requires Python 3.14 or newer.
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
uv add singularic
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
JAX is the only numerical backend. Runtime dependencies are JAX, NumPy, and
|
|
64
|
+
safetensors.
|
|
65
|
+
|
|
66
|
+
## Core guarantees
|
|
67
|
+
|
|
68
|
+
- One metadata-rich `State` pytree for parameters, buffers, caches, RNGs,
|
|
69
|
+
metrics, and optimizer slots.
|
|
70
|
+
- One composable `Selector` and ordered rule system for optimization, freezing,
|
|
71
|
+
sharding, precision, and checkpoint policy.
|
|
72
|
+
- Semantic Muon/AdamW routing through `singularic.optim.specs.muon()`; output heads use
|
|
73
|
+
`nn.Linear(..., role=ParamRole.OUTPUT_WEIGHT)`.
|
|
74
|
+
- Immutable deterministic data pipelines with JSON-safe global cursors;
|
|
75
|
+
non-indexed sources must declare a `ResumableStream` replay contract.
|
|
76
|
+
- Exact process-count elasticity for fixed-cardinality indexed pipelines.
|
|
77
|
+
Filtering and bucketing require deterministic source plans.
|
|
78
|
+
- Versioned JSON plus safetensors checkpoint bundles; never pickle. Immutable
|
|
79
|
+
objects and conditional commit records work through the dependency-free
|
|
80
|
+
`ByteStore` protocol, with a durable POSIX/shared-filesystem adapter in core.
|
|
81
|
+
|
|
82
|
+
Singularic 1.0.0 is the standalone release. The root package is a deliberately
|
|
83
|
+
small facade; import every other public symbol from its owning module. Read the
|
|
84
|
+
[quickstart](https://github.com/singularic/singularic/blob/main/docs/quickstart.md),
|
|
85
|
+
[architecture contract](https://github.com/singularic/singularic/blob/main/docs/architecture.md),
|
|
86
|
+
and [API guide](https://github.com/singularic/singularic/blob/main/docs/api.md). CPU, GPU, and TPU use the same portable-JAX
|
|
87
|
+
correctness contract; GPU accelerators are optional and lazily imported.
|
|
88
|
+
Serving, quantization, executable export, and external dataset connectors are
|
|
89
|
+
out of scope.
|
|
90
|
+
|
|
91
|
+
## Development and benchmarks
|
|
92
|
+
|
|
93
|
+
All operations use `uv`:
|
|
94
|
+
|
|
95
|
+
```console
|
|
96
|
+
uv sync --group dev
|
|
97
|
+
./scripts/check.sh
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The individual development suites are:
|
|
101
|
+
|
|
102
|
+
```console
|
|
103
|
+
uv run pytest tests/api tests/core
|
|
104
|
+
uv run pytest tests/nn
|
|
105
|
+
uv run pytest tests/optim
|
|
106
|
+
uv run pytest tests/train
|
|
107
|
+
uv run pytest tests/data tests/checkpoint
|
|
108
|
+
uv run pytest tests/distributed
|
|
109
|
+
uv run pytest tests/inspect tests/property tests/performance tests/inference
|
|
110
|
+
uv run ruff format --check src tests benchmarks
|
|
111
|
+
uv run ruff check src tests benchmarks
|
|
112
|
+
uv run mypy src/singularic benchmarks
|
|
113
|
+
uv run --group docs mkdocs build --strict
|
|
114
|
+
uv build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Run the reproducible decoder benchmark with
|
|
118
|
+
`uv run python -m benchmarks.train_decoder`; see
|
|
119
|
+
[benchmark policy](https://github.com/singularic/singularic/blob/main/docs/benchmarks.md) for environment-scoped baselines and the
|
|
120
|
+
10% release-regression gate.
|
|
121
|
+
|
|
122
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<0.12.0"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "singularic"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Full-stack modern AI/ML library in pure JAX"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Singularic contributors" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"jax",
|
|
16
|
+
"machine-learning",
|
|
17
|
+
"deep-learning",
|
|
18
|
+
"neural-networks",
|
|
19
|
+
"optimization",
|
|
20
|
+
"training",
|
|
21
|
+
"checkpoint",
|
|
22
|
+
"distributed",
|
|
23
|
+
"jax-framework",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 5 - Production/Stable",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Intended Audience :: Science/Research",
|
|
29
|
+
"License :: OSI Approved :: Apache Software License",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Programming Language :: Python :: 3.14",
|
|
34
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
35
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
dependencies = [
|
|
39
|
+
"jax>=0.11.0,<0.12",
|
|
40
|
+
"numpy>=2.0,<3",
|
|
41
|
+
"safetensors>=0.8.0,<0.9",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Repository = "https://github.com/singularic/singularic"
|
|
46
|
+
Homepage = "https://singularic.ai"
|
|
47
|
+
Documentation = "https://singularic.ai/docs"
|
|
48
|
+
"Bug Tracker" = "https://github.com/singularic/singularic/issues"
|
|
49
|
+
Changelog = "https://github.com/singularic/singularic/releases"
|
|
50
|
+
|
|
51
|
+
[dependency-groups]
|
|
52
|
+
dev = [
|
|
53
|
+
"hypothesis>=6.135",
|
|
54
|
+
"mypy>=1.17",
|
|
55
|
+
"pytest>=8.4",
|
|
56
|
+
"pytest-cov>=6.2",
|
|
57
|
+
"pytest-timeout>=2.4",
|
|
58
|
+
"ruff>=0.12",
|
|
59
|
+
]
|
|
60
|
+
docs = [
|
|
61
|
+
"mkdocs>=1.6",
|
|
62
|
+
"mkdocs-material>=9.6",
|
|
63
|
+
"mkdocstrings[python]>=0.30",
|
|
64
|
+
]
|
|
65
|
+
[tool.uv]
|
|
66
|
+
default-groups = ["dev"]
|
|
67
|
+
|
|
68
|
+
[tool.uv.build-backend]
|
|
69
|
+
module-root = "src"
|
|
70
|
+
module-name = "singularic"
|
|
71
|
+
# Subpackages are PEP 420 namespaces. The root module is the only facade;
|
|
72
|
+
# users import concrete APIs from their owning modules.
|
|
73
|
+
namespace = true
|
|
74
|
+
|
|
75
|
+
[tool.pytest.ini_options]
|
|
76
|
+
addopts = "-ra --strict-config --strict-markers"
|
|
77
|
+
testpaths = ["tests"]
|
|
78
|
+
pythonpath = ["."]
|
|
79
|
+
filterwarnings = ["error"]
|
|
80
|
+
markers = [
|
|
81
|
+
"distributed: tests that create multiple virtual CPU devices",
|
|
82
|
+
"hardware: tests that require a qualified accelerator runner",
|
|
83
|
+
"performance: non-default performance and benchmark assertions",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[tool.coverage.run]
|
|
87
|
+
branch = true
|
|
88
|
+
source = ["singularic"]
|
|
89
|
+
|
|
90
|
+
[tool.coverage.report]
|
|
91
|
+
show_missing = true
|
|
92
|
+
skip_covered = true
|
|
93
|
+
# This is an enforced non-regression floor. Raise it as the untested runtime
|
|
94
|
+
# paths receive coverage; a 95% global target was not representative of the
|
|
95
|
+
# current hardware-dependent codebase.
|
|
96
|
+
fail_under = 75
|
|
97
|
+
|
|
98
|
+
[tool.ruff]
|
|
99
|
+
line-length = 88
|
|
100
|
+
target-version = "py314"
|
|
101
|
+
src = ["src", "tests", "benchmarks"]
|
|
102
|
+
|
|
103
|
+
[tool.ruff.lint]
|
|
104
|
+
select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "PYI"]
|
|
105
|
+
ignore = ["E501"]
|
|
106
|
+
|
|
107
|
+
[tool.ruff.lint.isort]
|
|
108
|
+
known-first-party = ["singularic"]
|
|
109
|
+
|
|
110
|
+
[tool.mypy]
|
|
111
|
+
python_version = "3.14"
|
|
112
|
+
strict = true
|
|
113
|
+
packages = ["singularic"]
|
|
114
|
+
mypy_path = "src"
|
|
115
|
+
warn_unreachable = true
|
|
116
|
+
|
|
117
|
+
[[tool.mypy.overrides]]
|
|
118
|
+
module = ["jax.*", "safetensors.*"]
|
|
119
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Singularic's intentionally minimal package marker.
|
|
2
|
+
|
|
3
|
+
Stable APIs are imported from their owning modules. Child directories are
|
|
4
|
+
PEP 420 namespaces and deliberately have no package-barrel initializers.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from importlib.metadata import version as _distribution_version
|
|
8
|
+
from typing import Final
|
|
9
|
+
|
|
10
|
+
from .core.apply import apply as apply
|
|
11
|
+
from .core.state import State as State
|
|
12
|
+
|
|
13
|
+
__version__: Final = _distribution_version("singularic")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Generic portable checkpoint values independent of training orchestration."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from types import MappingProxyType
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from singularic.core.state import State
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _json_value(value: Mapping[str, Any] | None, description: str) -> Mapping[str, Any]:
|
|
13
|
+
resolved = {} if value is None else dict(value)
|
|
14
|
+
try:
|
|
15
|
+
json.dumps(resolved, allow_nan=False, sort_keys=True)
|
|
16
|
+
except (TypeError, ValueError) as error:
|
|
17
|
+
raise TypeError(
|
|
18
|
+
f"CheckpointBundle {description} must be JSON-compatible"
|
|
19
|
+
) from error
|
|
20
|
+
return MappingProxyType(resolved)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True)
|
|
24
|
+
class CheckpointBundle:
|
|
25
|
+
"""Named portable :class:`State` groups plus JSON metadata and cursor data.
|
|
26
|
+
|
|
27
|
+
The bundle has no knowledge of models, optimizers, or trainers. Group names
|
|
28
|
+
are stable storage ownership boundaries, allowing a caller to restore just
|
|
29
|
+
the local state it owns.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
groups: Mapping[str, State]
|
|
33
|
+
metadata: Mapping[str, Any] | None = None
|
|
34
|
+
dataset_cursor: Mapping[str, Any] | None = None
|
|
35
|
+
|
|
36
|
+
def __post_init__(self) -> None:
|
|
37
|
+
normalized = dict(self.groups)
|
|
38
|
+
if not normalized or any(
|
|
39
|
+
not isinstance(name, str) or not name for name in normalized
|
|
40
|
+
):
|
|
41
|
+
raise ValueError("CheckpointBundle groups must have non-empty string names")
|
|
42
|
+
if any(not isinstance(state, State) for state in normalized.values()):
|
|
43
|
+
raise TypeError("CheckpointBundle groups must be State values")
|
|
44
|
+
object.__setattr__(self, "groups", MappingProxyType(normalized))
|
|
45
|
+
object.__setattr__(self, "metadata", _json_value(self.metadata, "metadata"))
|
|
46
|
+
object.__setattr__(
|
|
47
|
+
self, "dataset_cursor", _json_value(self.dataset_cursor, "dataset cursor")
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def subset(self, names: tuple[str, ...]) -> CheckpointBundle:
|
|
51
|
+
if not names or len(names) != len(set(names)):
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"CheckpointBundle subset names must be non-empty and unique"
|
|
54
|
+
)
|
|
55
|
+
try:
|
|
56
|
+
groups = {name: self.groups[name] for name in names}
|
|
57
|
+
except KeyError as error:
|
|
58
|
+
raise KeyError(f"Unknown checkpoint group {error.args[0]!r}") from error
|
|
59
|
+
return CheckpointBundle(groups, self.metadata, self.dataset_cursor)
|