code: def _validate_and_normalize_config(
      dataset_configs: ml_collections.ConfigDict, train: bool = False
  ) -> ml_collections.ConfigDict:
      """Validates dataset_configs and normalizes it to a common format.
  
      Common and train/eval-mode-specific configs are merged into one.
      TFDS data dirs are added to the config.
  
      Args:
        dataset_configs: Dataset configuration as specified in the config file.
        train: Flag to switch between train and eval mode.
  
      Returns:
        Normalized config with merged common and mode-specific settings.
      """
      # Create a merged config for this mode (i.e. train or test):
      mode_config = (
          dataset_configs.train if train else dataset_configs.eval
      )
      config = ml_collections.ConfigDict(
          {**dataset_configs, **mode_config}
      )
  
      # Validate config structure:
      decoder_kwarg_list = config.get(
          "decoder_kwarg_list", [{}] * len(config.tfds_names)
      )
      if not (
          len(config.tfds_names)
          == len(config.splits)
          == len(config.dataset_probs)
          == len(decoder_kwarg_list)
      ):
          raise ValueError(
              "Dataset settings must have matching lengths, got "
              f"{config.tfds_names}, {config.splits}, {config.dataset_probs}, "
              f"{decoder_kwarg_list}."
          )
  
      mosaic_sizes = config.get("mosaic_sizes", (1,))
      mosaic_probs = config.get("mosaic_probs", (1.0,))
      if len(mosaic_sizes) != len(mosaic_probs):
          raise ValueError(
              "mosaic_sizes and mosaic_probs must have matching lengths, got "
              f"{mosaic_sizes}, {mosaic_probs}."
          )
  
      # Determine data_dirs:
      data_dirs = {}
      for tfds_name, kws in zip(config.tfds_names, decoder_kwarg_list):
          # First look for data dir in decoder_kwargs, otherwise use None:
          data_dirs[tfds_name] = kws.get("tfds_data_dir")
      config.data_dirs = (
          data_dirs,
      )  # Wrap tuple avoids ConfigDict conversion.
  
      return config
  
imports: import dataclasses
  import functools
  from typing import Any, Dict, Optional, Sequence
  from clu import deterministic_data
  from clu import preprocess_spec
  from flax import jax_utils
  import jax
  import jax.numpy
  import ml_collections
  from scenic.dataset_lib import dataset_utils
  from scenic.dataset_lib import datasets
  from scenic.projects.owl_vit.preprocessing import image_ops
  from scenic.projects.owl_vit.preprocessing import label_ops
  from scenic.projects.owl_vit.preprocessing import mosaic
  import tensorflow
  import tensorflow_datasets
label_desc: Use image node_id 6 for calling a global function with example usage: _validate_and_normalize_config(dataset_configs, train) and returns: config