Repository navigation
Proposed lab: The Same-Bits Contract, Part 2 (data-parallel training) #2199
Replies: 7 comments 1 reply
|
Here is the Part A prototype: https://github.com/Shakhtar-Sankur/cs249r_book/tree/same-bits-part2
On 4,096 synthetic gradients:
Each collective repeats its own bits exactly when run again, and all three stay within about 1e-6 of the float64 sum: none is wrong, they round differently. With 2 ranks every schedule computes a + b, so they agree; the lab uses that as its control. The new tests, Part 1's tests, the lab checks on labs/proposed (87 passed) and a run of the page: https://www.kaggle.com/code/sankurkundu/notebookbf588d3292 If this is the direction you'd like, Part B (4 against 8 ranks with the same global batch) comes next. |
|
@profvjreddi A gentle follow-up on Part 2 of the Same-Bits lab: the Part A prototype (ring, tree and star all-reduce giving 3 distinct results from the same gradients at 4+ ranks, with 8 tests) is ready on the branch above. Happy to turn it into a PR, adjust the scope, or wait if the timing isn't right. |
|
Hey @Shakhtar-Sankur - just a bit behind with some updates I am making to the books. About these labs, I am thinking of scrapping the labs. I feel they have never quite landed, and I am feeling stuck cause I don't seem to come up with a good way to structure these labs, and I haven't got any feedback from anyone on why they'd want to use them, as myself haven't yet found a compelling reason to make them good even for my own classes. So they are dragging. What are your thoughts on whether we should keep them or throw them out? |
|
Thanks for asking, and no rush at all. My honest view: keep a few, but only the ones that pass a hard test, and drop the rest. I'd only keep a lab if all three of these hold:
If a lab can't pass all three, I agree it's dragging and should go. Fewer, sharper labs are better than a full set nobody uses. A lighter format might also fit better than full labs: a short "check this claim yourself" box at the end of a chapter, with one cell to run and one question. Same idea, much less to maintain. If it helps, I'm happy to (a) go through the current labs against those three criteria and send you a keep/merge/drop list, or (b) turn Same-Bits into that short format as a trial, so you can see whether it works for your own class before deciding on the rest. And if you decide to scrap them all, that's completely fine too, and I'm glad to help with the book in other ways. |
|
Thanks for your honest feedback. I'd honestly say we should throw them out completely and restart. I never really finished them, and it was always difficult because either felt it was not ever really doing its job. The thing that got me started was that I wanted students to explore the trade-offs, what-ifs, which are hard to do just by reading a piece of text. But I never managed to fully land it. |
|
That makes sense, and I think restarting around that original goal is the right call: trade-offs and what-ifs are exactly what text can't teach. One shape that might land: instead of labs, one small "what-if explorer" per chapter, backed by mlsysim so the numbers are real.
If it would help, I'd be glad to build one as a prototype for a chapter you pick (batch size vs latency/throughput on mlsysim would be a natural first one) so you can try it in your own class before committing to the format. No pressure either way. |
|
Here is a first prototype: https://github.com/Shakhtar-Sankur/cs249r_book/tree/whatif-batching/labs/prototypes It is one Marimo page for the serving chapter, "What if we batch more requests?", built on mlsysim's ServingModel. Students make one quick guess, then change the model, GPU, precision, context length, batch size and a per-token latency limit, and two charts show tokens/s and each user's wait per token against batch size, with the memory wall and the latency limit marked. A "What if...?" table recomputes a few changes against their current settings (a faster GPU, INT4, 8x longer conversations, a bigger or smaller model), and it ends with "which batch would you pick, and what would make you change it?" For example, Llama 3.1 8B on an H100 at 4K context: batch 32 gives 16x the tokens per second of batch 1 while each user waits 1.9x as long, and memory runs out after batch 128. The page shows why: every request's KV cache is read every step, so once the KV caches outweigh the weights, extra requests stop being nearly free. To try it: marimo edit labs/prototypes/whatif_batching.py on that branch. It is deliberately lighter than the current labs (no locks, tabs or ledger) and sits in labs/prototypes so the Co-Lab checks do not apply. Happy to change it after you try it in class, or open a PR into dev if the format works for you. |
Uh oh!
There was an error while loading. Please reload this page.
Thank you again for merging The Same-Bits Contract (#2175) and for rerunning it. Part 1 followed reduction order into inference. I'd like to propose a companion that follows it into training, where the book states the contract but no lab measures it yet.
Vol II, Chapter 5 (Collective Communication) puts it in one paragraph: "A correct AllReduce therefore guarantees the specified reduction over all contributions, not bitwise identity across algorithms, rank counts, or hardware. Reproducibility-sensitive workloads must fix the algorithm and process-group configuration or use a reproducible accumulation scheme."
Driving question: you run the same data-parallel job twice, with the same seed and the same data, on 4 GPUs and then on 8, and get different weights. Nothing random was sampled. Where did the difference come from, and what does it cost to remove it?
It would be built the same way as Part 1: every number computed in mlsysim.labs.experiments with real IEEE 754 arithmetic and explicit reduction orders, so the lab runs in the browser with no GPU, with a test for each claim. Part D's fixed order is the kind my own data-parallel trainer relies on to train bit-identically to PyTorch DDP and FSDP on NCCL, and Part E's integer sums come from samebit, the project behind Part 1.
I'd put it in labs/proposed/ next to Part 1, so nothing in the catalog or the chapter slots moves. If it fits better beside Chapter 6 (Distributed Training) than Chapter 5, I'll shape it for that.
I'll start with Part A as a prototype and share it here before building the rest. @profvjreddi, does this sound useful?
All reactions