-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[https://nvbugs/6084764][fix] Cache NVLinkOneSided init failure to prevent OOM from repeated MnnvlMemory alloc #13235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,7 @@ class NVLinkOneSided(Communication): | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Single shared workspace/memory across the process | ||||||||||||||||||||||||||||||||||
| _WORKSPACE: dict | None = None | ||||||||||||||||||||||||||||||||||
| _WORKSPACE_INIT_FAILED: bool = False | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # MetaInfo indices - initialized from C++ constants | ||||||||||||||||||||||||||||||||||
| FLAG_VAL_OFFSET_INDEX = None | ||||||||||||||||||||||||||||||||||
|
|
@@ -168,6 +169,14 @@ def __init__( | |||||||||||||||||||||||||||||||||
| transfer (halves NVLink bandwidth usage, output precision is preserved). | ||||||||||||||||||||||||||||||||||
| Corresponds to model_config.use_low_precision_moe_combine. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| # Skip if workspace initialization previously failed to avoid repeated | ||||||||||||||||||||||||||||||||||
| # MnnvlMemory allocations that leak CUDA physical memory (held alive by | ||||||||||||||||||||||||||||||||||
| # exception traceback references), which can exhaust GPU memory. | ||||||||||||||||||||||||||||||||||
| if NVLinkOneSided._WORKSPACE_INIT_FAILED: | ||||||||||||||||||||||||||||||||||
| raise RuntimeError( | ||||||||||||||||||||||||||||||||||
| "NVLinkOneSided workspace initialization previously failed; skipping retry." | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| super().__init__(mapping) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if self.mapping.world_size != self.ep_size: | ||||||||||||||||||||||||||||||||||
|
|
@@ -229,15 +238,26 @@ def __init__( | |||||||||||||||||||||||||||||||||
| f"NVLinkOneSided: Allocating workspace with size {self.workspace_size_per_rank} bytes." | ||||||||||||||||||||||||||||||||||
| f"ep_rank: {self.ep_rank}, ep_size: {self.ep_size}, top_k: {self.top_k}, max_num_tokens_per_rank: {self.max_num_tokens_per_rank}" | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| mnnvl_mem = MnnvlMemory(mapping, self.workspace_size_per_rank) | ||||||||||||||||||||||||||||||||||
| workspace = mnnvl_mem.as_torch_strided_tensor(torch.uint8) | ||||||||||||||||||||||||||||||||||
| metainfo = torch.ops.trtllm.moe_a2a_initialize( | ||||||||||||||||||||||||||||||||||
| workspace, | ||||||||||||||||||||||||||||||||||
| self.ep_rank, | ||||||||||||||||||||||||||||||||||
| self.ep_size, | ||||||||||||||||||||||||||||||||||
| self.max_num_tokens_per_rank, | ||||||||||||||||||||||||||||||||||
| self.eplb_stats_num_experts, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| mnnvl_mem = None | ||||||||||||||||||||||||||||||||||
| workspace = None | ||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||
| mnnvl_mem = MnnvlMemory(mapping, self.workspace_size_per_rank) | ||||||||||||||||||||||||||||||||||
| workspace = mnnvl_mem.as_torch_strided_tensor(torch.uint8) | ||||||||||||||||||||||||||||||||||
| metainfo = torch.ops.trtllm.moe_a2a_initialize( | ||||||||||||||||||||||||||||||||||
| workspace, | ||||||||||||||||||||||||||||||||||
| self.ep_rank, | ||||||||||||||||||||||||||||||||||
| self.ep_size, | ||||||||||||||||||||||||||||||||||
| self.max_num_tokens_per_rank, | ||||||||||||||||||||||||||||||||||
| self.eplb_stats_num_experts, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||
| # Release CUDA physical memory immediately to prevent leak. | ||||||||||||||||||||||||||||||||||
| # Without explicit cleanup, MnnvlMemory objects stay alive | ||||||||||||||||||||||||||||||||||
| # (held by exception traceback references) until GC runs. | ||||||||||||||||||||||||||||||||||
| workspace = None | ||||||||||||||||||||||||||||||||||
| mnnvl_mem = None | ||||||||||||||||||||||||||||||||||
| NVLinkOneSided._WORKSPACE_INIT_FAILED = True | ||||||||||||||||||||||||||||||||||
| raise | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+253
to
+260
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n tensorrt_llm/_torch/modules/fused_moe/communication/nvlink_one_sided.py | sed -n '240,275p'Repository: NVIDIA/TensorRT-LLM Length of output: 2009 🏁 Script executed: find . -name "MOE_DEVELOPER_GUIDE.md" -type fRepository: NVIDIA/TensorRT-LLM Length of output: 125 🏁 Script executed: cat tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.mdRepository: NVIDIA/TensorRT-LLM Length of output: 8060 🏁 Script executed: rg "class MnnvlMemory" -A 30 tensorrt_llm/Repository: NVIDIA/TensorRT-LLM Length of output: 2183 🏁 Script executed: rg "class MnnvlMemory" -A 100 tensorrt_llm/_mnnvl_utils.py | head -150Repository: NVIDIA/TensorRT-LLM Length of output: 4017 🏁 Script executed: rg "def open_mnnvl_memory" -A 50 tensorrt_llm/Repository: NVIDIA/TensorRT-LLM Length of output: 3845 🏁 Script executed: rg "def open_mnnvl_memory" -A 100 tensorrt_llm/_mnnvl_utils.py | head -150Repository: NVIDIA/TensorRT-LLM Length of output: 4627 🏁 Script executed: rg "_WORKSPACE_INIT_FAILED" -B 3 -A 3 tensorrt_llm/_torch/modules/fused_moe/communication/Repository: NVIDIA/TensorRT-LLM Length of output: 2562 🏁 Script executed: rg "pack_strided_memory" -B 5 -A 20 tensorrt_llm/Repository: NVIDIA/TensorRT-LLM Length of output: 5061 🏁 Script executed: cat -n tensorrt_llm/_dlpack_utils.py | sed -n '1,100p'Repository: NVIDIA/TensorRT-LLM Length of output: 3978 🏁 Script executed: cat -n tensorrt_llm/_dlpack_utils.py | sed -n '58,120p'Repository: NVIDIA/TensorRT-LLM Length of output: 2927 🏁 Script executed: rg "def pack_strided_memory" -A 30 tensorrt_llm/_dlpack_utils.pyRepository: NVIDIA/TensorRT-LLM Length of output: 1143 🏁 Script executed: rg "moe_a2a_initialize" -B 3 -A 3 tensorrt_llm/Repository: NVIDIA/TensorRT-LLM Length of output: 2184 🏁 Script executed: rg "except.*:" -B 3 -A 10 tensorrt_llm/_torch/distributed/moe_alltoall.py | head -80Repository: NVIDIA/TensorRT-LLM Length of output: 45 🏁 Script executed: cat -n tensorrt_llm/_torch/distributed/moe_alltoall.py | sed -n '1,150p'Repository: NVIDIA/TensorRT-LLM Length of output: 7549 🏁 Script executed: cat -n tensorrt_llm/_torch/distributed/moe_alltoall.py | sed -n '150,230p'Repository: NVIDIA/TensorRT-LLM Length of output: 4528 Narrow exception handling to only catch expected initialization failures.
Proposed change- except Exception:
+ except RuntimeError:
# Release CUDA physical memory immediately to prevent leak.
# Without explicit cleanup, MnnvlMemory objects stay alive
# (held by exception traceback references) until GC runs.
workspace = None
mnnvl_mem = None
NVLinkOneSided._WORKSPACE_INIT_FAILED = True
raise📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| NVLinkOneSided._WORKSPACE = { | ||||||||||||||||||||||||||||||||||
| "workspace_size_per_rank": self.workspace_size_per_rank, | ||||||||||||||||||||||||||||||||||
| "max_num_tokens_per_rank": self.max_num_tokens_per_rank, | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution is duplicate of #13172, we may close this PR instead. We can unwaive 6084764 in #13172.