From f03ea34a3d35f540039bc7167c5759f62f0d8167 Mon Sep 17 00:00:00 2001 From: Yuhao Yang <47235274+yhyang201@users.noreply.github.com> Date: Sat, 29 Nov 2025 23:05:54 +0800 Subject: [PATCH] add runtime check for PyTorch 2.9.1 + CuDNN < 9.15 to prevent Conv3d performance issues (#14119) --- .github/workflows/pr-test.yml | 2 +- python/sglang/srt/server_args.py | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 148f30937..a8907ab97 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -453,8 +453,8 @@ jobs: - name: Install dependencies run: | - CUSTOM_BUILD_SGL_KERNEL=${{needs.check-changes.outputs.sgl_kernel}} bash scripts/ci/ci_install_dependency.sh pip install "bitsandbytes>=0.44.0" + CUSTOM_BUILD_SGL_KERNEL=${{needs.check-changes.outputs.sgl_kernel}} bash scripts/ci/ci_install_dependency.sh - name: Run test timeout-minutes: 30 run: | diff --git a/python/sglang/srt/server_args.py b/python/sglang/srt/server_args.py index abe466632..7a718795a 100644 --- a/python/sglang/srt/server_args.py +++ b/python/sglang/srt/server_args.py @@ -3979,6 +3979,11 @@ class ServerArgs: # Check LoRA self.check_lora_server_args() + # torch 2.9.1 has compatibility issues with cuDNN 9.14 and below, + # causing extremely slow nn.Conv3d performance. + # TODO(yhyang201): Remove this check when sglang no longer uses torch 2.9.1. + self.check_torch_2_9_1_cudnn_compatibility() + # Check speculative decoding if self.speculative_algorithm is not None: assert ( @@ -4054,6 +4059,46 @@ class ServerArgs: if self.model_impl == "mindspore": assert is_npu(), "MindSpore model impl is only supported on Ascend npu." + def check_torch_2_9_1_cudnn_compatibility(self): + if self.get_model_config().is_multimodal: + import torch + + torch_version = torch.__version__.split("+", 1)[0] + if torch_version == "2.9.1": + cudnn_version = None + try: + cudnn_version = torch.backends.cudnn.version() + except Exception: + cudnn_version = None + if cudnn_version is not None: + version_float = float(str(cudnn_version)[:3]) / 100 + if version_float < 9.15: + RED = "\033[91m" + BOLD = "\033[1m" + RESET = "\033[0m" + msg = ( + f"{RED}{BOLD}" + "CRITICAL WARNING: PyTorch 2.9.1 & CuDNN Compatibility Issue Detected\n" + "--------------------------------------------------------------------------------\n" + f"Current Environment: PyTorch {torch.__version__} | CuDNN {version_float:.2f}\n\n" + "Issue: There is a KNOWN BUG in PyTorch 2.9.1's `nn.Conv3d` implementation\n" + " when used with CuDNN versions older than 9.15. This can cause\n" + " SEVERE PERFORMANCE DEGRADATION and EXCESSIVE MEMORY USAGE.\n\n" + "Reference: https://github.com/pytorch/pytorch/issues/168167\n\n" + "Solution: You MUST upgrade CuDNN to version 9.15+ to ensure correctness.\n\n" + "Run the following command immediately to fix:\n" + " pip install nvidia-cudnn-cu12==9.16.0.29\n" + "--------------------------------------------------------------------------------\n" + f"{RESET}" + ) + raise RuntimeError(msg) + else: + RED = "\033[91m" + RESET = "\033[0m" + logger.warning( + f"{RED}WARNING: Could not determine CuDNN version for torch==2.9.1. Please ensure CuDNN >= 9.15 to avoid nn.Conv3d bugs.{RESET}" + ) + def check_lora_server_args(self): assert self.max_loras_per_batch > 0, "max_loras_per_batch must be positive"