Commit bebfbfb
committed
Replace cap-pass remediation with topo-span-bounded bucketing
Summary
Replaces the `_cap_compute_batch_size` post-hoc remediator with a topo-span close-bucket condition inside the patched FSDP bucketing. Same load-bearing knob (`bucket_cap_mb`) gains a companion (`max_topo_span`) that bounds the dependency-footprint problem the cap was trying to undo. The bucketing-time prevention has shipped at `max_topo_span=1500` on `fmassa/double_recomp` and matches the prior cap-based path on min latency while substantially improving variance.
Motivation
The prior cherry (`9871a48`) combined two opposing patches: non-adjacent bucketing (which widens bucket dependency footprints to improve NCCL throughput) and `_cap_compute_batch_size` (which reorders compute post-hoc to undo the resulting MM*N batching). The cap relied on pre-bucket reduce_scatter names surviving bucketing — a property that doesn't always hold when bucketing renames RS ops — so the cap silently degrades to chain-deps-only and doesn't bound `max_consec_compute_between_RS`. Bounding bucket topo-span at the source addresses the same MM*N harm without a downstream remediator, surfaces one tunable knob users can reason about, and degenerates to the prior cherry's behavior when `max_topo_span=None`.
What changed
`autoparallel/graph_passes/auto_bucketing.py`, −56 net LOC:
- **Kept** `_patched_identify_fsdp_groups` (primary-group-only filter) and `max_compute_pre_fetch=50`.
- **Replaced** the non-adjacent `_patched_greedy_bucket` with a version that adds `close_for_span` as a third close-bucket condition alongside `close_for_bytes`. Snapshots ranks at function entry, closes a bucket when `current_rank - bucket_start_rank > max_topo_span`.
- **Added** `aten_autobucketing_config.max_topo_span: int | None = 1500`. Set to `None` to restore the prior bytes-only (cherry) behavior with no codepath difference.
- **Added** INFO-level metrics inside `_patched_greedy_bucket`: per-invocation `(num_buckets, max_observed_span, n_close_bytes, n_close_span, max_topo_span)`. The cap's silent-failure mode is no longer possible.
- **Added** `_max_consec_compute_between_rs(graph)` helper, logged at INFO after `aten_autobucketing_reordering_pass` as a regression metric matching what the old cap enforced.
- **Removed** `_cap_compute_batch_size` (~120 LOC) and the pre/post-bucket name-snapshotting that fed it.
Validation
`tests/test_auto_bucketing_patches.py` (8 tests, ~3 s, no GPU):
- `identify_fsdp_groups`: primary group wins on imbalanced counts; empty graph returns empty; ties pick exactly one.
- `greedy_bucket`: merges within caps; splits on bytes; splits on span when bytes are under cap; `max_topo_span=None` disables span; descendant collectives never co-bucket.
Mutation-verified — reverting either patch causes the corresponding test to fail with an informative message.
Real benchmark results (LLaMA-3 8B, 32 layers, 128 H100s, seqlen=8192, global batch=32)
`max_topo_span=1500`, job 6513650, vs the most-stable prior cap-based run (6477238):
**Unconstrained**
| Run | min ms | avg ms | max ms | alloc GiB | rsrvd GiB | MFU |
| -------------------------- | ------- | --------- | --------- | --------- | --------- | --------- |
| New (`max_topo_span=1500`) | 379.3 | **389.6** | **436.6** | 7.69 | **8.06** | 492.5 % |
| Prior `_cap` (cleanest) | 378.3 | 384.2 | 412.0 | 7.55 | 8.20 | 499.4 % |
| Prior `_cap` (typical) | 370–377 | 424–569 | 1.8–6.0 s | 7.55 | 8.20 | 337–452 % |
| TorchTitan reference | 366.2 | 414.1 | 1742.8 | 8.62 | 9.43 | 463.4 % |
- **Min latency**: 379.3 ms, ~+1–9 ms over best prior runs; within the prior-run min spread.
- **Avg latency**: 389.6 ms — second-best across all runs (only the lucky 6477238 beats it at 384.2 ms); typical prior cap-based avg was 424–569 ms.
- **Max latency**: 436.6 ms — **best of all benchmarked runs**; every other prior run except 6477238 had >1.8 s tails.
- **Variance**: avg − min collapses from 5–200 ms range to 10 ms. The cap's silent-failure failure mode (which produced occasional multi-second tails) appears to be the source of prior variance; bucketing-time prevention is much more deterministic.
- **Memory**: +0.14 GiB alloc vs cap-based prior; rsrvd memory is the best of all runs.
**Constrained**
| Run | min ms | avg ms | max ms | alloc GiB | rsrvd GiB |
| -------------------------- | ----------- | ------- | ----------- | --------- | --------- |
| New (`max_topo_span=1500`) | 443.6 | 484.3 | 662.9 | 7.11 | **7.51** |
| Prior `_cap` (range) | 439.8–445.9 | 447–628 | 0.98–5.58 s | 7.12 | 7.49–7.59 |
- Min within prior noise band; avg/max middle of prior variance; **rsrvd memory is the best of all runs**.
Telemetry from the shipped run
The `max_topo_span=1500` knob is **dormant in practice** at this configuration:
- Fwd: 27 buckets, max span 619, closures `(bytes=26, span=0)`, `max_consec_compute_between_rs=8`
- Bwd group A: 43 buckets, max span 1325, closures `(bytes=40, span=1)`
- Bwd group B: 64 buckets, max span 561, closures `(bytes=62, span=0)`
- Bwd `max_consec_compute_between_rs=12` (vs 8 under the old explicit cap — 50% looser)
The span gate fires at most once across all bucketing invocations; actual behavior is byte-cap-only plus primary-group filter. The 4-extra MMs concentrated before each RS may explain the ~9 ms unconstrained min-latency gap vs the best prior run — testing `max_topo_span=1000` is in progress to validate whether tightening the gate closes that gap without reintroducing variance.
What this gives up vs the cap-based approach
- Min latency: within ±9 ms of best prior min, plausibly recoverable by tuning `max_topo_span` downward.
- Memory: rsrvd best-of-all-runs in both modes; alloc within 2% of prior best.
What this gains
- Avg/max latency stability: variance collapses dramatically vs the prior cap-based path (typical prior tails of 1.8–6.0 s disappear in unconstrained; 0.98–5.58 s tails in constrained reduce to 0.66 s).
- One declarative knob (`max_topo_span`) replaces two coupled patches plus a downstream remediator with a known name-matching brittleness.
- Loud metrics: `n_close_bytes` / `n_close_span` / `max_consec_compute_between_rs` are logged at INFO; the prior cap's silent-failure mode is no longer possible.
- ~56 net LOC removed.
Authored with Claude.1 parent 9871a48 commit bebfbfb
2 files changed
Lines changed: 371 additions & 148 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
29 | 36 | | |
30 | 37 | | |
31 | 38 | | |
| |||
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
74 | 86 | | |
75 | 87 | | |
76 | 88 | | |
| |||
83 | 95 | | |
84 | 96 | | |
85 | 97 | | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
91 | 109 | | |
| 110 | + | |
92 | 111 | | |
93 | 112 | | |
94 | 113 | | |
| |||
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
104 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
105 | 132 | | |
106 | 133 | | |
107 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
108 | 142 | | |
109 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
110 | 152 | | |
111 | 153 | | |
112 | 154 | | |
113 | 155 | | |
| 156 | + | |
114 | 157 | | |
115 | 158 | | |
116 | 159 | | |
117 | 160 | | |
118 | 161 | | |
119 | 162 | | |
| 163 | + | |
| 164 | + | |
120 | 165 | | |
121 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
122 | 182 | | |
123 | 183 | | |
124 | 184 | | |
| |||
128 | 188 | | |
129 | 189 | | |
130 | 190 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
158 | 197 | | |
159 | | - | |
160 | 198 | | |
161 | 199 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
193 | 203 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
255 | 211 | | |
256 | 212 | | |
257 | 213 | | |
| |||
341 | 297 | | |
342 | 298 | | |
343 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
344 | 304 | | |
345 | 305 | | |
346 | 306 | | |
347 | 307 | | |
348 | 308 | | |
349 | 309 | | |
350 | 310 | | |
| 311 | + | |
351 | 312 | | |
352 | 313 | | |
353 | 314 | | |
| |||
358 | 319 | | |
359 | 320 | | |
360 | 321 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | 322 | | |
383 | 323 | | |
384 | 324 | | |
| |||
389 | 329 | | |
390 | 330 | | |
391 | 331 | | |
392 | | - | |
393 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
394 | 336 | | |
| 337 | + | |
395 | 338 | | |
396 | 339 | | |
397 | 340 | | |
| |||
0 commit comments