speedtronic 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.
- speedtronic-0.1.0/LICENSE +178 -0
- speedtronic-0.1.0/MANIFEST.in +12 -0
- speedtronic-0.1.0/PKG-INFO +288 -0
- speedtronic-0.1.0/README.md +252 -0
- speedtronic-0.1.0/configs/diloco.yaml +53 -0
- speedtronic-0.1.0/configs/smoke.yaml +38 -0
- speedtronic-0.1.0/examples/diloco_master.yaml +45 -0
- speedtronic-0.1.0/examples/train_reference.py +34 -0
- speedtronic-0.1.0/pyproject.toml +76 -0
- speedtronic-0.1.0/setup.cfg +4 -0
- speedtronic-0.1.0/src/speedtronic/__init__.py +75 -0
- speedtronic-0.1.0/src/speedtronic/__main__.py +4 -0
- speedtronic-0.1.0/src/speedtronic/checkpoint.py +176 -0
- speedtronic-0.1.0/src/speedtronic/cli.py +75 -0
- speedtronic-0.1.0/src/speedtronic/config.py +520 -0
- speedtronic-0.1.0/src/speedtronic/data.py +263 -0
- speedtronic-0.1.0/src/speedtronic/distributed/__init__.py +30 -0
- speedtronic-0.1.0/src/speedtronic/distributed/diloco.py +363 -0
- speedtronic-0.1.0/src/speedtronic/distributed/hub.py +329 -0
- speedtronic-0.1.0/src/speedtronic/distributed/outer.py +344 -0
- speedtronic-0.1.0/src/speedtronic/distributed/tensors.py +148 -0
- speedtronic-0.1.0/src/speedtronic/hooks.py +17 -0
- speedtronic-0.1.0/src/speedtronic/integrations.py +38 -0
- speedtronic-0.1.0/src/speedtronic/model.py +342 -0
- speedtronic-0.1.0/src/speedtronic/module_utils.py +24 -0
- speedtronic-0.1.0/src/speedtronic/precision.py +147 -0
- speedtronic-0.1.0/src/speedtronic/profiling.py +140 -0
- speedtronic-0.1.0/src/speedtronic/registry.py +75 -0
- speedtronic-0.1.0/src/speedtronic/runtime.py +180 -0
- speedtronic-0.1.0/src/speedtronic/trainer.py +446 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/PKG-INFO +288 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/SOURCES.txt +40 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/dependency_links.txt +1 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/entry_points.txt +2 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/requires.txt +13 -0
- speedtronic-0.1.0/src/speedtronic.egg-info/top_level.txt +1 -0
- speedtronic-0.1.0/tests/test_config.py +51 -0
- speedtronic-0.1.0/tests/test_distributed.py +42 -0
- speedtronic-0.1.0/tests/test_hub.py +66 -0
- speedtronic-0.1.0/tests/test_model.py +36 -0
- speedtronic-0.1.0/tests/test_precision_data.py +29 -0
- speedtronic-0.1.0/tests/test_training.py +120 -0
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
Copyright 2026 BenchLabs
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
recursive-include configs *.yaml
|
|
5
|
+
recursive-include examples *.py *.yaml
|
|
6
|
+
recursive-include tests *.py
|
|
7
|
+
|
|
8
|
+
global-exclude __pycache__
|
|
9
|
+
global-exclude *.py[cod]
|
|
10
|
+
prune .speedtronic
|
|
11
|
+
prune checkpoints
|
|
12
|
+
prune runs
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: speedtronic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A fast, efficient, architecture-neutral training engine with DumbDiLoCo
|
|
5
|
+
Author: BenchLabs
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/bench-labs-org/Speedtronic
|
|
8
|
+
Project-URL: Repository, https://github.com/bench-labs-org/Speedtronic
|
|
9
|
+
Project-URL: Issues, https://github.com/bench-labs-org/Speedtronic/issues
|
|
10
|
+
Keywords: artificial-intelligence,deep-learning,distributed-training,pytorch,training
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
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.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: torch>=2.1
|
|
25
|
+
Requires-Dist: safetensors>=0.4
|
|
26
|
+
Requires-Dist: PyYAML>=6.0
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Requires-Dist: huggingface-hub>=0.23
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
32
|
+
Provides-Extra: logging
|
|
33
|
+
Requires-Dist: wandb>=0.16; extra == "logging"
|
|
34
|
+
Requires-Dist: tensorboard>=2.14; extra == "logging"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
<div align="center">
|
|
38
|
+
|
|
39
|
+
<img width="256" height="256" alt="Speedtronic Logo" src="https://github.com/user-attachments/assets/3389569b-430f-49f3-98b8-7c2d73dca8dc" />
|
|
40
|
+
|
|
41
|
+
# Speedtronic
|
|
42
|
+
|
|
43
|
+
*GPU-agnostic AI training, built for speed.*
|
|
44
|
+
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
[](https://pypi.org/project/speedtronic/)
|
|
48
|
+
|
|
49
|
+
**Be Fast, Be Efficient.**
|
|
50
|
+
|
|
51
|
+
Speedtronic is an open-source PyTorch training framework. You bring your own `nn.Module`, dataset, and a single YAML config; it runs an efficient training loop on CPU, CUDA, or MPS, with optional asynchronous multi-node training (DumbDiLoCo) synced through a Hugging Face Hub repo instead of a dedicated parameter server.
|
|
52
|
+
|
|
53
|
+
## What you get
|
|
54
|
+
|
|
55
|
+
- Architecture-neutral training engine: works with any `nn.Module`, not just the bundled model.
|
|
56
|
+
- Reference GPT-style decoder-only transformer (RoPE, GQA, SwiGLU, tied embeddings) so the repo runs out of the box.
|
|
57
|
+
- Single config file per run: local and distributed runs share the same code path.
|
|
58
|
+
- Efficiency defaults: auto mixed precision, gradient accumulation, streaming data loading with prefetch, fused AdamW when available, opt-in `torch.compile` and gradient checkpointing.
|
|
59
|
+
- Local resumable checkpoints (model, optimizer, scheduler, RNG, step counters).
|
|
60
|
+
- DumbDiLoCo: DiLoCo-style local-steps-then-sync, with the Hub as transport. One node is master, the rest are workers. No extra infrastructure to host.
|
|
61
|
+
- Pluggable metrics: stdout/file/JSONL built in, W&B and TensorBoard via optional hooks.
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- Python >= 3.10
|
|
66
|
+
- PyTorch >= 2.1 (install the CPU or CUDA wheel appropriate for your machine first)
|
|
67
|
+
- `safetensors`, `PyYAML`, `numpy`, `huggingface-hub` (installed automatically)
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install speedtronic
|
|
73
|
+
# optional logging integrations
|
|
74
|
+
pip install 'speedtronic[logging]'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For a source checkout:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install -e .
|
|
81
|
+
# dev tools (pytest, ruff)
|
|
82
|
+
pip install -e '.[dev]'
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Quickstart (60 seconds)
|
|
86
|
+
|
|
87
|
+
Train the bundled reference model on synthetic data (CPU-safe, no downloads):
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
speedtronic train --config configs/smoke.yaml
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Validate a config without training:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
speedtronic validate --config configs/smoke.yaml
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Same run from Python:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from speedtronic import SpeedtronicConfig
|
|
103
|
+
from speedtronic.runtime import train_from_config
|
|
104
|
+
|
|
105
|
+
config = SpeedtronicConfig.from_dict({
|
|
106
|
+
"run": {"name": "demo", "max_steps": 100, "device": "cpu"},
|
|
107
|
+
"model": {
|
|
108
|
+
"name": "reference_transformer",
|
|
109
|
+
"vocab_size": 256,
|
|
110
|
+
"max_seq_len": 64,
|
|
111
|
+
"n_layer": 2,
|
|
112
|
+
"n_head": 4,
|
|
113
|
+
"n_kv_head": 2,
|
|
114
|
+
"d_model": 64,
|
|
115
|
+
},
|
|
116
|
+
"data": {"micro_batch_size": 2, "target_batch_size": 8},
|
|
117
|
+
"precision": {"mode": "fp32"},
|
|
118
|
+
})
|
|
119
|
+
result = train_from_config(config)
|
|
120
|
+
print(result.steps, result.final_loss)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
CLI flags override the file without editing it:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
speedtronic train --config configs/smoke.yaml --max-steps 100 --output-dir runs/demo --resume
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Project layout
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
src/speedtronic/
|
|
133
|
+
config.py # SpeedtronicConfig: validation, YAML/JSON/dict loading
|
|
134
|
+
trainer.py # Trainer: accumulation, precision, compile, checkpoint hooks
|
|
135
|
+
runtime.py # build_runtime / train_from_config: wiring from config to Trainer
|
|
136
|
+
model.py # reference transformer (example model, not a framework dependency)
|
|
137
|
+
registry.py # model registry for custom architectures
|
|
138
|
+
data.py # synthetic + streaming text datasets, dataloader builder
|
|
139
|
+
precision.py # device and dtype capability detection
|
|
140
|
+
checkpoint.py # atomic local checkpoints
|
|
141
|
+
profiling.py # MetricLogger, stdout/file/JSONL output, hook fan-out
|
|
142
|
+
integrations.py # optional W&B / TensorBoard hooks
|
|
143
|
+
cli.py # speedtronic train | validate
|
|
144
|
+
distributed/ # DumbDiLoCo: hub.py, diloco.py, outer.py, tensors.py
|
|
145
|
+
configs/
|
|
146
|
+
smoke.yaml # minimal CPU run
|
|
147
|
+
diloco.yaml # local template with distributed section
|
|
148
|
+
examples/
|
|
149
|
+
train_reference.py
|
|
150
|
+
diloco_master.yaml
|
|
151
|
+
tests/ # CPU-only, Hub fakes (no network credentials needed)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Configuration
|
|
155
|
+
|
|
156
|
+
One `SpeedtronicConfig` drives everything. Load from YAML, JSON, a JSON/YAML string, or a plain dict. Unknown keys are rejected so typos fail fast.
|
|
157
|
+
|
|
158
|
+
| Section | Controls |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `run` | name, seed, device (`auto`/`cpu`/`cuda`/`mps`), `max_steps`, `output_dir` |
|
|
161
|
+
| `model` | registered model name + architecture params |
|
|
162
|
+
| `data` | `micro_batch_size` / `target_batch_size` (accumulation derived), text path or synthetic source, workers, prefetch, pin_memory, shuffle |
|
|
163
|
+
| `optimizer` | AdamW LR, betas, eps, weight decay, optional fused, grad clip |
|
|
164
|
+
| `scheduler` | `cosine` (default) or `constant`, warmup steps, min LR ratio |
|
|
165
|
+
| `precision` | `auto`/`bf16`/`fp16`/`fp32`; auto picks bf16 on capable CUDA, fp32 elsewhere |
|
|
166
|
+
| `compile` | opt-in `torch.compile`; logs and continues uncompiled if unsupported |
|
|
167
|
+
| `gradient_checkpointing` | calls the model's `set_gradient_checkpointing()` hook if present |
|
|
168
|
+
| `checkpoint` | directory, interval, retention (`keep_last`), resume flag |
|
|
169
|
+
| `logging` | level, file, JSONL file, step cadence, hook list |
|
|
170
|
+
| `distributed` | DumbDiLoCo role, node id, Hub repo, inner/outer loop tuning (see below) |
|
|
171
|
+
|
|
172
|
+
Top-level aliases (`name`, `max_steps`, `output_dir`, `seed`, `device`) are accepted as shorthand for `run.*`.
|
|
173
|
+
|
|
174
|
+
## Bring your own model
|
|
175
|
+
|
|
176
|
+
The engine only requires a module that maps a batch to a loss. Return a tensor, a `{"loss": ...}` dict, or a `(loss, ...)` tuple. Dict batches are passed as kwargs; tuple batches are passed as `(inputs, labels)`.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import torch
|
|
180
|
+
from speedtronic import register_model
|
|
181
|
+
|
|
182
|
+
@register_model("my_model")
|
|
183
|
+
def make_model(**kwargs):
|
|
184
|
+
return torch.nn.TransformerEncoder(
|
|
185
|
+
torch.nn.TransformerEncoderLayer(d_model=kwargs["d_model"], nhead=kwargs.get("n_head", 4)),
|
|
186
|
+
num_layers=kwargs.get("n_layer", 2),
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
model:
|
|
192
|
+
name: my_model
|
|
193
|
+
d_model: 256
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
For activation checkpointing, expose `set_gradient_checkpointing(enabled)` on your module; the trainer calls it and warns if it is absent.
|
|
197
|
+
|
|
198
|
+
## Bring your own data
|
|
199
|
+
|
|
200
|
+
- Default: deterministic synthetic token stream (good for smoke tests and benchmarking the loop).
|
|
201
|
+
- `data.text_path`: streams a UTF-8 file in fixed-size token blocks without loading it into RAM.
|
|
202
|
+
- `build_dataloader(..., dataset=..., tokenizer=...)`: pass any PyTorch `Dataset`/`IterableDataset` directly.
|
|
203
|
+
- `micro_batch_size` is what the loader emits; `target_batch_size` is the effective batch after accumulation. The trainer handles the math and keeps mixed precision correct across accumulation steps.
|
|
204
|
+
|
|
205
|
+
## Efficiency behavior
|
|
206
|
+
|
|
207
|
+
- **Precision:** `auto` uses bf16 where `torch.cuda.is_bf16_supported()`, fp16 with `GradScaler` on CUDA otherwise, fp32 on CPU/MPS. Explicit modes are honored unless the hardware cannot run them, in which case the run falls back to fp32 instead of crashing.
|
|
208
|
+
- **`torch.compile`:** never a hard failure. Unsupported combinations log and continue eagerly, including a runtime fallback if a compiled step throws.
|
|
209
|
+
- **Fused AdamW:** used only when construction with `fused=True` succeeds on CUDA.
|
|
210
|
+
- **Attention:** the reference model uses `scaled_dot_product_attention` so PyTorch picks flash / memory-efficient / math per device. No flash-attn dependency.
|
|
211
|
+
- **Data:** `num_workers`, `prefetch_factor`, and `pin_memory` are configurable; iterable datasets skip sampler shuffling (implement shuffling in the stream if needed).
|
|
212
|
+
|
|
213
|
+
## Checkpoints and resume
|
|
214
|
+
|
|
215
|
+
Checkpoints store model weights, optimizer state, scheduler state, step/sample/token counters, RNG state, redacted config copy, and (for DumbDiLoCo) coordinator state. Files are written to temp + atomic rename; a `latest.json` pointer tracks the newest checkpoint.
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
speedtronic train --config configs/smoke.yaml --resume
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`max_steps` is a global step target, so resuming with the same config continues rather than restarting. Saved Hub tokens are redacted (`<redacted>`) in stored configs; provide tokens via environment at runtime.
|
|
222
|
+
|
|
223
|
+
## DumbDiLoCo (distributed without a parameter server)
|
|
224
|
+
|
|
225
|
+
Each node trains locally for `inner_steps` AdamW steps, uploads a pseudo-gradient (`weights_at_last_sync - current_weights`) to its own `nodes/<node_id>/` folder in a Hub repo, and periodically pulls the newest global weights. The master aggregates whatever deltas arrived since the last round (simple mean), applies Nesterov momentum SGD, and publishes `global/latest.safetensors` + `global/step_count.json`. Nodes never share a clock and never block on stragglers.
|
|
226
|
+
|
|
227
|
+
```yaml
|
|
228
|
+
distributed:
|
|
229
|
+
enabled: true
|
|
230
|
+
mode: dumb_diloco
|
|
231
|
+
role: master # worker on the other machines
|
|
232
|
+
node_id: node-a # unique per participant, path-safe
|
|
233
|
+
repo_id: my-org/my-run
|
|
234
|
+
# token: prefer HF_TOKEN env var over YAML
|
|
235
|
+
inner_steps: 500
|
|
236
|
+
poll_interval: 60
|
|
237
|
+
outer_lr: 0.7
|
|
238
|
+
outer_momentum: 0.9
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Repo layout on the Hub:
|
|
242
|
+
|
|
243
|
+
```text
|
|
244
|
+
<run>/
|
|
245
|
+
global/latest.safetensors
|
|
246
|
+
global/step_count.json
|
|
247
|
+
nodes/<node_id>/delta_<local_step>.safetensors
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Operational notes:
|
|
251
|
+
|
|
252
|
+
- The master creates the repo (private by default) and attempts `collaborators` grants where the installed Hub SDK supports it; otherwise grant write access in the repo settings UI.
|
|
253
|
+
- `node_id` defaults to `HF_USERNAME` / `USER` / `local` if unset; set it explicitly per machine.
|
|
254
|
+
- Transient Hub failures retry with exponential backoff and never kill local training; a failed delta upload is retried as a cumulative delta at the next boundary.
|
|
255
|
+
- A corrupt delta is logged with its filename and skipped for that round.
|
|
256
|
+
- A restarted worker resumes from the latest global weights (at most one partial inner loop is lost). A restarted master resumes global weights, outer step, processed-delta set, and Nesterov momentum from its local `state_dir`.
|
|
257
|
+
- `distributed.reset_inner_optimizer` (default `true`) clears Adam state at each inner-loop boundary so stale moments do not leak across sync rounds.
|
|
258
|
+
|
|
259
|
+
Security model: trusted collaborators only. Anyone with a valid write token for the repo can influence the global model. There is no cryptographic node identity, Byzantine fault tolerance, or staleness weighting. Do not point this at a public-write repo.
|
|
260
|
+
|
|
261
|
+
## Metrics
|
|
262
|
+
|
|
263
|
+
Every run logs `loss`, `lr`, `steps/sec`, `samples/sec`, `tokens/sec`, memory (when the backend exposes it), and — for DumbDiLoCo — outer step plus deltas found/included per round. Output goes to stdout by default, optionally to a file and/or JSONL (`logging.file`, `logging.json_file`). `MetricLogger(hooks=[...])` accepts `(event, payload)` callables or objects with `on_event`; W&B and TensorBoard adapters live in `integrations.py` and stay optional dependencies.
|
|
264
|
+
|
|
265
|
+
## Development
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
pip install -e '.[dev]'
|
|
269
|
+
pytest -q
|
|
270
|
+
ruff check src tests examples
|
|
271
|
+
ruff format --check src tests examples
|
|
272
|
+
python -m compileall src
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Tests are CPU-only. Hub tests use fakes; no network or credentials required.
|
|
276
|
+
|
|
277
|
+
## Scope and non-goals
|
|
278
|
+
|
|
279
|
+
- One reference model, not a model zoo.
|
|
280
|
+
- No tokenizer training tooling.
|
|
281
|
+
- No FSDP or pipeline parallelism.
|
|
282
|
+
- No open/adversarial participation mode.
|
|
283
|
+
- No hosted dashboard; CLI + config files only.
|
|
284
|
+
- Mid-inner-loop worker resume is out of scope (restart from latest global).
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
Apache-2.0. See `LICENSE`.
|