code: def _get_pre_mosaic_process_fn(
      builder: tfds.core.DatasetBuilder,
      decoder_kwargs: Dict[str, Any],
      spec: str,
      mosaic_size: int = 1,
  ) -> preprocess_spec.PreprocessFn:
      """Constructs the preprocess_fn that should be applied before mosaicing.
  
      Args:
        builder: TFDS dataset builder.
        decoder_kwargs: Decoder kwargs.
        spec: Config string specifying the preprocessing.
        mosaic_size: Number of tiles along each mosaic edge. For no mosaicing, set
          to 1.
  
      Returns:
        PreprocessFns for pre-mosaic processing.
      """
      all_ops = preprocess_spec.get_all_ops(
          "scenic.projects.owl_vit.preprocessing.image_ops"
      )
      all_ops += preprocess_spec.get_all_ops(
          "scenic.projects.owl_vit.preprocessing.label_ops"
      )
      pre_mosaic_fn = preprocess_spec.parse(
          spec, all_ops, only_jax_types=False
      )
  
      # Add decoder:
      tfds_name = f"{builder.name}:{builder.version}"
      decoder_kwargs = decoder_kwargs.copy()
      decoder_name = decoder_kwargs.pop("name", tfds_name)
      if decoder_name not in DECODERS:
          raise ValueError(
              f"Did not find decoder for {decoder_name}. Please specify decoders for "
              "all datasets in DECODERS."
          )
      pre_mosaic_fn.ops = (
          DECODERS[decoder_name](**decoder_kwargs),
          *pre_mosaic_fn.ops,
      )
  
      # Reduce the resize-size of all ops by a factor of `mosaic_size`:
      resize_ops = (image_ops.ResizeWithPad, image_ops.CropOrPad)
      pre_mosaic_ops = []
      for op in pre_mosaic_fn.ops:
          # Validate op:
          if isinstance(op, PRE_MOSAIC_OPS):
              pass  # This is a pre-mosaic op, continue below.
          elif isinstance(op, POST_MOSAIC_OPS):
              continue  # This is a post-mosaic-only op, skip.
          else:
              raise ValueError(
                  f"Op {op!r} not found in PRE_MOSAIC_OPS or POST_MOSAIC_OPS. "
                  "Please add op to either or both lists."
              )
  
          # Adjust resizing ops to mosaic tile size:
          if isinstance(op, resize_ops):
              assert (
                  op.size % mosaic_size == 0
              ), "Size is not evenly divisible!"
              op = dataclasses.replace(op, size=op.size // mosaic_size)
          pre_mosaic_ops.append(op)
      pre_mosaic_fn.ops = pre_mosaic_ops
  
      return pre_mosaic_fn
  
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 1 for calling a global function with example usage: _get_pre_mosaic_process_fn(builder, decoder_kwargs, spec, mosaic_size) and returns: pre_mosaic_fn