Add opt-in foreach path to GPA-AdamW step - #279
shaneraphel wants to merge 1 commit into
Conversation
Same arithmetic as the per-parameter loop, grouped with multi-tensor foreach ops on one device. Default stays on the loop so existing runs do not change; set foreach=True where it is faster (many small parameters on CPU). Sparse grads or mixed dtypes fall back. The flag stays off the param group so checkpoints keep their keys.
|
Hi @shaneraphel! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
GPAAdamW.stepcan now run the parameter update with multi-tensor foreach ops on a single device, instead of only the per-parameter Python loop.foreachdefaults to off so existing runs are unaffected. It is opt-in because the win is shape-dependent.Evidence
Apple M4, PyTorch 2.11.0, CPU, 10 threads, 8 steps, median of 3 runs. foreach result is bit-identical to the loop (
torch.equalon params, z-buffer, exp_avg, exp_avg_sq).The 768 case is why this is opt-in rather than a new default.
Test plan
python -m unittest gpa.tests.gpa_adamw_test gpa.tests.gpa_equivalence_test(20 tests, newGPAAdamWForeachTestchecks bit-identical params and state over 4 steps)ruff checkandruff formaton the two touched filesmake test-gpuneeds CUDA hardware I do not have here)