Skip to content

Commit e1d5402

Browse files
authored
Fix all-reduce memory usage (vllm-project#2151)
1 parent 3d1cfbf commit e1d5402

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

vllm/worker/worker.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ def __init__(
4848
self.gpu_cache = None
4949

5050
def init_model(self, cupy_port: Optional[int] = None):
51+
# torch.distributed.all_reduce does not free the input tensor until
52+
# the synchronization point. This causes the memory usage to grow
53+
# as the number of all_reduce calls increases. This env var disables
54+
# this behavior.
55+
# Related issue:
56+
# https://discuss.pytorch.org/t/cuda-allocation-lifetime-for-inputs-to-distributed-all-reduce/191573
57+
os.environ["TORCH_NCCL_AVOID_RECORD_STREAMS"] = "1"
58+
5159
# This env var set by Ray causes exceptions with graph building.
5260
os.environ.pop("NCCL_ASYNC_ERROR_HANDLING", None)
5361
# Env vars will be set by Ray.

0 commit comments

Comments
 (0)