novatensor 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. novatensor-0.1.0/LICENSE +202 -0
  2. novatensor-0.1.0/NOTICE +6 -0
  3. novatensor-0.1.0/PKG-INFO +439 -0
  4. novatensor-0.1.0/README.md +402 -0
  5. novatensor-0.1.0/pyproject.toml +67 -0
  6. novatensor-0.1.0/setup.cfg +4 -0
  7. novatensor-0.1.0/src/novatensor/__init__.py +46 -0
  8. novatensor-0.1.0/src/novatensor/adapters/__init__.py +5 -0
  9. novatensor-0.1.0/src/novatensor/adapters/amp.py +178 -0
  10. novatensor-0.1.0/src/novatensor/adapters/batchsize.py +170 -0
  11. novatensor-0.1.0/src/novatensor/adapters/configs.py +193 -0
  12. novatensor-0.1.0/src/novatensor/adapters/dataflow.py +181 -0
  13. novatensor-0.1.0/src/novatensor/adapters/equivalence.py +207 -0
  14. novatensor-0.1.0/src/novatensor/adapters/layout.py +86 -0
  15. novatensor-0.1.0/src/novatensor/adapters/timing.py +346 -0
  16. novatensor-0.1.0/src/novatensor/capabilities.py +165 -0
  17. novatensor-0.1.0/src/novatensor/measure/__init__.py +46 -0
  18. novatensor-0.1.0/src/novatensor/measure/bottleneck.py +302 -0
  19. novatensor-0.1.0/src/novatensor/measure/convergence.py +289 -0
  20. novatensor-0.1.0/src/novatensor/measure/stats.py +340 -0
  21. novatensor-0.1.0/src/novatensor/measure/throughput.py +271 -0
  22. novatensor-0.1.0/src/novatensor/policy.py +357 -0
  23. novatensor-0.1.0/src/novatensor/py.typed +0 -0
  24. novatensor-0.1.0/src/novatensor/tune.py +570 -0
  25. novatensor-0.1.0/src/novatensor.egg-info/PKG-INFO +439 -0
  26. novatensor-0.1.0/src/novatensor.egg-info/SOURCES.txt +36 -0
  27. novatensor-0.1.0/src/novatensor.egg-info/dependency_links.txt +1 -0
  28. novatensor-0.1.0/src/novatensor.egg-info/requires.txt +11 -0
  29. novatensor-0.1.0/src/novatensor.egg-info/top_level.txt +1 -0
  30. novatensor-0.1.0/tests/test_bottleneck.py +245 -0
  31. novatensor-0.1.0/tests/test_configs.py +214 -0
  32. novatensor-0.1.0/tests/test_convergence.py +237 -0
  33. novatensor-0.1.0/tests/test_dataflow.py +106 -0
  34. novatensor-0.1.0/tests/test_policy_contract.py +101 -0
  35. novatensor-0.1.0/tests/test_policy_rules.py +392 -0
  36. novatensor-0.1.0/tests/test_stats.py +311 -0
  37. novatensor-0.1.0/tests/test_throughput.py +206 -0
  38. novatensor-0.1.0/tests/test_tune_result.py +296 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ NovaTensor
2
+ Copyright 2026 NovaTensor contributors
3
+
4
+ This product includes software developed as an independent extension to
5
+ PyTorch. It is not affiliated with, endorsed by, or a derivative work of the
6
+ PyTorch project.
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: novatensor
3
+ Version: 0.1.0
4
+ Summary: Automatic, verified training-configuration discovery for PyTorch
5
+ Author: skareef47
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/skareef47/novatensor
8
+ Project-URL: Repository, https://github.com/skareef47/novatensor
9
+ Project-URL: Issues, https://github.com/skareef47/novatensor/issues
10
+ Project-URL: Changelog, https://github.com/skareef47/novatensor/releases
11
+ Keywords: pytorch,training,performance,mixed-precision,amp,benchmark,profiling,channels-last,dataloader
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: System :: Benchmark
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ License-File: NOTICE
28
+ Requires-Dist: numpy>=1.21
29
+ Provides-Extra: torch
30
+ Requires-Dist: torch>=2.1; extra == "torch"
31
+ Provides-Extra: sysinfo
32
+ Requires-Dist: psutil>=5.9; extra == "sysinfo"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7; extra == "dev"
35
+ Requires-Dist: pytest-cov; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # NovaTensor
39
+
40
+ **Automatic, verified training-configuration discovery for PyTorch.**
41
+
42
+ NovaTensor does not invent new ways to make PyTorch fast. Every optimization it
43
+ applies already ships with PyTorch: automatic mixed precision, `channels_last`
44
+ memory format, cuDNN autotuning, `torch.compile`, and DataLoader worker and
45
+ prefetch tuning.
46
+
47
+ What NovaTensor adds is three things PyTorch does not:
48
+
49
+ 1. **It finds the right combination for your hardware.** The best batch size and
50
+ worker count on a 4 GB laptop GPU are not the ones from a blog post written
51
+ on an A100.
52
+ 2. **It proves each change helped on your machine.** Every optimization is
53
+ measured against your real baseline with a bootstrap confidence interval. If
54
+ the interval includes 1.0, the result is reported as *no measurable
55
+ difference* rather than as a win.
56
+ 3. **It refuses changes that alter your model's maths.** Gradients are compared
57
+ before and after; anything beyond your chosen tolerance is rejected.
58
+
59
+ ## Honest expectations
60
+
61
+ The speedup you get is a measure of how untuned your loop was, not of how fast
62
+ NovaTensor is:
63
+
64
+ | Your current loop | Gain, as measured on an RTX 3050 |
65
+ | --- | --- |
66
+ | PyTorch defaults: `num_workers=0`, fp32 | **~2x** end to end |
67
+ | Loader tuned, fp32 | ~1.9x |
68
+ | AMP already on, default loader | ~1.15x |
69
+ | AMP + `channels_last` + tuned loader | ~1.0x (nothing left to find) |
70
+
71
+ Most of that comes from mixed precision and `channels_last`, not from loader
72
+ configuration -- see the note on synchronisation below for why an earlier
73
+ version of this table claimed otherwise. The last row is the honest floor: if
74
+ you already know what `persistent_workers` and `channels_last` do, there is
75
+ nothing here for you but the diagnostic.
76
+
77
+ If you already know what `channels_last` and `prefetch_factor` do, NovaTensor is
78
+ a diagnostic tool for you, not a speedup. It will tell you so rather than
79
+ inventing a number.
80
+
81
+ NovaTensor does **not** contain custom CUDA kernels and does not intend to.
82
+ cuBLAS, cuDNN and Inductor represent an enormous amount of tuning for exactly
83
+ the operations your models use; beating them is not a realistic goal, and
84
+ pretending otherwise would be the fastest way to waste a year.
85
+
86
+ ## Measured results: the full stack
87
+
88
+ **RTX 3050 Laptop GPU** (4 GB, sm_86, Windows, torch 2.4.1+cu124), small conv
89
+ net, batch 128 at 32x32, synthetic dataset with realistic per-sample CPU cost,
90
+ measured through a real DataLoader. Timing is block-based: synchronisation only
91
+ at block boundaries, never per step (see below for why that matters).
92
+
93
+ | stage | ms/step | gain |
94
+ | --- | --- | --- |
95
+ | PyTorch defaults (`num_workers=0`, fp32) | 39.57 | -- |
96
+ | + `workers=2, pin_memory, persistent_workers` | 34.36 | 1.15x |
97
+ | + bf16 autocast + channels_last | 17.7 | 1.94x on top |
98
+ | **predicted total** | | **2.23x** |
99
+ | **measured end to end**, two full epochs | | **1.95x** |
100
+
101
+ The 13% gap between prediction and end-to-end comes from worker startup paid
102
+ once across two epochs, iterators re-created at the epoch boundary, and the
103
+ residual cost of block synchronisation that a real loop does not pay.
104
+
105
+ ### Synchronising every step measures the wrong thing
106
+
107
+ This was the most expensive mistake in the project, and it invalidated every
108
+ speed figure taken before it was found.
109
+
110
+ Timing a step as `synchronize(); t0; step(); synchronize(); t1` measures per-step
111
+ **latency**. Training throughput is a different quantity, and the gap between
112
+ them is large for two reasons:
113
+
114
+ * `torch.cuda.synchronize()` spin-waits, occupying a CPU core. When data loading
115
+ is CPU-bound -- decoding, augmentation -- the instrument competes with the
116
+ workload for cores. A 28.66 ms fetch measured 53.81 ms under per-step timing.
117
+ * More importantly, CUDA execution is **asynchronous**. Without a sync, the CPU
118
+ fetches batch n+1 while the GPU is still executing batch n, so PyTorch
119
+ pipelines data loading against compute for free. Synchronising every step
120
+ forbids that.
121
+
122
+ The consequence was a baseline measured at 87.28 ms/step where the real loop ran
123
+ at 38.5 ms/step, and a reported speedup of 4.86x against a true 2.08x. Because
124
+ the distortion is worse when loading happens in-process, it fell mainly on the
125
+ untuned baseline and inflated the ratio.
126
+
127
+ It also produced a wrong conclusion that survived for some time: that DataLoader
128
+ configuration was worth more than the entire compute effort. Under correct
129
+ timing, `num_workers=0` already achieves **78% overlap** through the CUDA queue
130
+ alone, so worker tuning is worth 1.15x rather than 1.82x, and mixed precision
131
+ plus `channels_last` is the dominant win at 1.94x.
132
+
133
+ Notably, this is the one bug the project's own discipline did not catch. Every
134
+ other error was found by a printed diagnostic contradicting itself; this one was
135
+ internally consistent -- data 53.81 + compute 33.16 was very close to the
136
+ measured step of 87.28, because all three figures were perturbed by the same
137
+ mechanism. Only comparing the prediction against an independent end-to-end
138
+ training run exposed it. Self-consistency checks catch errors in a measurement;
139
+ only an independent measurement catches an error in the instrument.
140
+
141
+ ## Measured results: compute in isolation## Measured results: compute in isolation
142
+
143
+ **RTX 3050 Laptop GPU** (4 GB, sm_86, Windows, torch 2.4.1+cu124), small conv
144
+ net, batch 128 at 32x32, 30 timed steps after warmup. Baseline fp32: 33.4-34.3
145
+ ms/step, measurement noise 0.2-0.4%.
146
+
147
+ | configuration | ms/step | speedup | peak VRAM |
148
+ | --- | --- | --- | --- |
149
+ | fp32 baseline | 34.31 | -- | 0.32 GB |
150
+ | channels_last alone | 128.10 | **0.268x** | 0.32 GB |
151
+ | bf16 autocast | 20.79 | 1.650x | 0.20 GB (-37%) |
152
+ | **bf16 autocast + channels_last** | **17.61** | **1.948x** | 0.20 GB (-37%) |
153
+ | fp16 autocast + loss scaling | 20.15 | 1.702x | 0.20 GB (-37%) |
154
+ | fp16 + channels_last | 105.54 | 0.325x | 0.20 GB (-37%) |
155
+ | cudnn.benchmark alone | 34.01 | 0.979-1.009x | 0.32 GB |
156
+
157
+ End-to-end through a real DataLoader, two epochs, `nt.tune()` choosing
158
+ automatically: **1.94x wall clock against a 1.93x prediction** -- a 0.00x
159
+ prediction error.
160
+
161
+ ### Optimizations do not compose arithmetically
162
+
163
+ This is the result that shaped the package's design. Measured alone,
164
+ `channels_last` is a severe regression at 0.268x. Combined with bf16 it is the
165
+ best configuration available at 1.948x. The product of the two separately
166
+ measured speedups predicts **0.42x** -- wrong by a factor of 4.5, and it would
167
+ have discarded the winner.
168
+
169
+ The cause is that `channels_last` is not an independent speedup but a
170
+ precondition. NHWC layout exists to feed tensor-core kernels; without reduced
171
+ precision there are no tensor-core kernels to feed, so cuDNN takes a poor NHWC
172
+ fp32 path and the layout conversion is paid for nothing.
173
+
174
+ Interactions like this cannot be inferred from component measurements, which is
175
+ why NovaTensor enumerates the combination lattice and measures each point rather
176
+ than composing results.
177
+
178
+ ### Two findings we could not explain
179
+
180
+ **fp16 + channels_last is 6x slower than bf16 + channels_last** (105.5 ms vs
181
+ 17.6 ms) with identical memory layout. The hypothesis was cuDNN algorithm
182
+ selection, since `cudnn.benchmark` is off by default and uses a heuristic. That
183
+ was tested and **rejected**: enabling autotuning changed nothing (105.5 ms ->
184
+ 107.0 ms). The cause remains unknown. It does not affect correctness -- the
185
+ measurement rejects the configuration -- but it is unexplained.
186
+
187
+ **`cudnn.benchmark` is slightly harmful here**, measuring 0.979-1.009x alone and
188
+ consistently ~0.7% worse in every combination, with non-overlapping confidence
189
+ intervals. With fixed input shapes cuDNN's heuristic already chooses well, and
190
+ autotuning only adds overhead.
191
+
192
+ ### Batch size
193
+
194
+ Measured in samples per second, since a larger batch takes longer per step and
195
+ may still finish an epoch sooner. 16,384-sample dataset, two workers.
196
+
197
+ | batch | fp32 samples/s | bf16 + channels_last samples/s | peak VRAM (bf16) |
198
+ | --- | --- | --- | --- |
199
+ | 32 | 3337 | 5142 | 0.07 GB |
200
+ | 64 | 3575 | 6625 | 0.11 GB |
201
+ | **128** | **3754** | **7245** | 0.19 GB |
202
+ | 256 | 3791 | 7564 | 0.34 GB |
203
+ | 512 | 3815 | 7555 | 0.64 GB |
204
+ | 1024 | 3830 | 7550 | 1.24 GB |
205
+
206
+ Throughput saturates: above 128 the gain is 2-4%, below the 5% threshold for
207
+ recommending a change, and batch size is the one knob here that alters training
208
+ dynamics. So nothing is recommended, and nothing is applied.
209
+
210
+ The search runs at both precisions because VRAM headroom depends on which is
211
+ used -- half precision roughly halves the footprint, so a search at fp32 would
212
+ recommend a batch size below what the card can actually hold during training.
213
+
214
+ This table also serves as an independent check on the compute result: at batch
215
+ 128, bf16 + channels_last is 7245/3754 = **1.93x** faster in samples per second,
216
+ against the 1.94x measured earlier by block-timed step comparison. Two
217
+ measurements sharing no code agreeing to 1% is evidence of a kind no internal
218
+ consistency check can provide -- which is the lesson the synchronisation bug
219
+ taught the hard way.
220
+
221
+ ### Batch size is reported, never applied
222
+
223
+ Mixed precision and memory layout compute the same function with different
224
+ arithmetic; training dynamics are untouched. Batch size is not like that.
225
+ Changing it changes the number of optimizer updates per epoch and the gradient
226
+ noise scale, so the model you end up with is different, and the learning rate
227
+ usually needs rescaling. A throughput measurement is silent on whether that
228
+ model is as good. The project rule "do not silently change training objectives"
229
+ draws the line exactly here, and batch size is the only knob in the package that
230
+ crosses it.
231
+
232
+ ### Architecture compatibility
233
+
234
+ Five architectures beyond the conv net, on the same RTX 3050. Pass means the
235
+ package behaved correctly -- applicability detected right, equivalence measured
236
+ without infinities, a decision reached, all state restored. It does not mean the
237
+ optimizations helped.
238
+
239
+ | architecture | baseline | channels_last offered | best candidate |
240
+ | --- | --- | --- | --- |
241
+ | MLP | 2.11 ms | no (correct) | all rejected, 0.57-0.62x |
242
+ | LSTM | 3.74 ms | no (correct) | all rejected, 0.44-0.65x |
243
+ | Transformer encoder | 10.08 ms | no (correct) | all rejected, 0.75-0.84x |
244
+ | ViT (conv patch embed) | 14.27 ms | yes (correct) | all rejected, 0.72-0.97x |
245
+ | Conv autoencoder | 4.67 ms | yes (correct) | all rejected, 0.52-0.88x |
246
+
247
+ **Mixed precision has a minimum problem size.** Every one of these was slower
248
+ under autocast. At 2-14 ms per step these models are kernel-launch bound rather
249
+ than compute bound: the GPU waits on Python to queue work rather than on
250
+ arithmetic, and autocast adds a cast before and after each operation. The
251
+ conv net that gained 1.94x ran at 33 ms per step, comfortably above that
252
+ threshold.
253
+
254
+ This is the clearest argument for measuring rather than recommending. A static
255
+ rule like "enable AMP on Ampere hardware" is wrong for every model in this
256
+ table, and NovaTensor rejects it on all five without being told to.
257
+
258
+ `channels_last` on `ConvTranspose2d` is worth noting specifically: transposed
259
+ convolutions store weights as `(in, out, H, W)`, the reverse of `Conv2d`, and
260
+ the layout change was expected to be a risk. Measured deviation was 1.79e-07
261
+ with a norm ratio of 1.0000 -- float32 round-off, identical to the forward conv
262
+ case. The concern was unfounded, and is now tested rather than assumed.
263
+
264
+ Also detected on this machine: PyTorch's Windows build ships without flash
265
+ attention, so transformer attention falls back to the math implementation. That
266
+ is part of why the transformer baseline is slow and why autocast does not
267
+ recover it.
268
+
269
+ ### Convergence
270
+
271
+ 5 seeds x 300 steps per configuration, 25% label noise to give the loss a
272
+ non-trivial floor. Judged against the standard error of the mean, not the range.
273
+
274
+ | configuration | effect on final loss | in standard errors | rate to target |
275
+ | --- | --- | --- | --- |
276
+ | bf16 + channels_last | -0.0317 | -0.42 | 1.03x |
277
+ | fp16 | +0.0365 | +0.46 | 1.04x |
278
+ | fp16 + channels_last | +0.0452 | +0.62 | 1.05x |
279
+ | bf16 | -0.0658 | -1.02 | 1.00x |
280
+
281
+ All four are indistinguishable from fp32 at a sensitivity of roughly 0.13-0.16
282
+ in final loss. That is a weaker claim than "no effect", and the two should not
283
+ be conflated: effects smaller than that would not have been detected.
284
+
285
+ Note that these estimates are unstable at this seed count. An earlier 7-seed run
286
+ put fp16 at +1.62 standard errors and bf16 at -0.24; here they are +0.46 and
287
+ -1.02. The ordering reversed, so neither reading distinguishes these
288
+ configurations on convergence. bf16 + channels_last is the default because it is
289
+ the fastest, not because it converges better.
290
+
291
+ These are measurements from one model at one batch size on one GPU. They are not
292
+ a general claim -- the point of the package is that the same measurement is
293
+ repeated wherever it runs.
294
+
295
+ ## Status
296
+
297
+ Early development. What exists and is tested:
298
+
299
+ - `novatensor.measure` — robust timing statistics, bootstrap confidence
300
+ intervals on the speedup ratio, separate steady-state and wall-clock metrics
301
+ with breakeven analysis.
302
+ - `novatensor.policy` — the acceptance rules deciding whether an optimization is
303
+ kept, including risk levels and numerical-equivalence gating.
304
+ - `novatensor.capabilities` — hardware and software probing, including whether
305
+ `torch.compile` can actually build on this machine.
306
+ - `novatensor.adapters` — timing probes with correct CUDA synchronisation,
307
+ state snapshot/restore (weights, optimizer, RNG, memory format and global
308
+ cuDNN flags), gradient-equivalence checking, and the optimization lattice.
309
+ - `novatensor.tune` — the `nt.tune()` entry point, which measures every
310
+ configuration and returns the winner applied to the user's own loop.
311
+ - `novatensor.measure.bottleneck` — attribution of step time between the data
312
+ pipeline and compute, with worker-throughput awareness and explicit refusal
313
+ when the inputs cannot describe one configuration.
314
+ - `novatensor.adapters.dataflow` — DataLoader configuration search, with
315
+ Windows spawn semantics accounted for.
316
+ - `scripts/` — `trial_full_stack.py` (pipeline then compute, end to end),
317
+ `trial_all.py` (the compute lattice), `trial_dataflow.py` (pipeline alone),
318
+ `trial_convergence.py` (multi-seed convergence), `trial_amp.py`.
319
+ - `examples/quickstart.py` — the five-line integration, end to end.
320
+
321
+ - `novatensor.measure.throughput` and `novatensor.adapters.batchsize` —
322
+ samples-per-second comparison across batch sizes, with out-of-memory treated
323
+ as data rather than failure.
324
+
325
+ Deliberately not built: native CUDA kernels. cuBLAS, cuDNN and Inductor
326
+ represent an enormous amount of tuning for exactly the operations these models
327
+ use, and a solo implementation beating them is not a realistic goal. The
328
+ project's own rule was to write none until profiling demonstrated a need; that
329
+ gate never opened, and on this evidence it should not.
330
+
331
+ ## What measuring correctly turned out to require
332
+
333
+ Three successive versions of the equivalence check produced three wrong answers,
334
+ each for a different reason, and all three are documented in the code and pinned
335
+ by tests:
336
+
337
+ 1. **Maximum elementwise deviation at random initialisation** reported 0.415 for
338
+ healthy bf16. Gradients at initialisation are sums of large opposing terms
339
+ that nearly cancel, so absolute rounding differences become enormous relative
340
+ ones. Replaced by cosine similarity of the global gradient vector.
341
+ 2. **Comparing at convergence** reported 5e-3 for the same bf16 configuration,
342
+ this time because training to loss 0.0008 drove gradients towards zero, where
343
+ float32 rounding alone rotates them more than any optimization does. Fixed by
344
+ stopping pre-training mid-descent and by refusing to issue a verdict when
345
+ gradients fall below 1e-6 of the parameter scale.
346
+ 3. **GradScaler's statefulness** raised on the second comparison batch, since
347
+ `unscale_` may be called only once between `update()` calls and a
348
+ backward-only check never steps. The exception was being reported as
349
+ corrupted gradients. Replaced with a fixed, deterministic loss scale.
350
+
351
+ A fourth issue was a mis-calibrated threshold rather than a bug: a fixed
352
+ deviation limit cannot be fair to two formats of different precision, so
353
+ candidates are now judged against their own mantissa floor.
354
+
355
+ The convergence comparison repeated the pattern twice more:
356
+
357
+ 5. **Comparing against the run-to-run range** made the test *less* sensitive as
358
+ seeds were added, because a range can only grow with sample size. Going from
359
+ 3 to 7 seeds moved the reported sensitivity from 0.3219 to 0.3653, making the
360
+ advice "add seeds to tighten this" exactly backwards. Replaced with the
361
+ standard error of the mean, which falls as 1/sqrt(n). The curve-divergence
362
+ statistic had the same defect as a maximum over seeds, and is now a median.
363
+ 6. **A task that everything converges on proves nothing.** The first convergence
364
+ run had every configuration reach loss 0.0004 by memorising its data, and
365
+ returned SAFE -- as it would have for a broken optimization. Label noise now
366
+ gives the loss a non-trivial floor, and the comparison refuses to issue a
367
+ verdict when the baseline converges below 1e-3.
368
+
369
+ The common thread: **every one of these was a flaw in the measurement, not in
370
+ the optimization.** Mixed precision worked correctly from the first run and
371
+ reported ~1.62x every time. What took six iterations was building something
372
+ trustworthy enough to say so.
373
+
374
+ Two more surfaced in the pipeline work:
375
+
376
+ 7. **Overlap efficiency divided by a near-zero span.** With data at 0.2 ms
377
+ against 33.4 ms of compute there is almost nothing available to hide, so the
378
+ ratio reported 0% overlap -- arithmetic rather than information. The fourth
379
+ vanishing-denominator bug in this project, and the point at which it became a
380
+ design rule: every ratio of measured quantities needs an explicit guard for
381
+ when its denominator stops being meaningful, and the guard should suppress
382
+ the number rather than print a misleading one.
383
+ 8. **Advice branched on the wrong variable.** Which half is larger says nothing
384
+ about whether they overlap. A step measured at 62.32 ms against 29.73 ms of
385
+ data and 33.48 ms of compute -- perfectly serialised -- was described as
386
+ "compute dominates and the loader is keeping up", dismissing a 1.86x
387
+ available win. The advice now branches on overlap first.
388
+
389
+ And one from pairing measurements taken under different configurations: an fp32
390
+ compute figure was reported against a bf16 step time, claiming a step contained
391
+ more compute than it took and yielding a pipeline headroom of 0.54x. The
392
+ analysis now refuses to compute headroom when `combined < max(data, compute)`,
393
+ since that is physically impossible and therefore a measurement error.
394
+
395
+ A related class of bug, found while adding `channels_last`: state that no
396
+ value-based check can see. `model.to(memory_format=...)` changes tensor strides,
397
+ and `load_state_dict` preserves the destination's layout, so restoring a state
398
+ dict does not undo a layout change. `torch.backends.cudnn.benchmark` is
399
+ process-global and leaks into the user's own training after tuning returns. Both
400
+ are snapshotted explicitly and verified restored at the end of every trial run.
401
+
402
+ ## Design: why the core has no torch dependency
403
+
404
+ The modules that decide whether to alter someone's training run import only
405
+ `numpy`. That is deliberate. It means the correctness of every speedup claim and
406
+ every accept/reject decision is unit-testable on a laptop, in CI, with no GPU
407
+ and no PyTorch installed. PyTorch appears only in thin adapter layers that
408
+ collect timings and apply settings.
409
+
410
+ ## Verified on
411
+
412
+ | platform | Python | torch | numpy |
413
+ | --- | --- | --- | --- |
414
+ | Windows, RTX 3050 | 3.8 | 2.4.1+cu124 | -- |
415
+ | Windows, CPU only | 3.12 | 2.13.0+cpu | 2.5.2 |
416
+ | Linux | 3.10 | -- | 2.2.6 |
417
+ | Linux | 3.13 | -- | 2.5.3 |
418
+
419
+ The two torch versions are nine minor releases apart, and the CPU-only path is
420
+ tested separately because it is the first thing a user without a GPU hits.
421
+
422
+ ## Development
423
+
424
+ ```bash
425
+ pip install -e ".[dev]"
426
+ pytest # 172 tests, a couple of seconds, no GPU and no PyTorch
427
+ ```
428
+
429
+ The test suite needs neither a GPU nor PyTorch. That is the payoff of keeping
430
+ the decision core free of torch: the logic that decides whether to alter
431
+ someone's training run is testable on a free CI runner, and only the thin
432
+ adapter layers need hardware.
433
+
434
+ The hardware trials live in `scripts/` and are not part of CI -- see
435
+ CONTRIBUTING.md for what each one measures.
436
+
437
+ ## Licence
438
+
439
+ Apache-2.0