axolotl-ringmaster 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 (73) hide show
  1. axolotl_ringmaster-0.1.0/.github/workflows/release.yml +52 -0
  2. axolotl_ringmaster-0.1.0/.gitignore +40 -0
  3. axolotl_ringmaster-0.1.0/LICENSE +202 -0
  4. axolotl_ringmaster-0.1.0/PKG-INFO +171 -0
  5. axolotl_ringmaster-0.1.0/README.md +148 -0
  6. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/PKG-INFO +171 -0
  7. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/SOURCES.txt +71 -0
  8. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/dependency_links.txt +1 -0
  9. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/requires.txt +8 -0
  10. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/scm_file_list.json +68 -0
  11. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/scm_version.json +8 -0
  12. axolotl_ringmaster-0.1.0/axolotl_ringmaster.egg-info/top_level.txt +1 -0
  13. axolotl_ringmaster-0.1.0/examples/cp_fsdp2/axolotl/llama3-8b-cp-fsdp2.yaml +66 -0
  14. axolotl_ringmaster-0.1.0/examples/cp_fsdp2/axolotl/nemotron-h-cp-fsdp2.yaml +93 -0
  15. axolotl_ringmaster-0.1.0/examples/cp_fsdp2/axolotl/qwen3.5-cp-fsdp2.yaml +73 -0
  16. axolotl_ringmaster-0.1.0/examples/cp_fsdp2/trl_cp_fsdp2.py +239 -0
  17. axolotl_ringmaster-0.1.0/examples/qwen35_axolotl_cp_fsdp.yaml +44 -0
  18. axolotl_ringmaster-0.1.0/examples/qwen35_trl_cp_smoke.py +155 -0
  19. axolotl_ringmaster-0.1.0/examples/run_cp_smoke.sh +34 -0
  20. axolotl_ringmaster-0.1.0/examples/trl_cp.py +82 -0
  21. axolotl_ringmaster-0.1.0/pyproject.toml +40 -0
  22. axolotl_ringmaster-0.1.0/ringmaster/__init__.py +127 -0
  23. axolotl_ringmaster-0.1.0/ringmaster/adapters/__init__.py +3 -0
  24. axolotl_ringmaster-0.1.0/ringmaster/adapters/accelerate.py +51 -0
  25. axolotl_ringmaster-0.1.0/ringmaster/adapters/raw.py +28 -0
  26. axolotl_ringmaster-0.1.0/ringmaster/balancers.py +29 -0
  27. axolotl_ringmaster-0.1.0/ringmaster/comm.py +90 -0
  28. axolotl_ringmaster-0.1.0/ringmaster/compat.py +35 -0
  29. axolotl_ringmaster-0.1.0/ringmaster/config.py +90 -0
  30. axolotl_ringmaster-0.1.0/ringmaster/cp_collectives.py +57 -0
  31. axolotl_ringmaster-0.1.0/ringmaster/loss.py +46 -0
  32. axolotl_ringmaster-0.1.0/ringmaster/memory/__init__.py +8 -0
  33. axolotl_ringmaster-0.1.0/ringmaster/mesh.py +139 -0
  34. axolotl_ringmaster-0.1.0/ringmaster/multimodal.py +49 -0
  35. axolotl_ringmaster-0.1.0/ringmaster/parallelism.py +64 -0
  36. axolotl_ringmaster-0.1.0/ringmaster/profiling.py +99 -0
  37. axolotl_ringmaster-0.1.0/ringmaster/ring/__init__.py +10 -0
  38. axolotl_ringmaster-0.1.0/ringmaster/ring/distflash.py +291 -0
  39. axolotl_ringmaster-0.1.0/ringmaster/ring/kernels.py +80 -0
  40. axolotl_ringmaster-0.1.0/ringmaster/ring/loop.py +158 -0
  41. axolotl_ringmaster-0.1.0/ringmaster/ring/merge.py +31 -0
  42. axolotl_ringmaster-0.1.0/ringmaster/ring/p2p_attn.py +259 -0
  43. axolotl_ringmaster-0.1.0/ringmaster/ring/varlen_blocks.py +203 -0
  44. axolotl_ringmaster-0.1.0/ringmaster/ring/zigzag.py +260 -0
  45. axolotl_ringmaster-0.1.0/ringmaster/runtime.py +91 -0
  46. axolotl_ringmaster-0.1.0/ringmaster/shard.py +152 -0
  47. axolotl_ringmaster-0.1.0/ringmaster/sp_context.py +154 -0
  48. axolotl_ringmaster-0.1.0/ringmaster/strategies/__init__.py +11 -0
  49. axolotl_ringmaster-0.1.0/ringmaster/strategies/linear_attn.py +236 -0
  50. axolotl_ringmaster-0.1.0/ringmaster/strategies/mamba.py +306 -0
  51. axolotl_ringmaster-0.1.0/ringmaster/strategies/ring.py +134 -0
  52. axolotl_ringmaster-0.1.0/ringmaster/strategies/state_passing.py +119 -0
  53. axolotl_ringmaster-0.1.0/ringmaster/strategies/ulysses.py +180 -0
  54. axolotl_ringmaster-0.1.0/ringmaster/strategies/usp.py +158 -0
  55. axolotl_ringmaster-0.1.0/setup.cfg +4 -0
  56. axolotl_ringmaster-0.1.0/tests/test_alltoall.py +57 -0
  57. axolotl_ringmaster-0.1.0/tests/test_core.py +122 -0
  58. axolotl_ringmaster-0.1.0/tests/test_distflash_cpu.py +117 -0
  59. axolotl_ringmaster-0.1.0/tests/test_distflash_gpu.py +79 -0
  60. axolotl_ringmaster-0.1.0/tests/test_e2e_ring_parity.py +111 -0
  61. axolotl_ringmaster-0.1.0/tests/test_e2e_ulysses_parity.py +108 -0
  62. axolotl_ringmaster-0.1.0/tests/test_linear_attn_cp_kernel.py +88 -0
  63. axolotl_ringmaster-0.1.0/tests/test_mamba_cp.py +136 -0
  64. axolotl_ringmaster-0.1.0/tests/test_mamba_cp_kernel.py +83 -0
  65. axolotl_ringmaster-0.1.0/tests/test_p2p_gpu.py +85 -0
  66. axolotl_ringmaster-0.1.0/tests/test_ring_cpu.py +99 -0
  67. axolotl_ringmaster-0.1.0/tests/test_state_passing.py +106 -0
  68. axolotl_ringmaster-0.1.0/tests/test_usp_cpu.py +77 -0
  69. axolotl_ringmaster-0.1.0/tests/test_varlen_cp.py +282 -0
  70. axolotl_ringmaster-0.1.0/tests/test_varlen_flash_block.py +95 -0
  71. axolotl_ringmaster-0.1.0/tests/test_varlen_gpu.py +94 -0
  72. axolotl_ringmaster-0.1.0/tests/test_varlen_plugin.py +107 -0
  73. axolotl_ringmaster-0.1.0/tests/test_zigzag_shard.py +83 -0
@@ -0,0 +1,52 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
17
+ with:
18
+ persist-credentials: false
19
+ fetch-depth: 0 # setuptools-scm derives the version from the tag
20
+ - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
21
+ with:
22
+ python-version: "3.12"
23
+ - name: Build sdist and wheel
24
+ run: |
25
+ python -m pip install --upgrade build twine
26
+ python -m build
27
+ twine check dist/*
28
+ - name: Smoke-test the wheel
29
+ run: |
30
+ python -m venv /tmp/smoke
31
+ /tmp/smoke/bin/pip install torch --index-url https://download.pytorch.org/whl/cpu
32
+ /tmp/smoke/bin/pip install dist/*.whl
33
+ /tmp/smoke/bin/python -c "import ringmaster; print(ringmaster.__version__)"
34
+ - uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+
39
+ publish:
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ environment:
43
+ name: pypi
44
+ url: https://pypi.org/p/axolotl-ringmaster
45
+ permissions:
46
+ id-token: write # PyPI trusted publishing (OIDC)
47
+ steps:
48
+ - uses: actions/download-artifact@v4
49
+ with:
50
+ name: dist
51
+ path: dist/
52
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,40 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ *.egg
11
+ .eggs/
12
+
13
+ # Virtual envs
14
+ .venv/
15
+ venv/
16
+ env/
17
+
18
+ # Test / lint / type caches
19
+ .pytest_cache/
20
+ .cache/
21
+ .coverage
22
+ .coverage.*
23
+ htmlcov/
24
+ .mypy_cache/
25
+ .ruff_cache/
26
+ .dmypy.json
27
+
28
+ # Training / example artifacts
29
+ outputs/
30
+ last_run_prepared/
31
+ wandb/
32
+ *.log
33
+ checkpoint-*/
34
+ runs/
35
+
36
+ # Editor / OS
37
+ .idea/
38
+ .vscode/
39
+ .DS_Store
40
+ *.swp
@@ -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,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: axolotl-ringmaster
3
+ Version: 0.1.0
4
+ Summary: Composable long-context attention: Ulysses / Ring / USP sequence parallelism for any framework
5
+ Author: Axolotl AI
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/axolotl-ai-cloud/ringmaster
8
+ Project-URL: Repository, https://github.com/axolotl-ai-cloud/ringmaster
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: torch>=2.11
17
+ Provides-Extra: transformers
18
+ Requires-Dist: transformers>=5.9; extra == "transformers"
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest; extra == "dev"
21
+ Requires-Dist: transformers>=5.9; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # ringmaster
25
+
26
+ Composable long-context attention for distributed LLM training. Ulysses / Ring /
27
+ USP sequence parallelism that **wraps existing kernels** instead of shipping its
28
+ own — so it rides HuggingFace `kernels` Flash-Attention (FA2/FA3/FA4), torch SDPA,
29
+ and FlexAttention, with **no `flash_attn` pypi dependency**. Framework-neutral
30
+ core; thin adapters for axolotl, trl/accelerate, and raw PyTorch.
31
+
32
+ ## Why
33
+
34
+ `ring-flash-attn` (the previous CP path) depends on the `flash_attn` pypi package,
35
+ which is no longer installed now that attention comes from HF `kernels`. ringmaster
36
+ takes two routes that avoid that dependency entirely:
37
+
38
+ - **Ulysses** wraps the model's *own* attention kernel with all-to-all on the head
39
+ dim — works with any kernel (FA2/3/4/sdpa/flex), inherently load-balanced, the
40
+ cheapest comm. Capped by KV-head count.
41
+ - **Ring** rides torch-native context parallel (`torch.distributed.tensor.experimental`)
42
+ on the SDPA/FlexAttention backends — no head cap, scales linearly. LSE merging
43
+ is handled inside aten, so we never reimplement a ring kernel.
44
+ - **USP** composes the two on a 2D mesh (Ulysses intra-node, Ring inter-node).
45
+
46
+ An **auto-selector** picks the `ulysses_size × ring_size` split from KV-head count,
47
+ world size, and intra-node topology.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install axolotl-ringmaster
53
+ ```
54
+
55
+ The distribution is `axolotl-ringmaster` (the unrelated `ringmaster` name was taken
56
+ on PyPI); the import name is `ringmaster`.
57
+
58
+ ## Quickstart
59
+
60
+ Requires **torch ≥ 2.11**. The framework adapters do this for you; the raw shape is:
61
+
62
+ ```python
63
+ import ringmaster as rm
64
+
65
+ cfg = rm.RingmasterConfig(size=8, backend=rm.Backend.AUTO)
66
+ runtime = rm.setup(cfg, num_kv_heads=8, device_mesh=mesh) # mesh has a "cp" dim
67
+ model.set_attn_implementation(runtime.attn_implementation)
68
+ rm.wire_recurrent_layers(model) # no-op for plain attention
69
+
70
+ from ringmaster.adapters.raw import context_parallel_region
71
+ for batch in loader:
72
+ with context_parallel_region(batch) as shard: # contiguous seq shard
73
+ loss = model(**shard).loss
74
+ loss.backward()
75
+ ```
76
+
77
+ Pair CP with **FSDP2** (a `dp_shard × cp` mesh), not plain DDP — FSDP2's gradient
78
+ reduce-scatter sums the CP-partial gradients; DDP would mis-reduce. See
79
+ [docs/concepts.md](docs/concepts.md#device-mesh-and-fsdp2-composition).
80
+
81
+ ## Documentation
82
+
83
+ - [docs/concepts.md](docs/concepts.md) — backends (Ulysses/Ring/USP), rotate
84
+ methods, load balancing, device-mesh / FSDP2 composition, and when to use which.
85
+ - [docs/integration.md](docs/integration.md) — raw PyTorch, trl/accelerate
86
+ (`CPSFTTrainer` + `ParallelismConfig` + `chunked_nll`), and axolotl (plugin + YAML).
87
+ - [docs/api.md](docs/api.md) — concise reference of the public API.
88
+ - [docs/models.md](docs/models.md) — plain attention, gated linear-attention
89
+ (Qwen3.5/Next), Mamba2 hybrids (Nemotron-H), and the sm_120 shim.
90
+ - [examples/cp_fsdp2/](examples/cp_fsdp2/) — worked TRL + FSDP2 script and axolotl
91
+ configs for all three model families, plus a CP-vs-non-CP benchmark table.
92
+
93
+ ## Status
94
+
95
+ Requires **torch ≥ 2.11**.
96
+
97
+ | Phase | Feature | State |
98
+ |-------|---------|-------|
99
+ | 0 | Package scaffold, config, mesh, runtime, registry, loss | ✅ |
100
+ | 1 | Ulysses backend (wraps HF kernels FA2/3/4/sdpa) | ✅ GPU-validated — sdpa + flash parity, fwd+bwd |
101
+ | 2 | Ring — kernel-agnostic loop; **p2p (memory-optimal, fwd+bwd) + allgather (fast)** rotaters; `hf_kernels`/`torch_native`/`math` providers | ✅ GPU parity (both providers) + gloo fwd+bwd grad parity (p2p **and** allgather) |
102
+ | 3 | USP 2D composition (Ulysses × Ring) + auto-selector | ✅ **2×2 validated** (4 gloo ranks) + auto-selector |
103
+ | 4 | Mamba2 SSM CP (owned: `strategies/mamba.py`) + linear-attention state-passing | ✅ **mamba2 CP validated with the real mamba-ssm kernel (2 GPU)**; **gated-DeltaNet linear attention validated with the real flash-linear-attention kernel (2 GPU)**; cp_linear_scan + mamba2-vs-SSD (gloo); sliding-window via flash `window` |
104
+ | 5 | ALST memory | deferred to host framework (axolotl-native) |
105
+ | 6 | Profiling, trl/accelerate + multimodal adapters, **accelerate ParallelismConfig compat**, benchmark, docs, axolotl plugin (schema-merge tested) | ✅ |
106
+ | 7 | Custom collectives — fused Q/K/V all-to-all (MHA) ✅; **comm/compute overlap (prefetch) in p2p ring** ✅; symmetric-memory / Triton | partial (two items done) |
107
+ | v2 | packing / varlen | deferred |
108
+
109
+ ## Benchmark (2× GPU, Ulysses, Llama hidden=2048/heads=16/layers=6, fwd+bwd)
110
+
111
+ | seq | non-CP (1 GPU) peak | CP (2 GPU) per-GPU peak | CP step |
112
+ |----:|----:|----:|----:|
113
+ | 16k | 8.4 GB | 4.6 GB | 440 ms |
114
+ | 65k | 31 GB | 16 GB | 2.1 s |
115
+ | 131k | 62 GB (10.1 s) | 31 GB | 6.3 s |
116
+ | 262k | **OOM** | 62 GB | 21 s |
117
+
118
+ CP halves per-GPU memory at every length (1/world sequence sharding) and reaches
119
+ 2× the sequence (262k vs 131k) on the same hardware. `benchmarks/cp_vs_noncp.py`.
120
+
121
+ **CP is a memory/latency tool, not a throughput win.** It uses `world` GPUs, so
122
+ total GPU-time is higher than non-CP for a sequence that already fits on one GPU:
123
+ at 131k, non-CP = 10.1 GPU-s vs CP = 6.3 s × 2 = 12.6 GPU-s (~1.25×); at 16k the
124
+ overhead is ~2.4× (comm dominates). The overhead shrinks as sequence grows
125
+ (attention compute is superlinear, comm linear) but never breaks even. Use CP for
126
+ context that won't fit on one GPU, or to cut latency when you have spare GPUs; for
127
+ sequences that fit, DP is more GPU-efficient.
128
+
129
+ **p2p ring is the memory-optimal path** (only O(S/P) KV resident) with a proper
130
+ flash-style reverse-ring backward and DistFlashAttn-style comm/compute overlap
131
+ (prefetch the next KV block while computing the current). allgather is the
132
+ faster/higher-memory option (torchtitan-style). Both train (grad-parity validated).
133
+
134
+ **Remaining gap:** a live multi-GPU `axolotl train` run for correct *gradient*
135
+ semantics needs CP to be a non-DP mesh dim (via accelerate ParallelismConfig
136
+ `cp_size`, now supported by `ringmaster.parallelism.setup_from_parallelism_config`);
137
+ wiring axolotl's core to route through it (vs the legacy ring path) is the last
138
+ integration step.
139
+
140
+ Comm/memory are profilable: wrap any step in `rm.profile_comms()` / `rm.profile_memory()`
141
+ to get per-collective bytes+time and peak memory. The Ulysses leg fuses K/V into one
142
+ all-to-all (3 collectives/attn, not 4); the Ring leg offers `allgather` (fast, more
143
+ memory) vs `p2p` (O(S/P) KV resident) rotaters.
144
+
145
+ ## Layout
146
+
147
+ ```
148
+ ringmaster/
149
+ config.py RingmasterConfig (framework-neutral)
150
+ compat.py torch>=2.11 gate + experimental API isolation
151
+ runtime.py process-wide CP groups + active runtime
152
+ mesh.py resolve cp group(s), topology probe
153
+ comm.py SeqAllToAll4D (Ulysses all-to-all autograd; gloo fallback)
154
+ profiling.py profile_comms / profile_memory
155
+ ring/
156
+ loop.py ring loop: allgather (autograd) + p2p (memory-frugal)
157
+ kernels.py block kernels: hf_kernels flash / aten flash (pluggable)
158
+ merge.py online-softmax LSE merge
159
+ strategies/
160
+ ulysses.py AttentionInterface wrapper around HF kernels
161
+ ring.py register kernel-agnostic ring + impl resolution
162
+ usp.py 2D composition + auto_select
163
+ state_passing.py Mamba2/linear exact CP linear scan
164
+ shard.py dense contiguous sequence sharding
165
+ balancers.py head_tail/contiguous index gen (Ring)
166
+ loss.py CP-correct token-weighted loss reduction
167
+ multimodal.py shard fused sequence after the encoder
168
+ memory/ deferred to host framework (axolotl ALST)
169
+ adapters/ raw PyTorch / trl+accelerate / hatchery-core entry points
170
+ benchmarks/ profile_cp.py (comm + memory across seq lengths)
171
+ ```
@@ -0,0 +1,148 @@
1
+ # ringmaster
2
+
3
+ Composable long-context attention for distributed LLM training. Ulysses / Ring /
4
+ USP sequence parallelism that **wraps existing kernels** instead of shipping its
5
+ own — so it rides HuggingFace `kernels` Flash-Attention (FA2/FA3/FA4), torch SDPA,
6
+ and FlexAttention, with **no `flash_attn` pypi dependency**. Framework-neutral
7
+ core; thin adapters for axolotl, trl/accelerate, and raw PyTorch.
8
+
9
+ ## Why
10
+
11
+ `ring-flash-attn` (the previous CP path) depends on the `flash_attn` pypi package,
12
+ which is no longer installed now that attention comes from HF `kernels`. ringmaster
13
+ takes two routes that avoid that dependency entirely:
14
+
15
+ - **Ulysses** wraps the model's *own* attention kernel with all-to-all on the head
16
+ dim — works with any kernel (FA2/3/4/sdpa/flex), inherently load-balanced, the
17
+ cheapest comm. Capped by KV-head count.
18
+ - **Ring** rides torch-native context parallel (`torch.distributed.tensor.experimental`)
19
+ on the SDPA/FlexAttention backends — no head cap, scales linearly. LSE merging
20
+ is handled inside aten, so we never reimplement a ring kernel.
21
+ - **USP** composes the two on a 2D mesh (Ulysses intra-node, Ring inter-node).
22
+
23
+ An **auto-selector** picks the `ulysses_size × ring_size` split from KV-head count,
24
+ world size, and intra-node topology.
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pip install axolotl-ringmaster
30
+ ```
31
+
32
+ The distribution is `axolotl-ringmaster` (the unrelated `ringmaster` name was taken
33
+ on PyPI); the import name is `ringmaster`.
34
+
35
+ ## Quickstart
36
+
37
+ Requires **torch ≥ 2.11**. The framework adapters do this for you; the raw shape is:
38
+
39
+ ```python
40
+ import ringmaster as rm
41
+
42
+ cfg = rm.RingmasterConfig(size=8, backend=rm.Backend.AUTO)
43
+ runtime = rm.setup(cfg, num_kv_heads=8, device_mesh=mesh) # mesh has a "cp" dim
44
+ model.set_attn_implementation(runtime.attn_implementation)
45
+ rm.wire_recurrent_layers(model) # no-op for plain attention
46
+
47
+ from ringmaster.adapters.raw import context_parallel_region
48
+ for batch in loader:
49
+ with context_parallel_region(batch) as shard: # contiguous seq shard
50
+ loss = model(**shard).loss
51
+ loss.backward()
52
+ ```
53
+
54
+ Pair CP with **FSDP2** (a `dp_shard × cp` mesh), not plain DDP — FSDP2's gradient
55
+ reduce-scatter sums the CP-partial gradients; DDP would mis-reduce. See
56
+ [docs/concepts.md](docs/concepts.md#device-mesh-and-fsdp2-composition).
57
+
58
+ ## Documentation
59
+
60
+ - [docs/concepts.md](docs/concepts.md) — backends (Ulysses/Ring/USP), rotate
61
+ methods, load balancing, device-mesh / FSDP2 composition, and when to use which.
62
+ - [docs/integration.md](docs/integration.md) — raw PyTorch, trl/accelerate
63
+ (`CPSFTTrainer` + `ParallelismConfig` + `chunked_nll`), and axolotl (plugin + YAML).
64
+ - [docs/api.md](docs/api.md) — concise reference of the public API.
65
+ - [docs/models.md](docs/models.md) — plain attention, gated linear-attention
66
+ (Qwen3.5/Next), Mamba2 hybrids (Nemotron-H), and the sm_120 shim.
67
+ - [examples/cp_fsdp2/](examples/cp_fsdp2/) — worked TRL + FSDP2 script and axolotl
68
+ configs for all three model families, plus a CP-vs-non-CP benchmark table.
69
+
70
+ ## Status
71
+
72
+ Requires **torch ≥ 2.11**.
73
+
74
+ | Phase | Feature | State |
75
+ |-------|---------|-------|
76
+ | 0 | Package scaffold, config, mesh, runtime, registry, loss | ✅ |
77
+ | 1 | Ulysses backend (wraps HF kernels FA2/3/4/sdpa) | ✅ GPU-validated — sdpa + flash parity, fwd+bwd |
78
+ | 2 | Ring — kernel-agnostic loop; **p2p (memory-optimal, fwd+bwd) + allgather (fast)** rotaters; `hf_kernels`/`torch_native`/`math` providers | ✅ GPU parity (both providers) + gloo fwd+bwd grad parity (p2p **and** allgather) |
79
+ | 3 | USP 2D composition (Ulysses × Ring) + auto-selector | ✅ **2×2 validated** (4 gloo ranks) + auto-selector |
80
+ | 4 | Mamba2 SSM CP (owned: `strategies/mamba.py`) + linear-attention state-passing | ✅ **mamba2 CP validated with the real mamba-ssm kernel (2 GPU)**; **gated-DeltaNet linear attention validated with the real flash-linear-attention kernel (2 GPU)**; cp_linear_scan + mamba2-vs-SSD (gloo); sliding-window via flash `window` |
81
+ | 5 | ALST memory | deferred to host framework (axolotl-native) |
82
+ | 6 | Profiling, trl/accelerate + multimodal adapters, **accelerate ParallelismConfig compat**, benchmark, docs, axolotl plugin (schema-merge tested) | ✅ |
83
+ | 7 | Custom collectives — fused Q/K/V all-to-all (MHA) ✅; **comm/compute overlap (prefetch) in p2p ring** ✅; symmetric-memory / Triton | partial (two items done) |
84
+ | v2 | packing / varlen | deferred |
85
+
86
+ ## Benchmark (2× GPU, Ulysses, Llama hidden=2048/heads=16/layers=6, fwd+bwd)
87
+
88
+ | seq | non-CP (1 GPU) peak | CP (2 GPU) per-GPU peak | CP step |
89
+ |----:|----:|----:|----:|
90
+ | 16k | 8.4 GB | 4.6 GB | 440 ms |
91
+ | 65k | 31 GB | 16 GB | 2.1 s |
92
+ | 131k | 62 GB (10.1 s) | 31 GB | 6.3 s |
93
+ | 262k | **OOM** | 62 GB | 21 s |
94
+
95
+ CP halves per-GPU memory at every length (1/world sequence sharding) and reaches
96
+ 2× the sequence (262k vs 131k) on the same hardware. `benchmarks/cp_vs_noncp.py`.
97
+
98
+ **CP is a memory/latency tool, not a throughput win.** It uses `world` GPUs, so
99
+ total GPU-time is higher than non-CP for a sequence that already fits on one GPU:
100
+ at 131k, non-CP = 10.1 GPU-s vs CP = 6.3 s × 2 = 12.6 GPU-s (~1.25×); at 16k the
101
+ overhead is ~2.4× (comm dominates). The overhead shrinks as sequence grows
102
+ (attention compute is superlinear, comm linear) but never breaks even. Use CP for
103
+ context that won't fit on one GPU, or to cut latency when you have spare GPUs; for
104
+ sequences that fit, DP is more GPU-efficient.
105
+
106
+ **p2p ring is the memory-optimal path** (only O(S/P) KV resident) with a proper
107
+ flash-style reverse-ring backward and DistFlashAttn-style comm/compute overlap
108
+ (prefetch the next KV block while computing the current). allgather is the
109
+ faster/higher-memory option (torchtitan-style). Both train (grad-parity validated).
110
+
111
+ **Remaining gap:** a live multi-GPU `axolotl train` run for correct *gradient*
112
+ semantics needs CP to be a non-DP mesh dim (via accelerate ParallelismConfig
113
+ `cp_size`, now supported by `ringmaster.parallelism.setup_from_parallelism_config`);
114
+ wiring axolotl's core to route through it (vs the legacy ring path) is the last
115
+ integration step.
116
+
117
+ Comm/memory are profilable: wrap any step in `rm.profile_comms()` / `rm.profile_memory()`
118
+ to get per-collective bytes+time and peak memory. The Ulysses leg fuses K/V into one
119
+ all-to-all (3 collectives/attn, not 4); the Ring leg offers `allgather` (fast, more
120
+ memory) vs `p2p` (O(S/P) KV resident) rotaters.
121
+
122
+ ## Layout
123
+
124
+ ```
125
+ ringmaster/
126
+ config.py RingmasterConfig (framework-neutral)
127
+ compat.py torch>=2.11 gate + experimental API isolation
128
+ runtime.py process-wide CP groups + active runtime
129
+ mesh.py resolve cp group(s), topology probe
130
+ comm.py SeqAllToAll4D (Ulysses all-to-all autograd; gloo fallback)
131
+ profiling.py profile_comms / profile_memory
132
+ ring/
133
+ loop.py ring loop: allgather (autograd) + p2p (memory-frugal)
134
+ kernels.py block kernels: hf_kernels flash / aten flash (pluggable)
135
+ merge.py online-softmax LSE merge
136
+ strategies/
137
+ ulysses.py AttentionInterface wrapper around HF kernels
138
+ ring.py register kernel-agnostic ring + impl resolution
139
+ usp.py 2D composition + auto_select
140
+ state_passing.py Mamba2/linear exact CP linear scan
141
+ shard.py dense contiguous sequence sharding
142
+ balancers.py head_tail/contiguous index gen (Ring)
143
+ loss.py CP-correct token-weighted loss reduction
144
+ multimodal.py shard fused sequence after the encoder
145
+ memory/ deferred to host framework (axolotl ALST)
146
+ adapters/ raw PyTorch / trl+accelerate / hatchery-core entry points
147
+ benchmarks/ profile_cp.py (comm + memory across seq lengths)
148
+ ```