code: def warn_if_infinite_kl_divergence(
      policy: Type["TFPolicy"], mean_kl: TensorType
  ) -> None:
      def print_warning():
          logger.warning(
              "KL divergence is non-finite, this will likely destabilize your model and"
              " the training process. Action(s) in a specific state have near-zero"
              " probability. This can happen naturally in deterministic environments"
              " where the optimal policy has zero mass for a specific action. To fix this"
              " issue, consider setting the coefficient for the KL loss term to zero or"
              " increasing policy entropy."
          )
          return tf.constant(0.0)
  
      if policy.loss_initialized():
          tf.cond(
              tf.math.is_inf(mean_kl),
              false_fn=lambda: tf.constant(0.0),
              true_fn=lambda: print_warning(),
          )
  
imports: import logging
  from typing import Any, Callable, List, Optional, Type, TYPE_CHECKING, Union
  import gymnasium
  import numpy
  import tree
  from gymnasium.spaces import Discrete, MultiDiscrete
  from ray.rllib.utils.annotations import PublicAPI, DeveloperAPI
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space
  from ray.rllib.utils.typing import LocalOptimizer, ModelGradients, PartialAlgorithmConfigDict, SpaceStruct, TensorStructType, TensorType
label_desc: Use image node_id 18 for calling a global function with example usage: warn_if_infinite_kl_divergence(policy, mean_kl) and returns: tf