code: def init_text_posemb(
      to_posemb: jnp.ndarray,
      from_posemb: jnp.ndarray,
  ) -> jnp.ndarray:
      """Clips or pads positional embeddings.
  
      This function is used to adjust positional embeddings for text encoders when
      the current model has a different sequence length from the pretrained model.
      When the current model uses a shorter sequence length, we clip the restored
      positional embeddings to match the new length. When the current model uses a
      longer sequence, we copy the first N values from the restored embeddings where
      N is the length of restored positional embeddings.
  
      Note that interpolation is another possibility here.
  
      Args:
        to_posemb: The current positional embedding.
        from_posemb: The positional embedding from the pretrained model.
  
      Returns:
        The adjusted positional embedding.
      """
      to_seq_len = to_posemb.shape[0]
      from_seq_len = from_posemb.shape[0]
      if to_seq_len < from_seq_len:
          logging.info(
              "Clip positional embedding to be a length of %s",
              to_seq_len,
          )
          return from_posemb[:to_seq_len, :]
      elif to_seq_len > from_seq_len:
          logging.warning(
              "The current sequence length is longer than the restored model. Only "
              "the first %s elements are initialized.",
              from_seq_len,
          )
          return jnp.concatenate(
              [from_posemb, to_posemb[from_seq_len:, :]], axis=0
          )
      else:
          return from_posemb
  
imports: from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
  from absl import logging
  import flax
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.projects.vivit import model_utils
  from scenic.train_lib import train_utils
label_desc: Use image node_id 8 for calling a global function with example usage: init_text_posemb(to_posemb, from_posemb) and returns: from_posemb, jnp, from_posemb