code: def build_q_model(
      policy: Policy,
      obs_space: gym.spaces.Space,
      action_space: gym.spaces.Space,
      config: AlgorithmConfigDict,
  ) -> ModelV2:
      """Build q_model and target_model for DQN
  
      Args:
          policy: The Policy, which will use the model for optimization.
          obs_space (gym.spaces.Space): The policy's observation space.
          action_space (gym.spaces.Space): The policy's action space.
          config (AlgorithmConfigDict):
  
      Returns:
          ModelV2: The Model for the Policy to use.
              Note: The target q model will not be returned, just assigned to
              `policy.target_model`.
      """
      if not isinstance(action_space, gym.spaces.Discrete):
          raise UnsupportedSpaceException(
              "Action space {} is not supported for DQN.".format(
                  action_space
              )
          )
  
      if config["hiddens"]:
          # try to infer the last layer size, otherwise fall back to 256
          num_outputs = (
              [256] + list(config["model"]["fcnet_hiddens"])
          )[-1]
          config["model"]["no_final_linear"] = True
      else:
          num_outputs = action_space.n
  
      q_model = ModelCatalog.get_model_v2(
          obs_space=obs_space,
          action_space=action_space,
          num_outputs=num_outputs,
          model_config=config["model"],
          framework="tf",
          model_interface=DistributionalQTFModel,
          name=Q_SCOPE,
          num_atoms=config["num_atoms"],
          dueling=config["dueling"],
          q_hiddens=config["hiddens"],
          use_noisy=config["noisy"],
          v_min=config["v_min"],
          v_max=config["v_max"],
          sigma0=config["sigma0"],
          # TODO(sven): Move option to add LayerNorm after each Dense
          #  generically into ModelCatalog.
          add_layer_norm=isinstance(
              getattr(policy, "exploration", None), ParameterNoise
          )
          or config["exploration_config"]["type"] == "ParameterNoise",
      )
  
      policy.target_model = ModelCatalog.get_model_v2(
          obs_space=obs_space,
          action_space=action_space,
          num_outputs=num_outputs,
          model_config=config["model"],
          framework="tf",
          model_interface=DistributionalQTFModel,
          name=Q_TARGET_SCOPE,
          num_atoms=config["num_atoms"],
          dueling=config["dueling"],
          q_hiddens=config["hiddens"],
          use_noisy=config["noisy"],
          v_min=config["v_min"],
          v_max=config["v_max"],
          sigma0=config["sigma0"],
          # TODO(sven): Move option to add LayerNorm after each Dense
          #  generically into ModelCatalog.
          add_layer_norm=isinstance(
              getattr(policy, "exploration", None), ParameterNoise
          )
          or config["exploration_config"]["type"] == "ParameterNoise",
      )
  
      return q_model
  
imports: from typing import Dict
  import gymnasium
  import numpy
  import ray
  from ray.rllib.algorithms.dqn.distributional_q_tf_model import DistributionalQTFModel
  from ray.rllib.algorithms.simple_q.utils import Q_SCOPE, Q_TARGET_SCOPE
  from ray.rllib.evaluation.postprocessing import adjust_nstep
  from ray.rllib.models import ModelCatalog
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.tf.tf_action_dist import get_categorical_class_with_temperature
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.tf_mixins import LearningRateSchedule, TargetNetworkMixin
  from ray.rllib.policy.tf_policy_template import build_tf_policy
  from ray.rllib.utils.error import UnsupportedSpaceException
  from ray.rllib.utils.exploration import ParameterNoise
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.tf_utils import huber_loss, l2_loss, make_tf_callable, minimize_and_clip, reduce_mean_ignore_inf
  from ray.rllib.utils.typing import AlgorithmConfigDict, ModelGradients, TensorType
label_desc: Use image node_id 1 for calling a global function with example usage: build_q_model(policy, obs_space, action_space, config) and returns: q_model