code: def validate_hyperparameters(
      model_id: str,
      model_version: str,
      hyperparameters: Dict[str, Any],
      validation_mode: HyperparameterValidationMode = HyperparameterValidationMode.VALIDATE_PROVIDED,
      region: Optional[str] = JUMPSTART_DEFAULT_REGION_NAME,
      sagemaker_session: Optional[session.Session] = None,
      tolerate_vulnerable_model: bool = False,
      tolerate_deprecated_model: bool = False,
  ) -> None:
      """Validate hyperparameters for JumpStart models.
  
      Args:
          model_id (str): Model ID of the model for which to validate hyperparameters.
          model_version (str): Version of the model for which to validate hyperparameters.
          hyperparameters (dict): Hyperparameters to validate.
          validation_mode (HyperparameterValidationMode): Method of validation to use with
            hyperparameters. If set to ``VALIDATE_PROVIDED``, only hyperparameters provided
            to this function will be validated, the missing hyperparameters will be ignored.
            If set to``VALIDATE_ALGORITHM``, all algorithm hyperparameters will be validated.
            If set to ``VALIDATE_ALL``, all hyperparameters for the model will be validated.
          region (str): Region for which to validate hyperparameters. (Default: JumpStart
            default region).
          sagemaker_session (Optional[Session]): Custom SageMaker Session to use.
            (Default: sagemaker.jumpstart.constants.DEFAULT_JUMPSTART_SAGEMAKER_SESSION).
          tolerate_vulnerable_model (bool): True if vulnerable versions of model
             specifications should be tolerated (exception not raised). If False, raises an
             exception if the script used by this version of the model has dependencies with known
             security vulnerabilities. (Default: False).
          tolerate_deprecated_model (bool): True if deprecated models should be tolerated
             (exception not raised). False if these models should raise an exception.
             (Default: False).
  
      Raises:
          JumpStartHyperparametersError: If the hyperparameters are not formatted correctly,
              according to their metadata specs.
  
      """
  
      if validation_mode is None:
          validation_mode = (
              HyperparameterValidationMode.VALIDATE_PROVIDED
          )
  
      if region is None:
          region = JUMPSTART_DEFAULT_REGION_NAME
  
      model_specs = verify_model_region_and_return_specs(
          model_id=model_id,
          version=model_version,
          region=region,
          scope=JumpStartScriptScope.TRAINING,
          sagemaker_session=sagemaker_session,
          tolerate_deprecated_model=tolerate_deprecated_model,
          tolerate_vulnerable_model=tolerate_vulnerable_model,
      )
      hyperparameters_specs = model_specs.hyperparameters
  
      if (
          validation_mode
          == HyperparameterValidationMode.VALIDATE_PROVIDED
      ):
          for (
              hyperparam_name,
              hyperparam_value,
          ) in hyperparameters.items():
              _validate_hyperparameter(
                  hyperparam_name,
                  hyperparam_value,
                  hyperparameters_specs,
              )
  
      elif (
          validation_mode
          == HyperparameterValidationMode.VALIDATE_ALGORITHM
      ):
          for hyperparam in hyperparameters_specs:
              if hyperparam.scope == VariableScope.ALGORITHM:
                  if hyperparam.name not in hyperparameters:
                      raise JumpStartHyperparametersError(
                          f"Cannot find algorithm hyperparameter for '{hyperparam.name}'."
                      )
                  _validate_hyperparameter(
                      hyperparam.name,
                      hyperparameters[hyperparam.name],
                      hyperparameters_specs,
                  )
  
      elif validation_mode == HyperparameterValidationMode.VALIDATE_ALL:
          for hyperparam in hyperparameters_specs:
              if hyperparam.name not in hyperparameters:
                  raise JumpStartHyperparametersError(
                      f"Cannot find hyperparameter for '{hyperparam.name}'."
                  )
              _validate_hyperparameter(
                  hyperparam.name,
                  hyperparameters[hyperparam.name],
                  hyperparameters_specs,
              )
  
      else:
          raise NotImplementedError(
              f"Unable to handle validation for the mode '{validation_mode.value}'."
          )
  
file_path: sagemaker-python-sdk/src/sagemaker/jumpstart/validators.py
imports: from __future__ import absolute_import
  from typing import Any, Dict, List, Optional
  from sagemaker import session
  from sagemaker.jumpstart.constants import JUMPSTART_DEFAULT_REGION_NAME
  from sagemaker.jumpstart.enums import HyperparameterValidationMode, JumpStartScriptScope, VariableScope, VariableTypes
  from sagemaker.jumpstart.exceptions import JumpStartHyperparametersError
  from sagemaker.jumpstart.types import JumpStartHyperparameter
  from sagemaker.jumpstart.utils import verify_model_region_and_return_specs
label_desc: Use image node_id 2 for calling a global function with example usage: validate_hyperparameters(model_id, model_version, hyperparameters, validation_mode, region, sagemaker_session, tolerate_vulnerable_model, tolerate_deprecated_model) without return types