code: def init_posemb(
      to_params,
      from_params,
      config,
      restored_model_cfg,
      is_temporal,
      posemb_name="posembed_input",
      restored_posemb_name="posembed_input",
  ):
      """Initialize the positional embeddings."""
      if config.init_from.get("restore_positional_embedding", True):
          posemb = to_params[posemb_name]["pos_embedding"]
          restored_posemb = from_params[restored_posemb_name][
              "pos_embedding"
          ]
          if restored_posemb.shape != posemb.shape:
              # Rescale the grid of pos, embeddings.
              # Default parameter shape is (1, N, 768)
              logging.info(
                  "Adapting positional embeddings from %s to %s",
                  restored_posemb.shape,
                  posemb.shape,
              )
              ntok = posemb.shape[1]
              if restored_model_cfg.model.classifier == "token":
                  # The first token is the CLS token.
                  restored_posemb_grid = restored_posemb[0, 1:]
                  if config.model.classifier == "token":
                      # CLS token in restored model and in target.
                      cls_tok = restored_posemb[:, :1]
                      ntok -= 1
                  else:
                      # CLS token in restored model, but not target.
                      cls_tok = restored_posemb[:, :0]
              else:
                  restored_posemb_grid = restored_posemb[0]
                  if config.model.classifier == "token":
                      # CLS token in target, but not restored model.
                      cls_tok = posemb[:, :1]
                      ntok -= 1
                  else:
                      # CLS token not in target or restored model.
                      cls_tok = restored_posemb[:, :0]
              if (config.model.classifier == "token") != (
                  restored_model_cfg.model.classifier == "token"
              ):
                  logging.warning(
                      "Only one of target and restored model uses a "
                      "classification token."
                  )
  
              if (
                  len(restored_posemb_grid) != ntok
              ):  # We need a resolution change.
                  if is_temporal:
                      restored_posemb_grid = (
                          interpolate_1d_positional_embeddings(
                              restored_posemb_grid, ntok
                          )
                      )
  
                  elif (
                      config.init_from.positional_embed_size_change
                      == "resize"
                  ):
                      restored_posemb_grid = (
                          interpolate_positional_embeddings(
                              restored_posemb_grid, ntok
                          )
                      )
  
                  elif (
                      config.init_from.positional_embed_size_change
                      == "tile"
                  ):
                      restored_posemb_grid = tile_positional_embeddings(
                          restored_posemb_grid, ntok
                      )
  
                  elif (
                      config.init_from.positional_embed_size_change
                      == "resize_tile"
                  ):
                      temp_encoding = (
                          config.model.temporal_encoding_config
                      )
                      if temp_encoding.method == "temporal_sampling":
                          tokens_per_frame = int(
                              ntok / temp_encoding.n_sampled_frames
                          )
                      elif temp_encoding.method == "3d_conv":
                          n_frames = (
                              config.dataset_configs.num_frames
                              // config.model.patches.size[2]
                          )
                          tokens_per_frame = ntok // n_frames
                      else:
                          raise AssertionError(
                              f"Unknown temporal encoding {temp_encoding.method}"
                          )
                      restored_posemb_grid = (
                          interpolate_positional_embeddings(
                              restored_posemb_grid, tokens_per_frame
                          )
                      )
                      restored_posemb_grid = restored_posemb_grid[0]
                      restored_posemb_grid = tile_positional_embeddings(
                          restored_posemb_grid, ntok
                      )
  
                  else:
                      raise AssertionError(
                          "Unknown positional embedding size changing method"
                      )
              else:  # Sequence lengths are the same.
                  # Adds batch dimension.
                  restored_posemb_grid = restored_posemb_grid[None, ...]
  
              # Attach the CLS token again.
              if config.model.classifier == "token":
                  restored_posemb = jnp.array(
                      np.concatenate(
                          [cls_tok, restored_posemb_grid], axis=1
                      )
                  )
              else:
                  restored_posemb = restored_posemb_grid
  
          to_params[posemb_name]["pos_embedding"] = restored_posemb
      else:
          logging.info(
              "Not restoring positional encodings from pretrained model"
          )
  
imports: from typing import Any, Optional, Tuple
  from absl import logging
  import flax
  from flax.linen import linear
  from flax.training import common_utils
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.model_lib.base_models import model_utils
  import scipy
label_desc: Use image node_id 10 for calling a global function with example usage: init_posemb(to_params, from_params, config, restored_model_cfg, is_temporal, posemb_name, restored_posemb_name) without return types