code: def get_encoder_reference_points(
      spatial_shapes: Sequence[Tuple[int, int]],
      valid_ratios: jnp.ndarray,
      dtype=jnp.float32,
  ) -> jnp.ndarray:
      """Return grid of 2D reference points within valid range by feature level.
  
      Args:
        spatial_shapes: [h, w] for each feature map level.
        valid_ratios: [bs, num_levels, 2] fraction of non-pad pixels in x and y.
        dtype: The dtype of the computation.
  
      Returns:
        [bs, len_v, num_levels, 2] of reference point positions in range [0, 1],
          where len_v is the sum of all feature map areas.
      """
      reference_points_list = []
      for lvl, (h, w) in enumerate(spatial_shapes):
          ref_y, ref_x = jnp.meshgrid(
              jnp.linspace(0.5, h - 0.5, h, dtype=dtype),
              jnp.linspace(0.5, w - 0.5, w, dtype=dtype),
          )
          ref_y, ref_x = ref_y.T, ref_x.T
          ref_y = ref_y.reshape(-1)[None] / (
              valid_ratios[:, None, lvl, 1] * h
          )
          ref_x = ref_x.reshape(-1)[None] / (
              valid_ratios[:, None, lvl, 0] * w
          )
          ref = jnp.stack((ref_x, ref_y), -1)
          reference_points_list.append(ref)
      reference_points = jnp.concatenate(reference_points_list, 1)
      # TODO(tonysherbondy): The reference implementation does this multiplication
      # of the valid_ratios again, which basically removes normalizing by
      # valid_ratios in the loop. It should be equivalent to just normalizing by h
      # and w, but for some reason it does not reproduce the results if we do that.
      reference_points = (
          reference_points[:, :, None] * valid_ratios[:, None]
      )
      return reference_points
  
imports: import functools
  from typing import Sequence, Tuple
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.projects.baselines.deformable_detr.attention import MultiScaleDeformableAttention
  from scenic.projects.baselines.detr.model import MultiHeadDotProductAttention
label_desc: Use image node_id 5 for calling a global function with example usage: get_encoder_reference_points(spatial_shapes, valid_ratios, dtype) and returns: reference_points