bitstraining 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 (100) hide show
  1. bitstraining-0.1.0/CHANGELOG.md +43 -0
  2. bitstraining-0.1.0/CODE_OF_CONDUCT.md +16 -0
  3. bitstraining-0.1.0/CONTRIBUTING.md +45 -0
  4. bitstraining-0.1.0/LICENSE +177 -0
  5. bitstraining-0.1.0/MANIFEST.in +4 -0
  6. bitstraining-0.1.0/PKG-INFO +228 -0
  7. bitstraining-0.1.0/README.md +182 -0
  8. bitstraining-0.1.0/RELEASING.md +43 -0
  9. bitstraining-0.1.0/bitstraining/__init__.py +28 -0
  10. bitstraining-0.1.0/bitstraining/autotune/__init__.py +7 -0
  11. bitstraining-0.1.0/bitstraining/autotune/cache.py +39 -0
  12. bitstraining-0.1.0/bitstraining/autotune/microbatch.py +42 -0
  13. bitstraining-0.1.0/bitstraining/autotune/tuner.py +134 -0
  14. bitstraining-0.1.0/bitstraining/compute/__init__.py +23 -0
  15. bitstraining-0.1.0/bitstraining/compute/base.py +104 -0
  16. bitstraining-0.1.0/bitstraining/compute/bundle.py +64 -0
  17. bitstraining-0.1.0/bitstraining/compute/catalog.py +86 -0
  18. bitstraining-0.1.0/bitstraining/compute/docker.py +107 -0
  19. bitstraining-0.1.0/bitstraining/compute/local.py +121 -0
  20. bitstraining-0.1.0/bitstraining/compute/notebook.py +132 -0
  21. bitstraining-0.1.0/bitstraining/compute/orchestrator.py +126 -0
  22. bitstraining-0.1.0/bitstraining/compute/ssh.py +157 -0
  23. bitstraining-0.1.0/bitstraining/core/__init__.py +1 -0
  24. bitstraining-0.1.0/bitstraining/core/config.py +85 -0
  25. bitstraining-0.1.0/bitstraining/core/errors.py +43 -0
  26. bitstraining-0.1.0/bitstraining/core/paths.py +28 -0
  27. bitstraining-0.1.0/bitstraining/core/registry.py +87 -0
  28. bitstraining-0.1.0/bitstraining/core/schemas.py +358 -0
  29. bitstraining-0.1.0/bitstraining/data/__init__.py +25 -0
  30. bitstraining-0.1.0/bitstraining/data/clean.py +147 -0
  31. bitstraining-0.1.0/bitstraining/data/loaders.py +135 -0
  32. bitstraining-0.1.0/bitstraining/data/pack.py +100 -0
  33. bitstraining-0.1.0/bitstraining/data/schema.py +123 -0
  34. bitstraining-0.1.0/bitstraining/data/split.py +42 -0
  35. bitstraining-0.1.0/bitstraining/data/stats.py +143 -0
  36. bitstraining-0.1.0/bitstraining/deploy/__init__.py +6 -0
  37. bitstraining-0.1.0/bitstraining/deploy/modelcard.py +41 -0
  38. bitstraining-0.1.0/bitstraining/deploy/serve.py +21 -0
  39. bitstraining-0.1.0/bitstraining/engines/__init__.py +19 -0
  40. bitstraining-0.1.0/bitstraining/engines/base.py +120 -0
  41. bitstraining-0.1.0/bitstraining/engines/deepspeed.py +44 -0
  42. bitstraining-0.1.0/bitstraining/engines/hf_peft.py +325 -0
  43. bitstraining-0.1.0/bitstraining/engines/mlx.py +100 -0
  44. bitstraining-0.1.0/bitstraining/engines/simulate.py +138 -0
  45. bitstraining-0.1.0/bitstraining/engines/unsloth.py +66 -0
  46. bitstraining-0.1.0/bitstraining/eval/__init__.py +17 -0
  47. bitstraining-0.1.0/bitstraining/eval/audit.py +63 -0
  48. bitstraining-0.1.0/bitstraining/eval/gate.py +69 -0
  49. bitstraining-0.1.0/bitstraining/eval/generate.py +51 -0
  50. bitstraining-0.1.0/bitstraining/eval/metrics.py +48 -0
  51. bitstraining-0.1.0/bitstraining/hardware/__init__.py +6 -0
  52. bitstraining-0.1.0/bitstraining/hardware/database.py +125 -0
  53. bitstraining-0.1.0/bitstraining/hardware/profiler.py +243 -0
  54. bitstraining-0.1.0/bitstraining/interfaces/__init__.py +1 -0
  55. bitstraining-0.1.0/bitstraining/interfaces/api.py +266 -0
  56. bitstraining-0.1.0/bitstraining/interfaces/cli.py +496 -0
  57. bitstraining-0.1.0/bitstraining/models/__init__.py +10 -0
  58. bitstraining-0.1.0/bitstraining/models/introspect.py +228 -0
  59. bitstraining-0.1.0/bitstraining/optimize/__init__.py +6 -0
  60. bitstraining-0.1.0/bitstraining/optimize/merge.py +26 -0
  61. bitstraining-0.1.0/bitstraining/optimize/quantize.py +37 -0
  62. bitstraining-0.1.0/bitstraining/planner/__init__.py +15 -0
  63. bitstraining-0.1.0/bitstraining/planner/calibration.py +62 -0
  64. bitstraining-0.1.0/bitstraining/planner/doctor.py +215 -0
  65. bitstraining-0.1.0/bitstraining/planner/memory.py +126 -0
  66. bitstraining-0.1.0/bitstraining/planner/search.py +368 -0
  67. bitstraining-0.1.0/bitstraining/planner/throughput.py +154 -0
  68. bitstraining-0.1.0/bitstraining/py.typed +0 -0
  69. bitstraining-0.1.0/bitstraining/runner.py +71 -0
  70. bitstraining-0.1.0/bitstraining/strategies/__init__.py +10 -0
  71. bitstraining-0.1.0/bitstraining/strategies/catalog.py +42 -0
  72. bitstraining-0.1.0/bitstraining/tracking/__init__.py +5 -0
  73. bitstraining-0.1.0/bitstraining/tracking/registry.py +208 -0
  74. bitstraining-0.1.0/bitstraining.egg-info/PKG-INFO +228 -0
  75. bitstraining-0.1.0/bitstraining.egg-info/SOURCES.txt +98 -0
  76. bitstraining-0.1.0/bitstraining.egg-info/dependency_links.txt +1 -0
  77. bitstraining-0.1.0/bitstraining.egg-info/entry_points.txt +17 -0
  78. bitstraining-0.1.0/bitstraining.egg-info/requires.txt +29 -0
  79. bitstraining-0.1.0/bitstraining.egg-info/top_level.txt +1 -0
  80. bitstraining-0.1.0/docs/architecture.md +79 -0
  81. bitstraining-0.1.0/docs/bitstraining.png +0 -0
  82. bitstraining-0.1.0/docs/plugins.md +45 -0
  83. bitstraining-0.1.0/examples/configs/chat_sft.yaml +17 -0
  84. bitstraining-0.1.0/examples/configs/free_colab.yaml +19 -0
  85. bitstraining-0.1.0/examples/configs/rented_gpu_budget.yaml +24 -0
  86. bitstraining-0.1.0/examples/custom_provider.py +99 -0
  87. bitstraining-0.1.0/pyproject.toml +88 -0
  88. bitstraining-0.1.0/setup.cfg +4 -0
  89. bitstraining-0.1.0/tests/conftest.py +67 -0
  90. bitstraining-0.1.0/tests/test_autotune_tracking_eval.py +168 -0
  91. bitstraining-0.1.0/tests/test_compute.py +264 -0
  92. bitstraining-0.1.0/tests/test_core.py +97 -0
  93. bitstraining-0.1.0/tests/test_data.py +149 -0
  94. bitstraining-0.1.0/tests/test_docs_examples.py +66 -0
  95. bitstraining-0.1.0/tests/test_end_to_end.py +180 -0
  96. bitstraining-0.1.0/tests/test_engines_deploy.py +134 -0
  97. bitstraining-0.1.0/tests/test_installed.py +13 -0
  98. bitstraining-0.1.0/tests/test_models_and_memory.py +135 -0
  99. bitstraining-0.1.0/tests/test_planner.py +192 -0
  100. bitstraining-0.1.0/tests/test_portability.py +77 -0
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ Format follows Keep a Changelog; versions follow SemVer. Entries say which earlier *results* could be
4
+ affected, because for a planner that matters as much as API changes.
5
+
6
+ ## 0.1.0 - initial release
7
+
8
+ First working version: planner, data pipeline, autotune, tracking, compute orchestration, eval gate,
9
+ CLI and Python API. See the README "Status & honesty" table for what is verified and what is not.
10
+
11
+ ### Bugs found and fixed by the test suite before release
12
+ * **Duplicate detection missed whitespace-only differences** at message boundaries (`"Q1 "` vs `"q1"`),
13
+ letting near-identical rows into training and across the train/eval split. Normalization is now per
14
+ message.
15
+ * **GPU lookup returned the 40 GB A100 for `A100-SXM4-80GB`** (the string `nvidia-smi` reports) because only
16
+ the exact key `a100-80gb` matched. The memory size in the name is now honored.
17
+ * **Layer streaming was modeled as free** when compute exceeded transfer time; an imperfect-overlap term
18
+ (a labeled heuristic) is now included.
19
+ * **Plan confidence was overstated**: uncalibrated estimates were reported as "medium". They are now "low"
20
+ until a real probe calibrates the hardware.
21
+
22
+ ### Found by a user run on Windows 11, fixed in 0.1.0
23
+ * **RAM was not detected on Windows**, so a machine without a GPU was modeled as a 0 GB device and every
24
+ plan was reported infeasible (6 of 150 tests failed on that machine; the other 144 passed). RAM is now
25
+ read through Windows, POSIX `sysconf`, `/proc` and `sysctl` probes. If none work the planner assumes 8 GB
26
+ and the doctor warns (DR050) instead of silently planning for nothing.
27
+ * `LocalProvider.cancel` used `os.killpg` (POSIX only) and would have failed on Windows once planning
28
+ succeeded; it now falls back to `terminate()`.
29
+ Verified by reproducing the failure on Linux (forcing RAM detection to 0) and adding regression tests.
30
+ **Not yet re-run on Windows itself.**
31
+
32
+ ### Found by the first GitHub Actions run on macOS and Windows, fixed in 0.1.0
33
+ * **macOS (Apple Silicon): undetected RAM produced a 0 GB Apple GPU**, so every plan was infeasible (the same
34
+ failure as on Windows, through a second code path). Unknown RAM now means "no Apple GPU modeled".
35
+ * **Windows: `examples/custom_provider.py` launched the runner with an environment containing only `PATH=/usr/bin:/bin`.**
36
+ Windows Python needs variables such as `SYSTEMROOT`, so the job failed and no results were fetched. The
37
+ example now passes the full environment. Fixed from the traceback and a minimal-environment run on Linux;
38
+ **not re-run on Windows or macOS.**
39
+
40
+ ### Known gaps
41
+ No validation against real GPU runs; `hf_peft`, `unsloth`, `mlx`, `ssh` and `docker` paths have never
42
+ been executed end to end; no layer-streaming or sharded (FSDP/ZeRO) engine; no preference/RL training;
43
+ no web UI or MCP server; no real cloud provisioning.
@@ -0,0 +1,16 @@
1
+ # Code of Conduct
2
+
3
+ We want Bitstraining to be a place where students, researchers and engineers can ask questions and
4
+ contribute without being made to feel small.
5
+
6
+ **Expected:** be respectful and patient; assume good faith; give specific, kind feedback; credit other
7
+ people's work; keep discussion about the work, not the person.
8
+
9
+ **Not acceptable:** harassment, discrimination, personal attacks, doxxing, sexualized language or
10
+ attention, sustained disruption, or publishing others' private information.
11
+
12
+ **Enforcement:** maintainers may edit, hide or remove contributions and may restrict participation for
13
+ behavior that violates this code. Report concerns privately to the maintainers listed in the repository;
14
+ reports are handled confidentially and in good faith.
15
+
16
+ This applies in all project spaces: issues, pull requests, discussions and any chat the project runs.
@@ -0,0 +1,45 @@
1
+ # Contributing to Bitstraining
2
+
3
+ Thanks for helping. The project's rule is simple: **numbers are measured, not claimed.**
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ git clone <your fork> && cd bitstraining
9
+ python -m venv .venv && source .venv/bin/activate
10
+ pip install -e ".[dev]"
11
+ pytest && ruff check bitstraining tests
12
+ ```
13
+
14
+ The suite needs no GPU and runs in seconds. If you add code that needs torch, import it inside the
15
+ function, never at module top level (a test enforces that listing plugins imports no heavy library).
16
+
17
+ ## What makes a good change
18
+
19
+ * **Fix with a test.** Reproduce the bug in a test first. Several real bugs in this codebase were found
20
+ that way (see CHANGELOG).
21
+ * **Test the property, not the call.** "Packing returns a valid partition within capacity" beats
22
+ "packing returns a list". Before sending a PR touching critical logic (memory model, orchestrator budget
23
+ cap, eval gate, packing, dedup, spike detection), try breaking it on purpose; if the suite stays green,
24
+ the tests are too weak.
25
+ * **Heuristics are labeled.** A constant that is an engineering guess (MFU, overheads, overlap loss)
26
+ lives in one named place with a comment saying so, and calibration can override it.
27
+ * **Errors carry fixes.** Raise `BitstrainingError` subclasses with `fix=` text that says what to do.
28
+ * **Honest status.** If you add something you could not run (no GPU, no remote host), say so in the module
29
+ docstring and in the README status table. "Written, never run" is acceptable; implying otherwise is not.
30
+
31
+ ## Adding an engine or provider
32
+
33
+ See [docs/plugins.md](docs/plugins.md). Include unit tests for everything that does not need the real
34
+ backend (command construction, data encoding, status mapping) and mark the rest as unverified.
35
+
36
+ ## Performance and accuracy claims
37
+
38
+ Do not add speed-up claims or comparisons with other tools without a reproducible measurement:
39
+ hardware, library versions, command, raw output. Predicted-vs-measured results from `bitstraining
40
+ autotune` are welcome as issues; they are how the cost model gets better.
41
+
42
+ ## Pull requests
43
+
44
+ Small and focused. Describe what changed, how you verified it, and what you could *not* verify.
45
+ By contributing you agree your work is licensed under Apache-2.0.
@@ -0,0 +1,177 @@
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
@@ -0,0 +1,4 @@
1
+ include LICENSE README.md CHANGELOG.md CONTRIBUTING.md CODE_OF_CONDUCT.md RELEASING.md
2
+ recursive-include docs *.md *.png
3
+ recursive-include examples *.py *.yaml
4
+ recursive-include tests *.py
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: bitstraining
3
+ Version: 0.1.0
4
+ Summary: Hardware-aware AI model training, fine-tuning, optimization and deployment framework.
5
+ Author: Bitstraining contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Sudharsansm/bitstraining
8
+ Project-URL: Repository, https://github.com/Sudharsansm/bitstraining
9
+ Project-URL: Issues, https://github.com/Sudharsansm/bitstraining/issues
10
+ Project-URL: Changelog, https://github.com/Sudharsansm/bitstraining/blob/main/CHANGELOG.md
11
+ Keywords: llm,fine-tuning,training,planner,lora,qlora,gpu
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pyyaml>=6.0
24
+ Provides-Extra: train
25
+ Requires-Dist: torch>=2.3; extra == "train"
26
+ Requires-Dist: transformers>=4.44; extra == "train"
27
+ Requires-Dist: peft>=0.11; extra == "train"
28
+ Requires-Dist: datasets>=2.19; extra == "train"
29
+ Requires-Dist: accelerate>=0.30; extra == "train"
30
+ Provides-Extra: quant
31
+ Requires-Dist: bitsandbytes>=0.43; extra == "quant"
32
+ Provides-Extra: fast
33
+ Requires-Dist: unsloth; extra == "fast"
34
+ Provides-Extra: mlx
35
+ Requires-Dist: mlx-lm; extra == "mlx"
36
+ Provides-Extra: parquet
37
+ Requires-Dist: pyarrow>=14; extra == "parquet"
38
+ Provides-Extra: numpy
39
+ Requires-Dist: numpy>=1.26; extra == "numpy"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=8; extra == "dev"
42
+ Requires-Dist: ruff>=0.5; extra == "dev"
43
+ Requires-Dist: mypy>=1.10; extra == "dev"
44
+ Requires-Dist: types-PyYAML; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ <div align="center">
48
+
49
+ <a href="docs/bitstraining.png"><img src="docs/bitstraining.png" alt="Bitstraining" width="200"></a>
50
+
51
+ # Bitstraining
52
+
53
+ <a href="https://pypi.org/project/bitstraining/"><img src="https://img.shields.io/pypi/v/bitstraining.svg" alt="PyPI version"></a>
54
+ <a href="https://pypi.org/project/bitstraining/"><img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue.svg" alt="Python versions"></a>
55
+ <a href="https://github.com/Sudharsansm/bitstraining/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Sudharsansm/bitstraining.svg" alt="License"></a>
56
+
57
+ **Train. Fine-tune. Optimize. Deploy.**
58
+
59
+ </div>
60
+
61
+ Bitstraining is a hardware-aware orchestration layer for fine-tuning language models. You describe a
62
+ *goal and constraints* (model, data, time or budget); it profiles the hardware, **predicts memory,
63
+ speed and cost for many candidate strategies, ranks them**, checks your setup before any GPU time is
64
+ spent, verifies the winner with a short real probe, runs it locally or on other compute, and tracks
65
+ everything that happened.
66
+
67
+ It does not reimplement training. PyTorch / Transformers / PEFT, Unsloth and MLX stay swappable
68
+ engines behind one small interface. The part that is Bitstraining's own is the planner, the compute
69
+ orchestration, the data tooling, evaluation gate, and run tracking.
70
+
71
+ > **Read [Status & honesty](#status--honesty) before relying on any number.** The planner's
72
+ > predictions are model-based estimates that have **not** been validated against real GPU runs yet, and
73
+ > nothing here has been benchmarked against other tools. The mechanism is built to make that
74
+ > measurement easy (`bitstraining autotune`), not to assume the answer.
75
+
76
+ ```
77
+ goal + constraints ─► hardware profile ─► cost model ─► ranked plans ─► doctor ─► probe/autotune
78
+ │
79
+ model card ◄─ eval gate ◄─ tracked run ◄─ engine (HF/PEFT, Unsloth, MLX) ◄─ compute (local/ssh/docker/notebook)
80
+ ```
81
+
82
+ ## Install
83
+
84
+ ```bash
85
+ pip install bitstraining # core: planner, data tools, tracking, orchestration, eval. Needs only PyYAML.
86
+ pip install "bitstraining[train]" # + torch, transformers, peft, datasets, accelerate (real training)
87
+ pip install "bitstraining[train,quant]" # + bitsandbytes (QLoRA, 8-bit optimizers)
88
+ pip install "bitstraining[fast]" # + unsloth | "[mlx]" for Apple Silicon | "[parquet]"
89
+ ```
90
+
91
+ (From a source checkout, use `pip install .` and `pip install ".[train]"` instead. Docker is never
92
+ required; the optional `docker` compute provider is only used if you select it.)
93
+
94
+ Python 3.10+ (the CPU test suite passes on 3.10, 3.11, 3.12 and 3.13 on Linux).
95
+
96
+ With [uv](https://docs.astral.sh/uv/) (verified: `uv venv`, `uv pip install -e ".[dev]"`, `uv run`, `uv tool install`):
97
+
98
+ ```bash
99
+ uv venv && uv pip install -e ".[dev]"
100
+ uv run pytest
101
+ uv tool install . # puts `bitstraining` and `bt` on your PATH
102
+ ```
103
+
104
+ **Platforms:** developed and tested on Linux. A run on Windows 11 found and fixed a RAM-detection bug (see
105
+ CHANGELOG); Windows has not been re-verified since, and macOS has not been tested. Please report problems.
106
+
107
+ ## Try it in 30 seconds, no GPU needed
108
+
109
+ ```bash
110
+ bitstraining quickstart
111
+ ```
112
+
113
+ This runs the whole pipeline (load data, plan, doctor, run, track) with the **simulation engine**,
114
+ which trains nothing and labels every artifact `simulated`. It exists so you can see the system work
115
+ and so CI can test orchestration without hardware.
116
+
117
+ ## A real workflow
118
+
119
+ ```bash
120
+ bitstraining init --template chat -o run.yaml # starter config; edit model.base and data.train
121
+ bitstraining data inspect data/train.jsonl # schema, token stats, truncation, padding waste
122
+ bitstraining profile # what hardware you actually have
123
+
124
+ bitstraining plan -c run.yaml # ranked plans for THIS machine
125
+ bitstraining plan -c run.yaml --gpu a100-80gb --price 2.5 # what-if for rented hardware, with cost
126
+ bitstraining doctor -c run.yaml # pre-flight: errors come with fixes
127
+ bitstraining autotune -c run.yaml # real probe: finds the micro-batch, calibrates the model
128
+ bitstraining train -c run.yaml --tune # plan -> check -> run -> track
129
+
130
+ bitstraining runs list # history
131
+ bitstraining runs spikes # trace a loss spike back to the training rows
132
+ bitstraining eval --task preds.jsonl --general general.jsonl # per-row audit + forgetting gate
133
+ bitstraining card # model card with data hash and lineage
134
+ bitstraining serve --model ./output --backend vllm # prints/starts an OpenAI-compatible server
135
+ ```
136
+
137
+ `run.yaml`:
138
+
139
+ ```yaml
140
+ name: support-bot
141
+ model: { base: meta-llama/Llama-3.1-8B-Instruct }
142
+ data: { train: ./data/train.jsonl, max_length: 1024, eval_split: 0.05 }
143
+ goal: { task: sft, epochs: 3, global_batch_size: 16, objective: time, budget_usd: 20 }
144
+ compute: { provider: local } # or ssh / docker / notebook (see below)
145
+ output: ./output
146
+ ```
147
+
148
+ ## What it does
149
+
150
+ | Area | Capability |
151
+ |---|---|
152
+ | **Planner** | Analytic GPU-memory model (weights, adapters, gradients, optimizer, activations, logits, context) and roofline throughput model. Searches method (full / LoRA / QLoRA / DoRA), activation checkpointing, optimizer (AdamW / 8-bit / paged), micro-batch, packing, attention kernel, FSDP/DDP. Ranks by time, cost or memory and respects budgets. |
153
+ | **Honest uncertainty** | Every plan carries a confidence level. It is `low` until a real probe has calibrated the model on your hardware. |
154
+ | **Doctor** | ~30 pre-flight checks (config sanity, schema/task mismatch, truncation, duplicates, train/eval leakage, resource fit, missing packages) each with a concrete fix. |
155
+ | **Autotune** | OOM-safe binary search for the largest micro-batch (a good hint costs 2-3 probes); learns measured/predicted ratios per hardware+engine+method; caches results. |
156
+ | **Data** | JSONL/JSON/CSV/TSV/TXT/Parquet/HF; auto schema detection (alpaca, chat, ShareGPT, prompt/completion, preference, raw text); cleaning; exact + MinHash near-duplicate removal; leakage-safe splits; packing and padding-waste analysis. |
157
+ | **Compute** | One job description, many places: `local` (subprocess), `ssh` (any GPU box), `docker`, `notebook` (self-running Colab/Kaggle notebook), `catalog` (illustrative price list for planning). Hard budget cap, wall-clock cap, auto-resume after preemption, guaranteed teardown. |
158
+ | **Tracking** | SQLite registry: runs, plans, metrics, artifacts with hashes, lineage from data hash to model. Per-step batch row ids let a loss spike be traced to the rows behind it. |
159
+ | **Eval** | Metrics, per-row better/worse/same audit, forgetting check, and a gate that blocks export on regressions. Pluggable judge: any `(prediction, reference) -> float`. |
160
+ | **Deploy** | Model cards, merge LoRA into base, GGUF export via llama.cpp, serve via vLLM or llama.cpp. |
161
+
162
+ ## Compute targets
163
+
164
+ ```yaml
165
+ compute: { provider: ssh, options: { host: ubuntu@203.0.113.7, gpu: a100-80gb, price_per_hour: 1.9 } }
166
+ compute: { provider: docker, options: { image: pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime } }
167
+ compute: { provider: notebook, options: { target: colab } } # writes a notebook; you press Run all
168
+ ```
169
+
170
+ The runner ships inside a *bundle* (spec, plan, data, a copy of this package), so remote machines
171
+ don't need Bitstraining installed. Colab and Kaggle cannot be driven unattended, so the notebook provider is
172
+ deliberately manual: it embeds the bundle in one notebook and you download `output.zip` afterwards
173
+ (`bitstraining compute fetch --zip output.zip`).
174
+
175
+ ## Extending
176
+
177
+ Engines and providers are plugins, discovered through Python entry points (or `registry.register(...)`
178
+ at runtime). See [docs/plugins.md](docs/plugins.md) and `examples/custom_provider.py`.
179
+
180
+ ## Status & honesty
181
+
182
+ This table is the source of truth. "Verified" means exercised by the automated test suite
183
+ (the CPU-only test suite, including real subprocess jobs); it does **not** mean validated on GPUs.
184
+
185
+ | Component | State |
186
+ |---|---|
187
+ | Planner (memory, throughput, search, doctor), calibration, autotune loop | **Verified** logic; parameter counts checked against published sizes (<1% error for 7 models). **Not validated** against real GPU measurements. |
188
+ | Data pipeline, tracking, eval/gate, model cards, orchestrator, bundle, local subprocess provider, notebook builder | **Verified** by tests, including mutation checks on the critical logic. |
189
+ | `hf_peft` engine | **Written, never run** against real torch/GPU in this repo (no GPU available during development). Prompt masking and tokenization logic is unit-tested with a stub tokenizer. Treat first use as a smoke test. |
190
+ | `unsloth`, `mlx` engines | **Written, never run.** Experimental. |
191
+ | `ssh`, `docker` providers | Command construction **unit-tested**; **never run** against a real host/daemon. |
192
+ | Layer streaming, FSDP/DeepSpeed, DPO/ORPO/KTO/GRPO training, pruning, distillation | **Not implemented.** The planner can *model* streaming and FSDP; no bundled real engine executes them. Preference tasks are rejected cleanly at planning time. |
193
+ | Web UI, MCP server, real cloud provisioning (RunPod, Lambda, AWS...) | **Not implemented.** `catalog` is a planning-only price list with illustrative numbers. |
194
+
195
+ **On "faster and more efficient".** The efficiency mechanisms that exist are: choosing QLoRA/LoRA vs full
196
+ fine-tuning by what fits, activation checkpointing only when memory demands it, 8-bit optimizers,
197
+ packing/length-grouping to cut padding waste, largest-safe micro-batch search, and cost-aware hardware
198
+ comparison. The planner quantifies their *predicted* effect. **No benchmark here shows Bitstraining
199
+ trains faster than Axolotl, LLaMA-Factory, Unsloth or plain Transformers**, and none should be assumed.
200
+ Speed-ups quoted by other libraries are theirs, not ours; use `bitstraining autotune` to measure on
201
+ your hardware.
202
+
203
+ Model constants that are heuristics, not measurements (all in one place, all tunable by calibration):
204
+ base MFU 0.42, QLoRA time overhead 1.20, DoRA 1.25, layer-streaming overlap loss 0.30, token
205
+ estimate of 3.8 characters per token when no tokenizer is available, and the GPU table's peak-FLOP
206
+ figures.
207
+
208
+ ## Documentation
209
+
210
+ * [Architecture](docs/architecture.md): how the planner, engines, compute providers and tracking fit together
211
+ * [Writing plugins](docs/plugins.md): custom engines and compute providers (`examples/custom_provider.py`)
212
+ * [Releasing](RELEASING.md): publishing to PyPI from GitHub
213
+ * [Changelog](CHANGELOG.md): includes which earlier *results* a fix could have affected
214
+
215
+ ## Development
216
+
217
+ ```bash
218
+ pip install -e ".[dev]"
219
+ pytest # a few seconds, no GPU
220
+ ruff check bitstraining tests
221
+ ```
222
+
223
+ See [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
224
+
225
+ ## License
226
+
227
+ Apache-2.0. Bitstraining was inspired by the single-config, pre-flight-check, measured-numbers ethos of
228
+ projects such as Soup CLI (trysoup.dev); it shares no code with them.