Repository: huggingface/transformers
File: src/transformers/utils/import_utils.py (Python)

Code before:
    if is_torch_musa_available():
        device_info = torch.musa.get_device_properties(torch.musa.current_device())
        if f"{device_info.major}{device_info.minor}" >= "22":
            return True
        return False
    if not torch.cuda.is_available() or torch.version.cuda is None:
        return False
    if torch.cuda.get_device_properties(torch.cuda.current_device()).major < 8:
        return False
    return True


@lru_cache
def is_torch_flex_attn_available() -> bool:
    return is_torch_available() and version.parse(get_torch_version()) >= version.parse("2.5.0")


@lru_cache
def is_kenlm_available() -> bool:
    return _is_package_available("kenlm")


@lru_cache
def is_kernels_available(MIN_VERSION: str = KERNELS_MIN_VERSION) -> bool:
    is_available, kernels_version = _is_package_available("kernels", return_version=True)
    return is_available and version.parse(kernels_version) >= version.parse(MIN_VERSION)


@lru_cache
def is_cv2_available() -> bool:
    return _is_package_available("cv2")


@lru_cache
def is_yt_dlp_available() -> bool:
    return _is_package_available("yt_dlp")


@lru_cache
def is_libcst_available() -> bool:
    return _is_package_available("libcst")


@lru_cache
def is_accelerate_available(min_version: str = ACCELERATE_MIN_VERSION) -> bool:
    is_available, accelerate_version = _is_package_available("accelerate", return_version=True)
    return is_available and version.parse(accelerate_version) >= version.parse(min_version)


@lru_cache
def is_triton_available(min_version: str = TRITON_MIN_VERSION) -> bool:

Review comment (suggestion):
@Rocketknight1 here we used global instead of specifics like for an example this
torch.backends.cudnn.conv.fp32_precision = "tf32" , regarding my comment on the issue for which this PR is related.

Code after:
        device_info = torch.musa.get_device_properties(torch.musa.current_device())
        if f"{device_info.major}{device_info.minor}" >= "22":
            return True
        return False
    if not torch.cuda.is_available() or torch.version.cuda is None:
        return False
    if torch.cuda.get_device_properties(torch.cuda.current_device()).major < 8:
        return False
    return True


@lru_cache
def enable_tf32(enable: bool) -> None:
    """
    Set TF32 mode using the appropriate PyTorch API.
    For PyTorch 2.9+, uses the new fp32_precision API.
    For older versions, uses the legacy allow_tf32 flags.
    Args:
        enable: Whether to enable TF32 mode
    """
    import torch

    pytorch_version = version.parse(get_torch_version())
    if pytorch_version >= version.parse("2.9.0"):
        precision_mode = "tf32" if enable else "ieee"
        torch.backends.fp32_precision = precision_mode
    else:
        if is_torch_musa_available():
            torch.backends.mudnn.allow_tf32 = enable
        else:
            torch.backends.cuda.matmul.allow_tf32 = enable
            torch.backends.cudnn.allow_tf32 = enable


@lru_cache
def is_torch_flex_attn_available() -> bool:
    return is_torch_available() and version.parse(get_torch_version()) >= version.parse("2.5.0")


@lru_cache
def is_kenlm_available() -> bool:
    return _is_package_available("kenlm")


@lru_cache
def is_kernels_available() -> bool:
    return _is_package_available("kernels")


@lru_cache
def is_cv2_available() -> bool: