class_docstr: A TFPolicy that auto-defines placeholders dynamically at runtime.
  
  This class is intended to be used and extended by sub-classing.
code: def __init__(
      self,
      obs_space: gym.spaces.Space,
      action_space: gym.spaces.Space,
      config: AlgorithmConfigDict,
      *,
      existing_inputs: Optional[Dict[str, "tf1.placeholder"]] = None,
      existing_model: Optional[ModelV2] = None,
  ):
      self.observation_space = obs_space
      self.action_space = action_space
      self.config = config
      self.framework = "tf"
      self._seq_lens = None
      self._is_tower = existing_inputs is not None
  
      self.validate_spaces(obs_space, action_space, config)
  
      self.dist_class = self._init_dist_class()
      # Setup self.model.
      if existing_model and isinstance(existing_model, list):
          self.model = existing_model[0]
          # TODO: (sven) hack, but works for `target_[q_]?model`.
          for i in range(1, len(existing_model)):
              setattr(self, existing_model[i][0], existing_model[i][1])
      else:
          self.model = self.make_model()
      # Auto-update model's inference view requirements, if recurrent.
      self._update_model_view_requirements_from_init_state()
  
      self._init_state_inputs(existing_inputs)
      self._init_view_requirements()
      timestep, explore = self._init_input_dict_and_dummy_batch(
          existing_inputs
      )
      (
          sampled_action,
          sampled_action_logp,
          dist_inputs,
          self._policy_extra_action_fetches,
      ) = self._init_action_fetches(timestep, explore)
  
      # Phase 1 init.
      sess = tf1.get_default_session() or tf1.Session(
          config=tf1.ConfigProto(**self.config["tf_session_args"])
      )
  
      batch_divisibility_req = self.get_batch_divisibility_req()
  
      prev_action_input = (
          self._input_dict[SampleBatch.PREV_ACTIONS]
          if SampleBatch.PREV_ACTIONS in self._input_dict.accessed_keys
          else None
      )
      prev_reward_input = (
          self._input_dict[SampleBatch.PREV_REWARDS]
          if SampleBatch.PREV_REWARDS in self._input_dict.accessed_keys
          else None
      )
  
      super().__init__(
          observation_space=obs_space,
          action_space=action_space,
          config=config,
          sess=sess,
          obs_input=self._input_dict[SampleBatch.OBS],
          action_input=self._input_dict[SampleBatch.ACTIONS],
          sampled_action=sampled_action,
          sampled_action_logp=sampled_action_logp,
          dist_inputs=dist_inputs,
          dist_class=self.dist_class,
          loss=None,  # dynamically initialized on run
          loss_inputs=[],
          model=self.model,
          state_inputs=self._state_inputs,
          state_outputs=self._state_out,
          prev_action_input=prev_action_input,
          prev_reward_input=prev_reward_input,
          seq_lens=self._seq_lens,
          max_seq_len=config["model"].get("max_seq_len", 20),
          batch_divisibility_req=batch_divisibility_req,
          explore=explore,
          timestep=timestep,
      )
  
imports: from collections import OrderedDict
  import gymnasium
  import logging
  import re
  import tree
  from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type, Union
  from ray.rllib.models.catalog import ModelCatalog
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.tf.tf_action_dist import TFActionDistribution
  from ray.rllib.policy.dynamic_tf_policy import TFMultiGPUTowerStack
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.tf_policy import TFPolicy
  from ray.rllib.policy.view_requirement import ViewRequirement
  from ray.rllib.utils import force_list
  from ray.rllib.utils.annotations import DeveloperAPI, OverrideToImplementCustomLogic, OverrideToImplementCustomLogic_CallToSuperRecommended, is_overridden, override
  from ray.rllib.utils.debug import summarize
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.metrics import DIFF_NUM_GRAD_UPDATES_VS_SAMPLER_POLICY, NUM_GRAD_UPDATES_LIFETIME
  from ray.rllib.utils.metrics.learner_info import LEARNER_STATS_KEY
  from ray.rllib.utils.spaces.space_utils import get_dummy_batch_for_space
  from ray.rllib.utils.tf_utils import get_placeholder
  from ray.rllib.utils.typing import AlgorithmConfigDict, LocalOptimizer, ModelGradients, TensorType
  from ray.util.debug import log_once
label_desc: Use image node_id 1 to create a new DynamicTFPolicyV2 object from inherited base classes: TFPolicy with example: obj = DynamicTFPolicyV2(obs_space, action_space, config)