Lower memory usage during AttnFuncWithCP.forward
Description
Release p2p_comm_buffers.
Fixes #952
Type of change
- [ ] Documentation change (change only to the documentation, either a fix or a new content)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Infra/Build change
- [ ] Code refractor
Changes
Please list the changes introduced in this PR:
- Change A
- Change B
Checklist:
- [x] I have read and followed the contributing guidelines
- [x] The functionality is complete
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
/te-ci pytorch
Hi @i4never
Thanks for submitting the PR! Have you done any E2E training test with your PR? There is some case where communication can take longer time than compute, your code seems can set p2p_comm_buffers[i]=None before the async P2P communication is done, right? Wouldn't this result in any issue?
Actually, how critical is it for you to fix the issue? The communication buffers are temp buffers per transformer layer, while the attention fwd of a transformer layer is done, those buffers will be released dynamically. Assuming mbs=1, seq=64K, head_dim=128, GQA group of 8 (i.e., num of KV heads is 8), and BF16 precision. The total P2P comm buffer size is only 65536128228=256MB. For long sequence like 64K, you may apply TP. Assuming TP8, then total P2P comm buffer size will be 8 times smaller, i.e., 256/8=32MB. Do you have a special case which the buffer size is too big?
Thanks.