diff --git a/docs/examples/te_gemma/tutorial_generation_gemma_with_te.ipynb b/docs/examples/te_gemma/tutorial_generation_gemma_with_te.ipynb index e9cf608a86c..e79fab133f0 100755 --- a/docs/examples/te_gemma/tutorial_generation_gemma_with_te.ipynb +++ b/docs/examples/te_gemma/tutorial_generation_gemma_with_te.ipynb @@ -172,7 +172,7 @@ "\n", "import torch\n", "cudnn_version = torch.backends.cudnn.version()\n", - "assert cudnn_version >= 91200, \"cuDNN version >= 9.12.0 is needed to run this tutorial.\"" + "assert cudnn_version >= 91801, \"cuDNN version >= 9.18.1 is needed to run this tutorial.\"" ] }, { diff --git a/docs/installation.rst b/docs/installation.rst index 09cb4baa807..0b9d5573300 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -14,7 +14,7 @@ Prerequisites 1. Linux x86_64 2. `CUDA 12.1+ (12.8+ for Blackwell support) `__ 3. |driver link|_ supporting CUDA 12.1 or later. -4. `cuDNN 9.12 `__ or later. +4. `cuDNN 9.18.1 `__ or later. 5. `cuDNN Frontend 1.31.0 `__ or later. PyTorch and JAX cuDNN attention require ``nvidia-cudnn-frontend`` version diff --git a/qa/L0_pytorch_unittest/test.sh b/qa/L0_pytorch_unittest/test.sh index 17bddf39bb8..977937c3e04 100644 --- a/qa/L0_pytorch_unittest/test.sh +++ b/qa/L0_pytorch_unittest/test.sh @@ -33,6 +33,7 @@ export NVTE_REPORT_IF_CUTEDSL_BACKEND_NOT_CHOSEN=ERROR pip3 install pytest==8.4.2 || error_exit "Failed to install pytest" python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_optional_flash_attn_import.xml $TE_PATH/tests/pytorch/test_optional_flash_attn_import.py || test_fail "test_optional_flash_attn_import.py" +python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_cudnn_min_version.xml $TE_PATH/tests/pytorch/test_cudnn_min_version.py || test_fail "test_cudnn_min_version.py" python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_sanity.xml $TE_PATH/tests/pytorch/test_sanity.py || test_fail "test_sanity.py" python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_recipe.xml $TE_PATH/tests/pytorch/test_recipe.py || test_fail "test_recipe.py" python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_custom_recipe.xml $TE_PATH/tests/pytorch/test_custom_recipe.py || test_fail "test_custom_recipe.py" diff --git a/tests/jax/test_fused_attn.py b/tests/jax/test_fused_attn.py index c9fce8a88db..7bc695bd063 100644 --- a/tests/jax/test_fused_attn.py +++ b/tests/jax/test_fused_attn.py @@ -993,14 +993,9 @@ def _check_configs(self): "For sm100+, non-deterministic bprop does not support bias with dropout" ) if not FusedAttnHelper.is_non_deterministic_allowed() and ( - self.dropout_prob != 0.0 - or self.attn_bias_type != AttnBiasType.NO_BIAS - or cudnn_version < 91801 + self.dropout_prob != 0.0 or self.attn_bias_type != AttnBiasType.NO_BIAS ): - pytest.skip( - "For sm100+, deterministic bprop (cuDNN 9.18.1+) does not support bias or" - " dropout" - ) + pytest.skip("For sm100+, deterministic bprop does not support bias or dropout") # Test the MLA case where head dims for qk differ from head dims for v, only if the tensors # are provided in BSHD_BSHD_BSHD or THD_THD_THD formats if self.head_dim_qk != self.head_dim_v and not self.qkv_layout.is_separate(): diff --git a/tests/pytorch/attention/benchmark_cp.py b/tests/pytorch/attention/benchmark_cp.py index 61238ec8d50..2793b5104c9 100644 --- a/tests/pytorch/attention/benchmark_cp.py +++ b/tests/pytorch/attention/benchmark_cp.py @@ -21,10 +21,7 @@ import subprocess import pytest import torch -from transformer_engine.pytorch import ( - get_device_compute_capability, - get_cudnn_version, -) +from transformer_engine.pytorch import get_device_compute_capability _current_file = pathlib.Path(__file__).resolve() sys.path = [str(_current_file.parent.parent)] + sys.path @@ -109,7 +106,6 @@ def get_bash_arguments(num_gpus_per_node, **kwargs): } -@pytest.mark.skipif(get_cudnn_version() < (8, 9, 7), reason="cuDNN 8.9.7+ is required.") @pytest.mark.skipif(get_device_compute_capability() < (9, 0), reason="THD requires sm90+.") @pytest.mark.parametrize("model", model_configs_fused_attn.keys()) @pytest.mark.parametrize("qkv_format", ["thd"]) diff --git a/tests/pytorch/attention/test_attention.py b/tests/pytorch/attention/test_attention.py index 1148691140c..a8873b01360 100644 --- a/tests/pytorch/attention/test_attention.py +++ b/tests/pytorch/attention/test_attention.py @@ -796,12 +796,6 @@ def fail(_self): "changes,version,capability,reason", ( ({"qkv_dtype": DType.kFloat32}, 92700, (10, 0), "Unsupported QKV dtype"), - ( - {"cuda_graph": True, "max_seqlen_kv": 127}, - 91500, - (10, 0), - "Known cuDNN <= 9.15 issue with CUDA graph", - ), ( {"qkv_layout": QKVLayout["thd_thd_thd"], "num_tokens_q": 256, "num_tokens_kv": 256}, 92700, @@ -2036,7 +2030,6 @@ def test_dpa_softmax(dtype, model_configs, model): test_dot_product_attention(dtype, model_configs, model, True, "bshd_bshd_bshd", False, False) -@pytest.mark.skipif(get_cudnn_version() < (9, 18, 0), reason="cuDNN 9.18.0+ is required.") @pytest.mark.parametrize("dtype", [torch.bfloat16]) @pytest.mark.parametrize("model_configs", [model_configs_softmax]) @pytest.mark.parametrize("model", model_configs_softmax.keys()) diff --git a/tests/pytorch/attention/test_attention_backend_selection.py b/tests/pytorch/attention/test_attention_backend_selection.py index 66e1ff7c1cf..11cf3df3075 100644 --- a/tests/pytorch/attention/test_attention_backend_selection.py +++ b/tests/pytorch/attention/test_attention_backend_selection.py @@ -185,14 +185,13 @@ def test_fused_eval_backward_after_forward_only(monkeypatch, dtype): @pytest.mark.parametrize("capability", ((12, 0), (12, 1), (12, 9))) -@pytest.mark.parametrize("case", ("fp8", "kv_cache", "mla", "thd_version", "thd_packed")) +@pytest.mark.parametrize("case", ("fp8", "kv_cache", "mla", "thd_packed")) def test_sm12x_fused_backend_restrictions(monkeypatch, capability, case): """SM121 and other SM12x variants must retain the SM120 backend restrictions.""" monkeypatch.setenv("NVTE_FUSED_ATTN", "1") monkeypatch.setenv("NVTE_FLASH_ATTN", "0") monkeypatch.setattr(dpa_utils, "get_device_compute_capability", lambda _device: capability) - version = (9, 18, 0) if case == "thd_version" else (9, 27, 0) - monkeypatch.setattr(dpa_utils, "get_cudnn_version", lambda: version) + monkeypatch.setattr(dpa_utils, "get_cudnn_version", lambda: (9, 27, 0)) probe = Mock(return_value=(dpa_utils.FusedAttnBackend.F16.value, "")) monkeypatch.setattr(dpa_utils, "_get_fused_attn_backend", probe) options = dict( @@ -213,7 +212,7 @@ def test_sm12x_fused_backend_restrictions(monkeypatch, capability, case): options.update(head_dim_qk=192, head_dim_v=128) else: options.update( - qkv_layout="t3hd" if case == "thd_packed" else "thd_thd_thd", + qkv_layout="t3hd", attn_mask_type="padding", num_tokens_q=128, num_tokens_kv=128, diff --git a/tests/pytorch/attention/test_attention_with_cp.py b/tests/pytorch/attention/test_attention_with_cp.py index 56055ca1694..5bc82fa531f 100644 --- a/tests/pytorch/attention/test_attention_with_cp.py +++ b/tests/pytorch/attention/test_attention_with_cp.py @@ -668,13 +668,6 @@ def test_cp_with_fused_attention( if config.softmax_type != "vanilla" and cp_comm_type != "a2a": pytest.skip(f"No support for non-vanilla softmax with cp_comm_type={cp_comm_type}!") - if ( - config.softmax_type != "vanilla" - and qkv_format == "thd" - and get_cudnn_version() < (9, 18, 0) - ): - pytest.skip("No support for non-vanilla softmax with THD format and cuDNN < 9.18.0!") - if dtype == "fp8" and scaling_mode is None: pytest.skip("dtype=fp8 requires scaling_mode != None!") if dtype != "fp8" and scaling_mode is not None: diff --git a/tests/pytorch/test_cudnn_min_version.py b/tests/pytorch/test_cudnn_min_version.py new file mode 100644 index 00000000000..14180d1ef60 --- /dev/null +++ b/tests/pytorch/test_cudnn_min_version.py @@ -0,0 +1,65 @@ +# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# See LICENSE for license information. +"""The cuDNN floor must reject older runtimes and stay consistent across its declarations. + +``MIN_CUDNN_VERSION`` is one of three copies of the same number: the C++ build asserts +against ``kMinCudnnVersion`` in ``cudnn_min_version.h`` and the CMake configure step +rejects old headers using a literal in ``cuDNN.cmake``. CI always runs a recent cuDNN, +so neither the runtime rejection nor the agreement between those copies is otherwise +exercised. +""" + +from __future__ import annotations + +import re +from pathlib import Path +from typing import Tuple + +import pytest + +from transformer_engine.common import ( + MIN_CUDNN_VERSION, + check_cudnn_version, + decode_cudnn_version, +) + +_ROOT = Path(__file__).resolve().parents[2] +_HEADER = _ROOT / "transformer_engine" / "common" / "cudnn_min_version.h" +_CMAKE = _ROOT / "transformer_engine" / "common" / "cmake" / "cuDNN.cmake" + + +def _encode(version: Tuple[int, int, int]) -> int: + """Encode (major, minor, patch) the way cudnnGetVersion() reports it.""" + major, minor, patch = version + return major * (1000 if major < 9 else 10000) + minor * 100 + patch + + +@pytest.mark.parametrize("version", ((8, 9, 7), (9, 12, 0), (9, 18, 0))) +def test_check_cudnn_version_rejects_older_runtimes(version): + with pytest.raises(RuntimeError, match="requires cuDNN"): + check_cudnn_version(_encode(version)) + + +@pytest.mark.parametrize("version", (MIN_CUDNN_VERSION, (9, 19, 0), (10, 0, 0))) +def test_check_cudnn_version_accepts_supported_runtimes(version): + check_cudnn_version(_encode(version)) + + +@pytest.mark.parametrize("version", ((8, 9, 7), (9, 18, 1), (9, 27, 0))) +def test_decode_cudnn_version_round_trips(version): + assert decode_cudnn_version(_encode(version)) == version + + +@pytest.mark.skipif(not _HEADER.is_file(), reason="Source tree is not available.") +def test_header_floor_matches_python_floor(): + match = re.search(r"kMinCudnnVersion\s*=\s*(\d+)", _HEADER.read_text()) + assert match is not None, f"Could not find kMinCudnnVersion in {_HEADER}." + assert decode_cudnn_version(int(match.group(1))) == MIN_CUDNN_VERSION + + +@pytest.mark.skipif(not _CMAKE.is_file(), reason="Source tree is not available.") +def test_cmake_floor_matches_python_floor(): + match = re.search(r"CUDNN_VERSION\s+VERSION_LESS\s+\"([\d.]+)\"", _CMAKE.read_text()) + assert match is not None, f"Could not find the version guard in {_CMAKE}." + assert tuple(int(part) for part in match.group(1).split(".")) == MIN_CUDNN_VERSION diff --git a/transformer_engine/common/__init__.py b/transformer_engine/common/__init__.py index 1c55083f34b..cdce2288bb6 100644 --- a/transformer_engine/common/__init__.py +++ b/transformer_engine/common/__init__.py @@ -21,7 +21,7 @@ # Minimum cuDNN version supported by Transformer Engine, as (major, minor, patch). # Keep in sync with kMinCudnnVersion in transformer_engine/common/cudnn_min_version.h. -MIN_CUDNN_VERSION = (9, 12, 0) +MIN_CUDNN_VERSION = (9, 18, 1) def decode_cudnn_version(encoded_version: int) -> Tuple[int, int, int]: diff --git a/transformer_engine/common/cmake/cuDNN.cmake b/transformer_engine/common/cmake/cuDNN.cmake index aa944030370..00ad2340f15 100644 --- a/transformer_engine/common/cmake/cuDNN.cmake +++ b/transformer_engine/common/cmake/cuDNN.cmake @@ -39,9 +39,9 @@ if(CUDNN_INCLUDE_DIR) set(CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}") # Keep in sync with kMinCudnnVersion in transformer_engine/common/cudnn_min_version.h. - if(CUDNN_VERSION VERSION_LESS "9.12.0") + if(CUDNN_VERSION VERSION_LESS "9.18.1") message(FATAL_ERROR - "Transformer Engine requires cuDNN 9.12.0 or later, but found ${CUDNN_VERSION} " + "Transformer Engine requires cuDNN 9.18.1 or later, but found ${CUDNN_VERSION} " "headers in ${CUDNN_INCLUDE_DIR}.") endif() endif() diff --git a/transformer_engine/common/cudnn_min_version.h b/transformer_engine/common/cudnn_min_version.h index 1e3ff0a34a3..e86d2154a61 100644 --- a/transformer_engine/common/cudnn_min_version.h +++ b/transformer_engine/common/cudnn_min_version.h @@ -18,10 +18,10 @@ namespace transformer_engine { // Minimum cuDNN version supported by Transformer Engine, encoded as cudnnGetVersion() reports it. // Keep in sync with MIN_CUDNN_VERSION in transformer_engine/common/__init__.py. -constexpr size_t kMinCudnnVersion = 91200; +constexpr size_t kMinCudnnVersion = 91801; static_assert(static_cast(CUDNN_VERSION) >= kMinCudnnVersion, - "Transformer Engine must be built against cuDNN 9.12.0 or later headers."); + "Transformer Engine must be built against cuDNN 9.18.1 or later headers."); } // namespace transformer_engine diff --git a/transformer_engine/jax/cpp_extensions/attention.py b/transformer_engine/jax/cpp_extensions/attention.py index 6d110c627ad..50a82c74baf 100644 --- a/transformer_engine/jax/cpp_extensions/attention.py +++ b/transformer_engine/jax/cpp_extensions/attention.py @@ -3818,12 +3818,11 @@ def fused_attn_bwd( ) ) or ( not FusedAttnHelper.is_non_deterministic_allowed() - and cudnn_attention.cudnn_version() >= 91801 and attn_bias_type in (AttnBiasType.NO_BIAS, AttnBiasType.ALIBI) and dropout_probability == 0.0 ), ( "For sm100+, non-deterministic bprop does not support bias with dropout," - " and deterministic bprop (cuDNN 9.18.1+) does not support bias or dropout" + " and deterministic bprop does not support bias or dropout" ) fused_config = _FusedAttnConfig( diff --git a/transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py b/transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py index 4062ffa3781..17b339300f0 100644 --- a/transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py +++ b/transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py @@ -12,7 +12,6 @@ from transformer_engine.pytorch.device import te_device_type from transformer_engine.pytorch.utils import ( - get_cudnn_version, nvtx_range_pop, nvtx_range_push, get_device_compute_capability, @@ -5719,12 +5718,6 @@ def attn_forward_func_with_cp( assert ( softmax_type == "vanilla" or cp_comm_type == "a2a" ), f"Context parallelism only supports {softmax_type=} with cp_comm_type = 'a2a'!" - if get_cudnn_version() < (9, 18, 0): - assert softmax_type == "vanilla" or qkv_format != "thd", ( - f"Before cuDNN 9.18.0, context parallelism does not support {softmax_type=} with" - " qkv_format = 'thd'!" - ) - args = [ is_training, q, diff --git a/transformer_engine/pytorch/attention/dot_product_attention/utils.py b/transformer_engine/pytorch/attention/dot_product_attention/utils.py index 297c1830c3b..5e4a4168116 100644 --- a/transformer_engine/pytorch/attention/dot_product_attention/utils.py +++ b/transformer_engine/pytorch/attention/dot_product_attention/utils.py @@ -803,34 +803,10 @@ def _disable_all_flash_attention() -> None: if not allow_emulation: logger.debug("Disabling UnfusedDotProductAttention for FP8 attention") use_unfused_attention = False - if use_fused_attention and fp8_recipe.delayed(): - if ( - device_compute_capability >= (10, 0) - and deterministic - and cudnn_version < (9, 18, 0) - ): - logger.debug( - "Disabling FusedAttention for FP8 delayed scaling on arch >= sm100 with" - " determinism for cuDNN < 9.18.0" - ) - use_fused_attention = False if use_fused_attention and fp8_recipe.float8_current_scaling(): if device_compute_capability < (10, 0): logger.debug("Disabling FusedAttention for FP8 current scaling on arch < sm100") use_fused_attention = False - else: - if cudnn_version < (9, 14, 0): - logger.debug( - "Disabling FusedAttention for FP8 current scaling with cuDNN < 9.14.0" - ) - use_fused_attention = False - else: - if deterministic and cudnn_version < (9, 18, 0): - logger.debug( - "Disabling FusedAttention for FP8 current scaling with determinism" - " for cuDNN < 9.18.0" - ) - use_fused_attention = False if use_fused_attention and fp8_recipe.mxfp8(): reason = mxfp8_support_error( 10 * device_compute_capability[0] + device_compute_capability[1], @@ -1239,22 +1215,14 @@ def _is_fa3_supported(num_heads, num_gqa_groups, head_dim_qk, head_dim_v, qkv_dt if use_unfused_attention: logger.debug("Disabling UnfusedDotProductAttention for pad_between_seqs = True") use_unfused_attention = False - if is_sm12x: - if cudnn_version < (9, 18, 1): - if use_fused_attention: - logger.debug( - "Disabling FusedAttention when Q or KV uses THD because it is" - " not supported for compute capability = sm12x and cuDNN version < 9.18.1" - ) - use_fused_attention = False - elif qkv_layout in {"t3hd", "th3d"}: - if use_fused_attention: - logger.debug( - "Disabling FusedAttention as qkv_layout = %s is not supported for" - " compute capability = sm12x", - qkv_layout, - ) - use_fused_attention = False + if is_sm12x and qkv_layout in {"t3hd", "th3d"}: + if use_fused_attention: + logger.debug( + "Disabling FusedAttention as qkv_layout = %s is not supported for" + " compute capability = sm12x", + qkv_layout, + ) + use_fused_attention = False # Filter: Dropout if attention_dropout != 0.0: @@ -1293,13 +1261,6 @@ def _is_fa3_supported(num_heads, num_gqa_groups, head_dim_qk, head_dim_v, qkv_dt softmax_type, ) use_unfused_attention = False - if qkv_format == "thd" and cudnn_version < (9, 18, 0): - logger.debug( - "Disabling FusedAttention for softmax_type = %s, qkv_format = thd and cuDNN" - " version < 9.18", - softmax_type, - ) - use_fused_attention = False if context_parallel and cp_comm_type != "a2a": logger.debug( "Disabling FusedAttention for context parallelism with softmax_type = %s and" diff --git a/transformer_engine/pytorch/cpp_extensions/fused_attn.py b/transformer_engine/pytorch/cpp_extensions/fused_attn.py index 41d3b03bf40..4d9ab378410 100644 --- a/transformer_engine/pytorch/cpp_extensions/fused_attn.py +++ b/transformer_engine/pytorch/cpp_extensions/fused_attn.py @@ -685,15 +685,6 @@ def _support_reason(config, version, capability, backward=False): if not fp8: if q_format == kv_format == "thd" and capability < (9, 0): return "F16/BF16 fused attention with THD format requires sm90 or later." - affected_cuda_graph = version <= 91500 and config.cuda_graph and config.max_seqlen_kv % 128 - if ( - affected_cuda_graph - and config.is_training - and q_format == kv_format - and q_format in ("bshd", "sbhd") - and not padding - ): - return "Known cuDNN <= 9.15 issue with CUDA graph. Please upgrade cuDNN." if ( backward and ragged_stats