quarterbit 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,239 @@
1
+ """
2
+ QuarterBit PyTorch Backend — Utilities
3
+ Copyright (c) 2026 Clouthier Simulation Labs. All rights reserved.
4
+ """
5
+
6
+ import ctypes
7
+ from pathlib import Path
8
+ import warnings
9
+ import sys
10
+
11
+ _lib = None
12
+ _available = None
13
+
14
+ def _load_backend():
15
+ """Load the QuarterBit CUDA backend."""
16
+ global _lib, _available
17
+
18
+ if _available is not None:
19
+ return _available
20
+
21
+ # DLL search paths (compiled binaries only - source is confidential)
22
+ candidates = [
23
+ Path(__file__).parent.parent / "bin" / "quarterbit_core.dll",
24
+ Path(__file__).parent.parent.parent / "build" / "quarterbit_core.dll",
25
+ Path(r"C:\QuarterBit\build\quarterbit_core.dll"),
26
+ ]
27
+
28
+ # Linux paths
29
+ if sys.platform != "win32":
30
+ candidates = [
31
+ Path(__file__).parent.parent / "bin" / "libquarterbit_core.so",
32
+ Path(__file__).parent.parent.parent / "build" / "libquarterbit_core.so",
33
+ ]
34
+
35
+ for path in candidates:
36
+ if path.exists():
37
+ try:
38
+ _lib = ctypes.CDLL(str(path))
39
+ _configure_functions()
40
+ _available = True
41
+ return True
42
+ except Exception as e:
43
+ warnings.warn(f"Failed to load QuarterBit backend: {e}")
44
+
45
+ _available = False
46
+ return False
47
+
48
+ def _configure_functions():
49
+ """Configure ctypes function signatures."""
50
+ global _lib
51
+
52
+ P_F = ctypes.POINTER(ctypes.c_float)
53
+
54
+ # eft_accumulate
55
+ _lib.eft_accumulate.argtypes = [P_F, P_F, P_F, ctypes.c_int]
56
+ _lib.eft_accumulate.restype = ctypes.c_int
57
+
58
+ # eft_accumulate_scaled
59
+ _lib.eft_accumulate_scaled.argtypes = [P_F, P_F, P_F, ctypes.c_float, ctypes.c_int]
60
+ _lib.eft_accumulate_scaled.restype = ctypes.c_int
61
+
62
+ # eft_sgd_step
63
+ _lib.eft_sgd_step.argtypes = [
64
+ P_F, P_F, P_F, # weight, comp, grad
65
+ ctypes.c_float, ctypes.c_float, # lr, weight_decay
66
+ ctypes.c_int # n
67
+ ]
68
+ _lib.eft_sgd_step.restype = ctypes.c_int
69
+
70
+ # eft_adam_step
71
+ _lib.eft_adam_step.argtypes = [
72
+ P_F, P_F, P_F, # weight, weight_comp, grad
73
+ P_F, P_F, # exp_avg, exp_avg_sq
74
+ P_F, P_F, # exp_avg_comp, exp_avg_sq_comp
75
+ ctypes.c_float, ctypes.c_float, ctypes.c_float, # lr, beta1, beta2
76
+ ctypes.c_float, ctypes.c_float, # eps, weight_decay
77
+ ctypes.c_int, ctypes.c_int # step, n
78
+ ]
79
+ _lib.eft_adam_step.restype = ctypes.c_int
80
+
81
+ # eft_matmul
82
+ _lib.eft_matmul.argtypes = [P_F, P_F, P_F, ctypes.c_int, ctypes.c_int, ctypes.c_int]
83
+ _lib.eft_matmul.restype = ctypes.c_int
84
+
85
+ # eft_reduce_sum
86
+ _lib.eft_reduce_sum.argtypes = [P_F, P_F, P_F, ctypes.c_int]
87
+ _lib.eft_reduce_sum.restype = ctypes.c_int
88
+
89
+ # eft_zero_compensation
90
+ _lib.eft_zero_compensation.argtypes = [P_F, ctypes.c_int]
91
+ _lib.eft_zero_compensation.restype = ctypes.c_int
92
+
93
+ # Try to configure compact functions (may not be present in core library)
94
+ _try_configure_compact_functions()
95
+
96
+
97
+ def _try_configure_compact_functions():
98
+ """Try to configure compact adam functions. These may be in a separate library."""
99
+ global _lib
100
+
101
+ P_F = ctypes.POINTER(ctypes.c_float)
102
+ P_V = ctypes.c_void_p
103
+
104
+ # Check if compact functions already exist in core lib
105
+ if hasattr(_lib, 'compact_adam_create'):
106
+ _configure_compact_signatures()
107
+ return
108
+
109
+ # Try to load compact library separately
110
+ compact_candidates = [
111
+ Path(__file__).parent.parent / "bin" / "quarterbit_compact.dll",
112
+ Path(__file__).parent.parent.parent / "build" / "quarterbit_compact.dll",
113
+ Path(r"C:\QuarterBit\build\quarterbit_compact.dll"),
114
+ ]
115
+ if sys.platform != "win32":
116
+ compact_candidates = [
117
+ Path(__file__).parent.parent / "bin" / "libquarterbit_compact.so",
118
+ Path(__file__).parent.parent.parent / "build" / "libquarterbit_compact.so",
119
+ ]
120
+
121
+ for path in compact_candidates:
122
+ if path.exists():
123
+ try:
124
+ compact_lib = ctypes.CDLL(str(path))
125
+ # Add compact functions to main lib object for unified access
126
+ _lib.compact_adam_create = compact_lib.compact_adam_create
127
+ _lib.compact_adam_step = compact_lib.compact_adam_step
128
+ _lib.compact_adam_destroy = compact_lib.compact_adam_destroy
129
+ _lib.compact_adam_memory_info = compact_lib.compact_adam_memory_info
130
+ _configure_compact_signatures()
131
+ return
132
+ except Exception:
133
+ pass
134
+
135
+
136
+ def _configure_compact_signatures():
137
+ """Configure ctypes signatures for compact functions."""
138
+ global _lib
139
+
140
+ P_F = ctypes.POINTER(ctypes.c_float)
141
+ P_V = ctypes.c_void_p
142
+ P_D = ctypes.POINTER(ctypes.c_double)
143
+
144
+ # compact_adam_create(n, use_ef) -> handle
145
+ _lib.compact_adam_create.argtypes = [ctypes.c_int, ctypes.c_int]
146
+ _lib.compact_adam_create.restype = P_V
147
+
148
+ # compact_adam_step(handle, params, grads, lr, beta1, beta2, eps, step) -> int
149
+ _lib.compact_adam_step.argtypes = [
150
+ P_V, P_F, P_F, # handle, params, grads
151
+ ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_float, # lr, beta1, beta2, eps
152
+ ctypes.c_int # step
153
+ ]
154
+ _lib.compact_adam_step.restype = ctypes.c_int
155
+
156
+ # compact_adam_destroy(handle)
157
+ _lib.compact_adam_destroy.argtypes = [P_V]
158
+ _lib.compact_adam_destroy.restype = None
159
+
160
+ # compact_adam_memory_info(n, use_ef, fp32_bytes, compact_bytes, savings_pct)
161
+ _lib.compact_adam_memory_info.argtypes = [
162
+ ctypes.c_longlong, ctypes.c_int, P_D, P_D, P_D
163
+ ]
164
+ _lib.compact_adam_memory_info.restype = None
165
+
166
+
167
+ # CompactEFT library (separate from compact)
168
+ _compact_eft_lib = None
169
+
170
+ def _load_compact_eft_lib():
171
+ """Load the CompactEFT library (production optimizer with EFT precision)."""
172
+ global _compact_eft_lib
173
+
174
+ if _compact_eft_lib is not None:
175
+ return _compact_eft_lib
176
+
177
+ P_F = ctypes.POINTER(ctypes.c_float)
178
+ P_V = ctypes.c_void_p
179
+
180
+ candidates = [
181
+ Path(__file__).parent.parent / "bin" / "quarterbit_compact_eft.dll",
182
+ Path(__file__).parent.parent.parent / "build" / "quarterbit_compact_eft.dll",
183
+ Path(r"C:\QuarterBit\build\quarterbit_compact_eft.dll"),
184
+ ]
185
+ if sys.platform != "win32":
186
+ candidates = [
187
+ Path(__file__).parent.parent / "bin" / "libquarterbit_compact_eft.so",
188
+ Path(__file__).parent.parent.parent / "build" / "libquarterbit_compact_eft.so",
189
+ ]
190
+
191
+ for path in candidates:
192
+ if path.exists():
193
+ try:
194
+ lib = ctypes.CDLL(str(path))
195
+
196
+ # Configure signatures
197
+ lib.compact_eft_adam_create.argtypes = [ctypes.c_int]
198
+ lib.compact_eft_adam_create.restype = P_V
199
+
200
+ lib.compact_eft_adam_step.argtypes = [
201
+ P_V, P_F, P_F,
202
+ ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_float,
203
+ ctypes.c_int
204
+ ]
205
+ lib.compact_eft_adam_step.restype = ctypes.c_int
206
+
207
+ lib.compact_eft_adam_destroy.argtypes = [P_V]
208
+ lib.compact_eft_adam_destroy.restype = None
209
+
210
+ _compact_eft_lib = lib
211
+ return lib
212
+ except Exception as e:
213
+ warnings.warn(f"Failed to load CompactEFT library: {e}")
214
+
215
+ return None
216
+
217
+
218
+ def get_lib():
219
+ """Get the loaded library, loading if necessary."""
220
+ if not _load_backend():
221
+ raise RuntimeError(
222
+ "QuarterBit backend not available. "
223
+ "Ensure CUDA is installed and you have a valid license."
224
+ )
225
+ return _lib
226
+
227
+ def is_available() -> bool:
228
+ """Check if QuarterBit backend is available."""
229
+ return _load_backend()
230
+
231
+ def get_backend_info() -> dict:
232
+ """Get backend information."""
233
+ if not _load_backend():
234
+ return {"available": False}
235
+
236
+ return {
237
+ "available": True,
238
+ "version": "1.0.0",
239
+ }
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: quarterbit
3
+ Version: 0.1.0
4
+ Summary: Precision optimizer for PyTorch - 1,000,000x more accurate than FP32
5
+ Author-email: Kyle Clouthier <info@quarterbit.dev>
6
+ License: Proprietary - Free tier available, commercial use requires license
7
+ Project-URL: Homepage, https://quarterbit.dev
8
+ Project-URL: Repository, https://github.com/DigitalMax321/quarterbit
9
+ Project-URL: Documentation, https://quarterbit.dev/docs
10
+ Keywords: pytorch,optimizer,precision,training,gpu,cuda,adam
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: Other/Proprietary License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: torch>=2.0
27
+ Requires-Dist: numpy>=1.20
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: build; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # QuarterBit
35
+
36
+ **The Pareto-Optimal Optimizer for PyTorch**
37
+
38
+ Better precision. Less memory. Faster training. No tradeoffs.
39
+
40
+ ## The Problem
41
+
42
+ Standard FP32 training loses precision over long runs. Tiny gradient updates get rounded away, causing:
43
+ - Stalled convergence in late training
44
+ - Wasted GPU hours
45
+ - Suboptimal final models
46
+
47
+ ## The Solution
48
+
49
+ QuarterBit's `CompactEFTAdam` combines **compressed storage** with **EFT (Error-Free Transformation) arithmetic** to achieve:
50
+
51
+ | Metric | PyTorch Adam | CompactEFTAdam | Improvement |
52
+ |--------|--------------|----------------|-------------|
53
+ | Precision | Loses 100% of tiny updates | Loses 0% | **1,000,000x** |
54
+ | Memory | 16 B/param | 9.25-13.25 B/param | **17-42% savings** |
55
+ | Convergence | 41 steps to target | 27 steps | **34% faster** |
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install quarterbit
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ```python
66
+ from quarterbit.torch import CompactEFTAdam
67
+
68
+ # Drop-in replacement for torch.optim.Adam
69
+ optimizer = CompactEFTAdam(model.parameters(), lr=1e-3)
70
+
71
+ # Train as usual
72
+ for batch in dataloader:
73
+ loss = model(batch)
74
+ loss.backward()
75
+ optimizer.step()
76
+ optimizer.zero_grad()
77
+ ```
78
+
79
+ ## Why QuarterBit?
80
+
81
+ ### 1. Precision That Matters
82
+ After 500K training steps, standard FP32 loses **100%** of tiny gradient updates. QuarterBit's EFT arithmetic preserves every bit.
83
+
84
+ ### 2. Memory Efficiency
85
+ Train larger models on the same GPU. CompactEFTAdam uses compressed FP16+FP4 storage, saving 17-42% memory.
86
+
87
+ ### 3. Faster Convergence
88
+ Better precision = faster convergence. Reach your target loss in 34% fewer steps.
89
+
90
+ ### 4. Drop-In Replacement
91
+ No code changes needed. Just swap your optimizer.
92
+
93
+ ## Benchmarks
94
+
95
+ See our [Kaggle notebook](https://www.kaggle.com/code/kyleclouthier/quarterbit-benchmark-v2) for full benchmarks on GPT-2.
96
+
97
+ ## Requirements
98
+
99
+ - Python 3.8+
100
+ - PyTorch 2.0+
101
+ - NVIDIA GPU with CUDA support
102
+
103
+ ## Pricing
104
+
105
+ | Tier | Price | Use Case |
106
+ |------|-------|----------|
107
+ | **Free** | $0 | Personal, research, evaluation (<10 GPU-hrs/mo) |
108
+ | **Pro** | $299/mo | Commercial use, up to 10 GPUs |
109
+ | **Team** | $2,499/mo | Up to 100 GPUs, priority support |
110
+ | **Enterprise** | Custom | Unlimited GPUs, custom SLA |
111
+
112
+ See [quarterbit.dev/pricing](https://quarterbit.dev/pricing) for details.
113
+
114
+ ## License
115
+
116
+ Proprietary - see [LICENSE](LICENSE) for details. Free tier available for non-commercial use.
117
+
118
+ ## Links
119
+
120
+ - Website: [quarterbit.dev](https://quarterbit.dev)
121
+ - GitHub: [github.com/DigitalMax321/quarterbit](https://github.com/DigitalMax321/quarterbit)
122
+ - Email: info@quarterbit.dev
@@ -0,0 +1,10 @@
1
+ quarterbit/__init__.py,sha256=XkZDkB0_pdGIi0JEj6yVccqRo48B5-SCEEi7Y1vevN4,2483
2
+ quarterbit/torch/__init__.py,sha256=e41S-OgXlbXh5vkbpGwVB0g3Eqv0z594UmMiGrHBo-8,621
3
+ quarterbit/torch/functional.py,sha256=VaNMvOzqvo2AgCRI3OQNpk-bIVOc-3usKAKyhYyI84g,5760
4
+ quarterbit/torch/optim.py,sha256=NbYJjKt4v1dAf2kswPiSg10n7kEgta1aivJ8_Dy2tDU,26883
5
+ quarterbit/torch/utils.py,sha256=4mnCwgygwDueJbkM7BaFbjEmmD6VQIV0tAK7ffasY1o,8162
6
+ quarterbit-0.1.0.dist-info/licenses/LICENSE,sha256=sIMy1D4ij6YMTJf8ohG5TRIZJRpeb7zS4VGjA9pY5qk,2007
7
+ quarterbit-0.1.0.dist-info/METADATA,sha256=twvl-oxLPsPxNVFQFOpfblR8oB4XDWim4NsxkTc2pSc,4082
8
+ quarterbit-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ quarterbit-0.1.0.dist-info/top_level.txt,sha256=QVr0PzQsD71veFxGScXUdhVVxcrQtxDY3UCvRbGkWxA,11
10
+ quarterbit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,53 @@
1
+ QuarterBit Software License Agreement
2
+ Copyright (c) 2026 Clouthier Simulation Labs. All rights reserved.
3
+
4
+ ================================================================================
5
+ TERMS OF USE
6
+ ================================================================================
7
+
8
+ This software is proprietary and offered under a tiered licensing model.
9
+
10
+ FREE TIER
11
+ ---------
12
+ You may use QuarterBit free of charge for:
13
+ - Personal projects
14
+ - Academic research (non-commercial)
15
+ - Evaluation purposes
16
+ - Projects with less than 10 GPU-hours per month
17
+
18
+ FREE TIER RESTRICTIONS:
19
+ - No commercial use without a paid license
20
+ - No redistribution of source code
21
+ - No removal of license notices
22
+ - Attribution required in publications
23
+
24
+ PAID TIERS
25
+ ----------
26
+ Commercial use requires a paid license:
27
+
28
+ Pro ($299/month) - Up to 10 GPUs, commercial use permitted
29
+ Team ($2,499/month) - Up to 100 GPUs, priority support
30
+ Enterprise (Custom) - Unlimited GPUs, custom SLA, on-premise deployment
31
+
32
+ Contact: info@quarterbit.dev
33
+ Website: https://quarterbit.dev/pricing
34
+
35
+ ================================================================================
36
+ WARRANTY DISCLAIMER
37
+ ================================================================================
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
46
+
47
+ ================================================================================
48
+ CONTACT
49
+ ================================================================================
50
+
51
+ Clouthier Simulation Labs
52
+ Email: info@quarterbit.dev
53
+ Web: https://quarterbit.dev
@@ -0,0 +1 @@
1
+ quarterbit