Repository: huggingface/transformers
Pull request: add type hints

# What does this PR do?

Add type hints to `import_utils.py`

Based on these [docs](https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker), this change should avoid errors like:
```
infinity_emb/inference/loading_strategy.py:10: error: Skipping analyzing "transformers.utils.import_utils": module is installed, but missing library stubs or py.typed marker  [import-untyped]
```


<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?




Changed files:
filename: src/transformers/utils/import_utils.py
patch: @@ -31,7 +31,7 @@
 from functools import lru_cache
 from itertools import chain
 from types import ModuleType
-from typing import Any, Optional, Union
+from typing import Any, Callable, Optional, Union
 
 from packaging import version
 
@@ -371,35 +371,35 @@ def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[
         logger.info(f"Torch XLA version {_torch_xla_version} available.")
 
 
-def is_kenlm_available():
+def is_kenlm_available() -> Union[tuple[bool, str], bool]:
     return _kenlm_available
 
 
-def is_kernels_available():
+def is_kernels_available() -> Union[tuple[bool, str], bool]:
     return _kernels_available
 
 
-def is_cv2_available():
+def is_cv2_available() -> Union[tuple[bool, str], bool]:
     return _cv2_available
 
 
-def is_yt_dlp_available():
+def is_yt_dlp_available() -> Union[tuple[bool, str], bool]:
     return _yt_dlp_available
 
 
-def is_torch_available():
+def is_torch_available() -> Union[tuple[bool, str], bool]:
     return _torch_available
 
 
-def is_libcst_available():
+def is_libcst_available() -> Union[tuple[bool, str], bool]:
     return _libcst_available
 
 
-def is_accelerate_available(min_version: str = ACCELERATE_MIN_VERSION):
+def is_accelerate_available(min_version: str = ACCELERATE_MIN_VERSION) -> bool:
     return _accelerate_available and version.parse(_accelerate_version) >= version.parse(min_version)
 
 
-def is_torch_accelerator_available():
+def is_torch_accelerator_available() -> bool:
     if is_torch_available():
         import torch
 
@@ -408,7 +408,7 @@ def is_torch_accelerator_available():
     return False
 
 
-def is_torch_deterministic():
+def is_torch_deterministic() -> bool:
     """
     Check whether pytorch uses deterministic algorithms by looking if torch.set_deterministic_debug_mode() is set to 1 or 2"
     """
@@ -423,23 +423,23 @@ def is_torch_deterministic():
     return False
 
 
-def is_triton_available(min_version: str = TRITON_MIN_VERSION):
+def is_triton_available(min_version: str = TRITON_MIN_VERSION) -> bool:
     return _triton_available and version.parse(_triton_version) >= version.parse(min_version)
 
 
-def is_hadamard_available():
+def is_hadamard_available() -> Union[tuple[bool, str], bool]:
     return _hadamard_available
 
 
-def is_hqq_available(min_version: str = HQQ_MIN_VERSION):
+def is_hqq_available(min_version: str = HQQ_MIN_VERSION) -> bool:
     return _hqq_available and version.parse(_hqq_version) >= version.parse(min_version)
 
 
-def is_pygments_available():
+def is_pygments_available() -> Union[tuple[bool, str], bool]:
     return _pygments_available
 
 
-def get_torch_version():
+def get_torch_version() -> str:
     return _torch_version
 
 
@@ -457,7 +457,7 @@ def is_torch_sdpa_available():
     return True
 
 
-def is_torch_flex_attn_available():
+def is_torch_flex_attn_available() -> bool:
     if not is_torch_available() or _torch_version == "N/A":
         return False
 
@@ -466,75 +466,75 @@ def is_torch_flex_attn_available():
     return version.parse(_torch_version) >= version.parse("2.5.0")
 
 
-def is_torchvision_available():
+def is_torchvision_available() -> bool:
     return _torchvision_available
 
 
-def is_torchvision_v2_available():
+def is_torchvision_v2_available() -> bool:
     if not is_torchvision_available():
         return False
 
     # NOTE: We require torchvision>=0.15 as v2 transforms are available from this version: https://pytorch.org/vision/stable/transforms.html#v1-or-v2-which-one-should-i-use
     return version.parse(_torchvision_version) >= version.parse("0.15")
 
 
-def is_galore_torch_available():
+def is_galore_torch_available() -> Union[tuple[bool, str], bool]:
     return _galore_torch_available
 
 
-def is_apollo_torch_available():
+def is_apollo_torch_available() -> Union[tuple[bool, str], bool]:
     return _apollo_torch_available
 
 
-def is_torch_optimi_available():
+def is_torch_optimi_available() -> Union[tuple[bool, str], bool]:
     return _torch_optimi_available
 
 
-def is_lomo_available():
+def is_lomo_available() -> Union[tuple[bool, str], bool]:
     return _lomo_available
 
 
-def is_grokadamw_available():
+def is_grokadamw_available() -> Union[tuple[bool, str], bool]:
     return _grokadamw_available
 
 
-def is_schedulefree_available(min_version: str = SCHEDULEFREE_MIN_VERSION):
+def is_schedulefree_available(min_version: str = SCHEDULEFREE_MIN_VERSION) -> bool:
     return _schedulefree_available and version.parse(_schedulefree_version) >= version.parse(min_version)
 
 
-def is_pyctcdecode_available():
+def is_pyctcdecode_available() -> Union[tuple[bool, str], bool]:
     return _pyctcdecode_available
 
 
-def is_librosa_available():
+def is_librosa_available() -> Union[tuple[bool, str], bool]:
     return _librosa_available
 
 
-def is_essentia_available():
+def is_essentia_available() -> Union[tuple[bool, str], bool]:
     return _essentia_available
 
 
-def is_pydantic_available():
+def is_pydantic_available() -> Union[tuple[bool, str], bool]:
     return _pydantic_available
 
 
-def is_fastapi_available():
+def is_fastapi_available() -> Union[tuple[bool, str], bool]:
     return _fastapi_available
 
 
-def is_uvicorn_available():
+def is_uvicorn_available() -> Union[tuple[bool, str], bool]:
     return _uvicorn_available
 
 
-def is_openai_available():
+def is_openai_available() -> Union[tuple[bool, str], bool]:
     return _openai_available
 
 
-def is_pretty_midi_available():
+def is_pretty_midi_available() -> Union[tuple[bool, str], bool]:
     return _pretty_midi_available
 
 
-def is_torch_cuda_available():
+def is_torch_cuda_available() -> bool:
     if is_torch_available():
         import torch
 
@@ -543,7 +543,7 @@ def is_torch_cuda_available():
         return False
 
 
-def is_cuda_platform():
+def is_cuda_platform() -> bool:
     if is_torch_available():
         import torch
 
@@ -552,7 +552,7 @@ def is_cuda_platform():
         return False
 
 
-def is_rocm_platform():
+def is_rocm_platform() -> bool:
     if is_torch_available():
         import torch
 
@@ -561,7 +561,7 @@ def is_rocm_platform():
         return False
 
 
-def is_mamba_ssm_available():
+def is_mamba_ssm_available() -> Union[tuple[bool, str], bool]:
     if is_torch_available():
         import torch
 
@@ -572,7 +572,7 @@ def is_mamba_ssm_available():
     return False
 
 
-def is_mamba_2_ssm_available():
+def is_mamba_2_ssm_available() -> bool:
     if is_torch_available():
         import torch
 
@@ -587,7 +587,7 @@ def is_mamba_2_ssm_available():
     return False
 
 
-def is_causal_conv1d_available():
+def is_causal_conv1d_available() -> Union[tuple[bool, str], bool]:
     if is_torch_available():
         import torch
 
@@ -597,19 +597,19 @@ def is_causal_conv1d_available():
     return False
 
 
-def is_xlstm_available():
+def is_xlstm_available() -> Union[tuple[bool, str], bool]:
     if is_torch_available():
         return _is_package_available("xlstm")
     return False
 
 
-def is_mambapy_available():
+def is_mambapy_available() -> Union[tuple[bool, str], bool]:
     if is_torch_available():
         return _is_package_available("mambapy")
     return False
 
 
-def is_torch_mps_available(min_version: Optional[str] = None):
+def is_torch_mps_available(min_version: Optional[str] = None) -> bool:
     if is_torch_available():
         import torch
 
@@ -639,11 +639,11 @@ def is_torch_bf16_gpu_available() -> bool:
     return False
 
 
-def is_torch_bf16_cpu_available() -> bool:
+def is_torch_bf16_cpu_available() -> Union[tuple[bool, str], bool]:
     return is_torch_available()
 
 
-def is_torch_bf16_available():
+def is_torch_bf16_available() -> bool:
     # the original bf16 check was for gpu only, but later a cpu/bf16 combo has emerged so this util
     # has become ambiguous and therefore deprecated
     warnings.warn(
@@ -655,7 +655,7 @@ def is_torch_bf16_available():
 
 
 @lru_cache
-def is_torch_fp16_available_on_device(device):
+def is_torch_fp16_available_on_device(device: str) -> bool:
     if not is_torch_available():
         return False
 
@@ -687,7 +687,7 @@ def is_torch_fp16_available_on_device(device):
 
 
 @lru_cache
-def is_torch_bf16_available_on_device(device):
+def is_torch_bf16_available_on_device(device: str) -> bool:
     if not is_torch_available():
         return False
 
@@ -710,7 +710,7 @@ def is_torch_bf16_available_on_device(device):
     return True
 
 
-def is_torch_tf32_available():
+def is_torch_tf32_available() -> bool:
     if not is_torch_available():
         return False
 
@@ -723,55 +723,55 @@ def is_torch_tf32_available():
     return True
 
 
-def is_torch_fx_available():
+def is_torch_fx_available() -> Union[tuple[bool, str], bool]:
     return is_torch_available()
 
 
-def is_peft_available():
+def is_peft_available() -> Union[tuple[bool, str], bool]:
     return _peft_available
 
 
-def is_bs4_available():
+def is_bs4_available() -> Union[tuple[bool, str], bool]:
     return _bs4_available
 
 
-def is_tf_available():
+def is_tf_available() -> bool:
     return _tf_available
 
 
-def is_coloredlogs_available():
+def is_coloredlogs_available() -> Union[tuple[bool, str], bool]:
     return _coloredlogs_available
 
 
-def is_tf2onnx_available():
+def is_tf2onnx_available() -> Union[tuple[bool, str], bool]:
     return _tf2onnx_available
 
 
-def is_onnx_available():
+def is_onnx_available() -> Union[tuple[bool, str], bool]:
     return _onnx_available
 
 
-def is_flax_available():
+def is_flax_available() -> bool:
     return _flax_available
 
 
-def is_flute_available():
+def is_flute_available() -> bool:
     try:
         return importlib.util.find_spec("flute") is not None and importlib.metadata.version("flute-kernel") >= "0.4.1"
     except importlib.metadata.PackageNotFoundError:
         return False
 
 
-def is_ftfy_available():
+def is_ftfy_available() -> Union[tuple[bool, str], bool]:
     return _ftfy_available
 
 
-def is_g2p_en_available():
+def is_g2p_en_available() -> Union[tuple[bool, str], bool]:
     return _g2p_en_available
 
 
 @lru_cache
-def is_torch_xla_available(check_is_tpu=False, check_is_gpu=False):
+def is_torch_xla_available(check_is_tpu=False, check_is_gpu=False) -> bool:
     """
     Check if `torch_xla` is available. To train a native pytorch job in an environment with torch xla installed, set
     the USE_TORCH_XLA to false.
@@ -792,14 +792,14 @@ def is_torch_xla_available(check_is_tpu=False, check_is_gpu=False):
 
 
 @lru_cache
-def is_torch_neuroncore_available(check_device=True):
+def is_torch_neuroncore_available(check_device=True) -> bool:
     if importlib.util.find_spec("torch_neuronx") is not None:
         return is_torch_xla_available()
     return False
 
 
 @lru_cache
-def is_torch_npu_available(check_device=False):
+def is_torch_npu_available(check_device=False) -> bool:
     "Checks if `torch_npu` is installed and potentially if a NPU is in the environment"
     if not _torch_available or importlib.util.find_spec("torch_npu") is None:
         return False
@@ -818,7 +818,7 @@ def is_torch_npu_available(check_device=False):
 
 
 @lru_cache
-def is_torch_mlu_available(check_device=False):
+def is_torch_mlu_available(check_device=False) -> bool:
     """
     Checks if `mlu` is available via an `cndev-based` check which won't trigger the drivers and leave mlu
     uninitialized.
@@ -843,7 +843,7 @@ def is_torch_mlu_available(check_device=False):
 
 
 @lru_cache
-def is_torch_musa_available(check_device=False):
+def is_torch_musa_available(check_device=False) -> bool:
     "Checks if `torch_musa` is installed and potentially if a MUSA is in the environment"
     if not _torch_available or importlib.util.find_spec("torch_musa") is None:
         return False
@@ -866,7 +866,7 @@ def is_torch_musa_available(check_device=False):
 
 
 @lru_cache
-def is_torch_hpu_available():
+def is_torch_hpu_available() -> bool:
     "Checks if `torch.hpu` is available and potentially if a HPU is in the environment"
     if (
         not _torch_available
@@ -963,7 +963,7 @@ def hpu_backend_compile(*args, **kwargs):
 
 
 @lru_cache
-def is_habana_gaudi1():
+def is_habana_gaudi1() -> bool:
     if not is_torch_hpu_available():
         return False
 
@@ -973,15 +973,15 @@ def is_habana_gaudi1():
     return htexp._get_device_type() == htexp.synDeviceType.synDeviceGaudi
 
 
-def is_torchdynamo_available():
+def is_torchdynamo_available() -> Union[tuple[bool, str], bool]:
     return is_torch_available()
 
 
-def is_torch_compile_available():
+def is_torch_compile_available() -> Union[tuple[bool, str], bool]:
     return is_torch_available()
 
 
-def is_torchdynamo_compiling():
+def is_torchdynamo_compiling() -> Union[tuple[bool, str], bool]:
     if not is_torch_available():
         return False
 
@@ -1000,7 +1000,7 @@ def is_torchdynamo_compiling():
             return False
 
 
-def is_torchdynamo_exporting():
+def is_torchdynamo_exporting() -> bool:
     if not is_torch_available():
         return False
 
@@ -1017,61 +1017,61 @@ def is_torchdynamo_exporting():
             return False
 
 
-def is_torch_tensorrt_fx_available():
+def is_torch_tensorrt_fx_available() -> bool:
     if importlib.util.find_spec("torch_tensorrt") is None:
         return False
     return importlib.util.find_spec("torch_tensorrt.fx") is not None
 
 
-def is_datasets_available():
+def is_datasets_available() -> Union[tuple[bool, str], bool]:
     return _datasets_available
 
 
-def is_detectron2_available():
+def is_detectron2_available() -> Union[tuple[bool, str], bool]:
     return _detectron2_available
 
 
-def is_rjieba_available():
+def is_rjieba_available() -> Union[tuple[bool, str], bool]:
     return _rjieba_available
 
 
-def is_psutil_available():
+def is_psutil_available() -> Union[tuple[bool, str], bool]:
     return _psutil_available
 
 
-def is_py3nvml_available():
+def is_py3nvml_available() -> Union[tuple[bool, str], bool]:
     return _py3nvml_available
 
 
-def is_sacremoses_available():
+def is_sacremoses_available() -> Union[tuple[bool, str], bool]:
     return _sacremoses_available
 
 
-def is_apex_available():
+def is_apex_available() -> Union[tuple[bool, str], bool]:
     return _apex_available
 
 
-def is_aqlm_available():
+def is_aqlm_available() -> Union[tuple[bool, str], bool]:
     return _aqlm_available
 
 
-def is_vptq_available(min_version: str = VPTQ_MIN_VERSION):
+def is_vptq_available(min_version: str = VPTQ_MIN_VERSION) -> bool:
     return _vptq_available and version.parse(_vptq_version) >= version.parse(min_version)
 
 
-def is_av_available():
+def is_av_available() -> bool:
     return _av_available
 
 
-def is_decord_available():
+def is_decord_available() -> bool:
     return _decord_available
 
 
-def is_torchcodec_available():
+def is_torchcodec_available() -> bool:
     return _torchcodec_available
 
 
-def is_ninja_available():
+def is_ninja_available() -> bool:
     r"""
     Code comes from *torch.utils.cpp_extension.is_ninja_available()*. Returns `True` if the
     [ninja](https://ninja-build.org/) build system is available on the system, `False` otherwise.
@@ -1084,7 +1084,7 @@ def is_ninja_available():
         return True
 
 
-def is_ipex_available(min_version: str = ""):
+def is_ipex_available(min_version: str = "") -> bool:
     def get_major_and_minor_from_version(full_version):
         return str(version.parse(full_version).major) + "." + str(version.parse(full_version).minor)
 
@@ -1105,7 +1105,7 @@ def get_major_and_minor_from_version(full_version):
 
 
 @lru_cache
-def is_torch_xpu_available(check_device=False):
+def is_torch_xpu_available(check_device: bool = False) -> bool:
     """
     Checks if XPU acceleration is available either via native PyTorch (>=2.6),
     `intel_extension_for_pytorch` or via stock PyTorch (>=2.4) and potentially
@@ -1134,7 +1134,7 @@ def is_torch_xpu_available(check_device=False):
 
 
 @lru_cache
-def is_bitsandbytes_available(check_library_only=False) -> bool:
+def is_bitsandbytes_available(check_library_only: bool = False) -> bool:
     if not _bitsandbytes_available:
         return False
 
@@ -1164,7 +1164,7 @@ def is_bitsandbytes_multi_backend_available() -> bool:
     return "multi_backend" in getattr(bnb, "features", set())
 
 
-def is_flash_attn_2_available():
+def is_flash_attn_2_available() -> bool:
     if not is_torch_available():
         return False
 
@@ -1189,7 +1189,7 @@ def is_flash_attn_2_available():
 
 
 @lru_cache
-def is_flash_attn_3_available():
+def is_flash_attn_3_available() -> bool:
     if not is_torch_available():
         return False
 
@@ -1208,23 +1208,23 @@ def is_flash_attn_3_available():
 
 
 @lru_cache
-def is_flash_attn_greater_or_equal_2_10():
+def is_flash_attn_greater_or_equal_2_10() -> bool:
     if not _is_package_available("flash_attn"):
         return False
 
     return version.parse(importlib.metadata.version("flash_attn")) >= version.parse("2.1.0")
 
 
 @lru_cache
-def is_flash_attn_greater_or_equal(library_version: str):
+def is_flash_attn_greater_or_equal(library_version: str) -> bool:
     if not _is_package_available("flash_attn"):
         return False
 
     return version.parse(importlib.metadata.version("flash_attn")) >= version.parse(library_version)
 
 
 @lru_cache
-def is_torch_greater_or_equal(library_version: str, accept_dev: bool = False):
+def is_torch_greater_or_equal(library_version: str, accept_dev: bool = False) -> bool:
     """
     Accepts a library version and returns True if the current version of the library is greater than or equal to the
     given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches
@@ -1242,7 +1242,7 @@ def is_torch_greater_or_equal(library_version: str, accept_dev: bool = False):
 
 
 @lru_cache
-def is_torch_less_or_equal(library_version: str, accept_dev: bool = False):
+def is_torch_less_or_equal(library_version: str, accept_dev: bool = False) -> bool:
     """
     Accepts a library version and returns True if the current version of the library is less than or equal to the
     given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches
@@ -1260,7 +1260,7 @@ def is_torch_less_or_equal(library_version: str, accept_dev: bool = False):
 
 
 @lru_cache
-def is_huggingface_hub_greater_or_equal(library_version: str, accept_dev: bool = False):
+def is_huggingface_hub_greater_or_equal(library_version: str, accept_dev: bool = False) -> bool:
     if not _is_package_available("huggingface_hub"):
         return False
 
@@ -1273,7 +1273,7 @@ def is_huggingface_hub_greater_or_equal(library_version: str, accept_dev: bool =
 
 
 @lru_cache
-def is_quanto_greater(library_version: str, accept_dev: bool = False):
+def is_quanto_greater(library_version: str, accept_dev: bool = False) -> bool:
     """
     Accepts a library version and returns True if the current version of the library is greater than or equal to the
     given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches
@@ -1294,49 +1294,49 @@ def is_torchdistx_available():
     return _torchdistx_available
 
 
-def is_faiss_available():
+def is_faiss_available() -> bool:
     return _faiss_available
 
 
-def is_scipy_available():
+def is_scipy_available() -> Union[tuple[bool, str], bool]:
     return _scipy_available
 
 
-def is_sklearn_available():
+def is_sklearn_available() -> Union[tuple[bool, str], bool]:
     return _sklearn_available
 
 
-def is_sentencepiece_available():
+def is_sentencepiece_available() -> Union[tuple[bool, str], bool]:
     return _sentencepiece_available
 
 
-def is_seqio_available():
+def is_seqio_available() -> Union[tuple[bool, str], bool]:
     return _is_seqio_available
 
 
-def is_gguf_available(min_version: str = GGUF_MIN_VERSION):
+def is_gguf_available(min_version: str = GGUF_MIN_VERSION) -> bool:
     return _is_gguf_available and version.parse(_gguf_version) >= version.parse(min_version)
 
 
-def is_protobuf_available():
+def is_protobuf_available() -> bool:
     if importlib.util.find_spec("google") is None:
         return False
     return importlib.util.find_spec("google.protobuf") is not None
 
 
-def is_fsdp_available(min_version: str = FSDP_MIN_VERSION):
+def is_fsdp_available(min_version: str = FSDP_MIN_VERSION) -> bool:
     return is_torch_available() and version.parse(_torch_version) >= version.parse(min_version)
 
 
-def is_optimum_available():
+def is_optimum_available() -> Union[tuple[bool, str], bool]:
     return _optimum_available
 
 
-def is_auto_awq_available():
+def is_auto_awq_available() -> bool:
     return _auto_awq_available
 
 
-def is_auto_round_available(min_version: str = AUTOROUND_MIN_VERSION):
+def is_auto_round_available(min_version: str = AUTOROUND_MIN_VERSION) -> bool:
     return _auto_round_available and version.parse(_auto_round_version) >= version.parse(min_version)
 
 
@@ -1345,56 +1345,56 @@ def is_optimum_quanto_available():
     return _is_optimum_quanto_available
 
 
-def is_quark_available():
+def is_quark_available() -> Union[tuple[bool, str], bool]:
     return _quark_available
 
 
-def is_fp_quant_available():
+def is_fp_quant_available() -> bool:
     return _fp_quant_available and version.parse(_fp_quant_version) >= version.parse("0.1.6")
 
 
-def is_qutlass_available():
+def is_qutlass_available() -> Union[tuple[bool, str], bool]:
     return _qutlass_available
 
 
-def is_compressed_tensors_available():
+def is_compressed_tensors_available() -> bool:
     return _compressed_tensors_available
 
 
-def is_auto_gptq_available():
+def is_auto_gptq_available() -> Union[tuple[bool, str], bool]:
     return _auto_gptq_available
 
 
-def is_gptqmodel_available():
+def is_gptqmodel_available() -> Union[tuple[bool, str], bool]:
     return _gptqmodel_available
 
 
-def is_eetq_available():
+def is_eetq_available() -> Union[tuple[bool, str], bool]:
     return _eetq_available
 
 
-def is_fbgemm_gpu_available():
+def is_fbgemm_gpu_available() -> Union[tuple[bool, str], bool]:
     return _fbgemm_gpu_available
 
 
-def is_levenshtein_available():
+def is_levenshtein_available() -> Union[tuple[bool, str], bool]:
     return _levenshtein_available
 
 
-def is_optimum_neuron_available():
+def is_optimum_neuron_available() -> Union[tuple[bool, str], bool]:
     return _optimum_available and _is_package_available("optimum.neuron")
 
 
-def is_safetensors_available():
+def is_safetensors_available() -> Union[tuple[bool, str], bool]:
     return _safetensors_available
 
 
-def is_tokenizers_available():
+def is_tokenizers_available() -> Union[tuple[bool, str], bool]:
     return _tokenizers_available
 
 
 @lru_cache
-def is_vision_available():
+def is_vision_available() -> bool:
     _pil_available = importlib.util.find_spec("PIL") is not None
     if _pil_available:
         try:
@@ -1408,27 +1408,27 @@ def is_vision_available():
     return _pil_available
 
 
-def is_pytesseract_available():
+def is_pytesseract_available() -> Union[tuple[bool, str], bool]:
     return _pytesseract_available
 
 
-def is_pytest_available():
+def is_pytest_available() -> Union[tuple[bool, str], bool]:
     return _pytest_available
 
 
-def is_spacy_available():
+def is_spacy_available() -> Union[tuple[bool, str], bool]:
     return _spacy_available
 
 
-def is_tensorflow_text_available():
+def is_tensorflow_text_available() -> Union[tuple[bool, str], bool]:
     return is_tf_available() and _tensorflow_text_available
 
 
-def is_keras_nlp_available():
+def is_keras_nlp_available() -> Union[tuple[bool, str], bool]:
     return is_tensorflow_text_available() and _keras_nlp_available
 
 
-def is_in_notebook():
+def is_in_notebook() -> bool:
     try:
         # Check if we are running inside Marimo
         if "marimo" in sys.modules:
@@ -1448,19 +1448,19 @@ def is_in_notebook():
         return False
 
 
-def is_pytorch_quantization_available():
+def is_pytorch_quantization_available() -> Union[tuple[bool, str], bool]:
     return _pytorch_quantization_available
 
 
-def is_tensorflow_probability_available():
+def is_tensorflow_probability_available() -> Union[tuple[bool, str], bool]:
     return _tensorflow_probability_available
 
 
-def is_pandas_available():
+def is_pandas_available() -> Union[tuple[bool, str], bool]:
     return _pandas_available
 
 
-def is_sagemaker_dp_enabled():
+def is_sagemaker_dp_enabled() -> bool:
     # Get the sagemaker specific env variable.
     sagemaker_params = os.getenv("SM_FRAMEWORK_PARAMS", "{}")
     try:
@@ -1474,7 +1474,7 @@ def is_sagemaker_dp_enabled():
     return _smdistributed_available
 
 
-def is_sagemaker_mp_enabled():
+def is_sagemaker_mp_enabled() -> bool:
     # Get the sagemaker specific mp parameters from smp_options variable.
     smp_options = os.getenv("SM_HP_MP_PARAMETERS", "{}")
     try:
@@ -1498,52 +1498,52 @@ def is_sagemaker_mp_enabled():
     return _smdistributed_available
 
 
-def is_training_run_on_sagemaker():
+def is_training_run_on_sagemaker() -> bool:
     return "SAGEMAKER_JOB_NAME" in os.environ
 
 
-def is_soundfile_available():
+def is_soundfile_available() -> Union[tuple[bool, str], bool]:
     return _soundfile_available
 
 
-def is_timm_available():
+def is_timm_available() -> Union[tuple[bool, str], bool]:
     return _timm_available
 
 
-def is_natten_available():
+def is_natten_available() -> Union[tuple[bool, str], bool]:
     return _natten_available
 
 
-def is_nltk_available():
+def is_nltk_available() -> Union[tuple[bool, str], bool]:
     return _nltk_available
 
 
-def is_torchaudio_available():
+def is_torchaudio_available() -> Union[tuple[bool, str], bool]:
     return _torchaudio_available
 
 
-def is_torchao_available(min_version: str = TORCHAO_MIN_VERSION):
+def is_torchao_available(min_version: str = TORCHAO_MIN_VERSION) -> bool:
     return _torchao_available and version.parse(_torchao_version) >= version.parse(min_version)
 
 
-def is_speech_available():
+def is_speech_available() -> Union[tuple[bool, str], bool]:
     # For now this depends on torchaudio but the exact dependency might evolve in the future.
     return _torchaudio_available
 
 
-def is_spqr_available():
+def is_spqr_available() -> Union[tuple[bool, str], bool]:
     return _spqr_available
 
 
-def is_phonemizer_available():
+def is_phonemizer_available() -> Union[tuple[bool, str], bool]:
     return _phonemizer_available
 
 
-def is_uroman_available():
+def is_uroman_available() -> Union[tuple[bool, str], bool]:
     return _uroman_available
 
 
-def torch_only_method(fn):
+def torch_only_method(fn: Callable) -> Callable:
     def wrapper(*args, **kwargs):
         if not _torch_available:
             raise ImportError(
@@ -1556,19 +1556,19 @@ def wrapper(*args, **kwargs):
     return wrapper
 
 
-def is_ccl_available():
+def is_ccl_available() -> bool:
     return _is_ccl_available
 
 
-def is_sudachi_available():
+def is_sudachi_available() -> bool:
     return _sudachipy_available
 
 
-def get_sudachi_version():
+def get_sudachi_version() -> bool:
     return _sudachipy_version
 
 
-def is_sudachi_projection_available():
+def is_sudachi_projection_available() -> bool:
     if not is_sudachi_available():
         return False
 
@@ -1577,54 +1577,54 @@ def is_sudachi_projection_available():
     return version.parse(_sudachipy_version) >= version.parse("0.6.8")
 
 
-def is_jumanpp_available():
+def is_jumanpp_available() -> bool:
     return (importlib.util.find_spec("rhoknp") is not None) and (shutil.which("jumanpp") is not None)
 
 
-def is_cython_available():
+def is_cython_available() -> bool:
     return importlib.util.find_spec("pyximport") is not None
 
 
-def is_jieba_available():
+def is_jieba_available() -> Union[tuple[bool, str], bool]:
     return _jieba_available
 
 
-def is_jinja_available():
+def is_jinja_available() -> Union[tuple[bool, str], bool]:
     return _jinja_available
 
 
-def is_mlx_available():
+def is_mlx_available() -> Union[tuple[bool, str], bool]:
     return _mlx_available
 
 
-def is_num2words_available():
+def is_num2words_available() -> Union[tuple[bool, str], bool]:
     return _num2words_available
 
 
-def is_tiktoken_available():
+def is_tiktoken_available() -> Union[tuple[bool, str], bool]:
     return _tiktoken_available and _blobfile_available
 
 
-def is_liger_kernel_available():
+def is_liger_kernel_available() -> bool:
     if not _liger_kernel_available:
         return False
 
     return version.parse(importlib.metadata.version("liger_kernel")) >= version.parse("0.3.0")
 
 
-def is_rich_available():
+def is_rich_available() -> Union[tuple[bool, str], bool]:
     return _rich_available
 
 
-def is_matplotlib_available():
+def is_matplotlib_available() -> Union[tuple[bool, str], bool]:
     return _matplotlib_available
 
 
-def is_mistral_common_available():
+def is_mistral_common_available() -> Union[tuple[bool, str], bool]:
     return _mistral_common_available
 
 
-def check_torch_load_is_safe():
+def check_torch_load_is_safe() -> None:
     if not is_torch_greater_or_equal("2.6"):
         raise ValueError(
             "Due to a serious vulnerability issue in `torch.load`, even with `weights_only=True`, we now require users "
@@ -2451,7 +2451,7 @@ def inner_fn(fun):
 }
 
 
-def fetch__all__(file_content):
+def fetch__all__(file_content) -> list[str]:
     """
     Returns the content of the __all__ variable in the file content.
     Returns None if not defined, otherwise returns a list of strings.
@@ -2483,7 +2483,7 @@ def fetch__all__(file_content):
 
     # __all__ is defined on multiple lines
     else:
-        _all = []
+        _all: list[str] = []
         for __all__line_index in range(1, len(lines)):
             if lines[__all__line_index].strip() == "]":
                 return _all
@@ -2855,7 +2855,7 @@ def define_import_structure(module_path: str, prefix: Optional[str] = None) -> I
         return spread_dict
 
 
-def clear_import_cache():
+def clear_import_cache() -> None:
     """
     Clear cached Transformers modules to allow reloading modified code.