NVIDIA / TransformerEngine

A library for accelerating Transformer models on NVIDIA GPUs, including using 8-bit floating point (FP8) precision on Hopper and Ada GPUs, to provide better performance with lower memory utilization in both training and inference.
https://docs.nvidia.com/deeplearning/transformer-engine/user-guide/index.html
Apache License 2.0
1.6k stars 255 forks source link

Lower memory usage during AttnFuncWithCP.forward #951

Open i4never opened 1 week ago

i4never commented 1 week ago

Description

Release p2p_comm_buffers.

Fixes #952

Type of change

Changes

Please list the changes introduced in this PR:

Checklist:

timmoon10 commented 1 week ago

/te-ci pytorch

xrennvidia commented 1 week ago

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.