code: def init_posemb(
      to_params,
      from_params,
      init_config,
      model_config,
      dataset_config,
      restored_model_cfg,
      name,
      prefix_path=None,
  ):
      """Initialize the positional embeddings."""
      if name not in to_params:
          logging.info("No %s in target model", name)
      elif init_config.restore_positional_embedding:
          if name == "bottleneck":
              posemb = to_params[name]
          else:
              posemb = to_params[name]["pos_embedding"]
          restored_posemb = from_params["posembed_input"][
              "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 %s from %s to %s",
                  name,
                  restored_posemb.shape,
                  posemb.shape,
              )
              ntok = posemb.shape[1]
              if prefix_path:
                  # MBT is part of a larger model
                  classifier = restored_model_cfg.mbt.model.classifier
              else:
                  classifier = restored_model_cfg.model.classifier
              if classifier == "token":
                  # the first token is the CLS token
                  cls_tok = restored_posemb[:, :1]
                  restored_posemb_grid = restored_posemb[0, 1:]
              else:
                  cls_tok = restored_posemb[:, :0]
                  restored_posemb_grid = restored_posemb[0]
              if model_config.classifier == "token":
                  ntok -= 1
  
              size_change = init_config.positional_embed_size_change
              if name == "bottleneck":
                  restored_posemb_grid = (
                      interpolate_positional_embeddings(
                          restored_posemb_grid, ntok
                      )
                  )
              elif size_change == "tile":
                  restored_posemb_grid = (
                      vivit_utils.tile_positional_embeddings(
                          restored_posemb_grid, ntok
                      )
                  )
              elif size_change in ["resize_tile", "resize"]:
                  temp_encoding = model_config.temporal_encoding_config
                  if name.find("spec") > -1:
                      gh = (
                          dataset_config.spec_shape[0]
                          * dataset_config.num_spec_frames
                      ) // model_config.patches.size[0]
                      gw = (
                          dataset_config.spec_shape[1]
                          // model_config.patches.size[1]
                      )
                      tokens_per_frame = (gh, gw)
                  elif (
                      name.find("wave") > -1 or size_change == "resize"
                  ):
                      tokens_per_frame = ntok
                  elif temp_encoding.method == "temporal_sampling":
                      tokens_per_frame = int(
                          ntok / temp_encoding.n_sampled_frames
                      )
                  elif temp_encoding.method == "3d_conv":
                      # This is for RGB only.
                      n_frames = (
                          dataset_config.num_frames
                          // model_config.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
                      )
                  )
                  if (
                      size_change == "resize_tile"
                      and ntok != tokens_per_frame
                  ):
                      restored_posemb_grid = restored_posemb_grid[0]
                      restored_posemb_grid = (
                          vivit_utils.tile_positional_embeddings(
                              restored_posemb_grid, ntok
                          )
                      )
              else:
                  raise AssertionError(
                      "Unknown positional embedding size changing method"
                  )
              # attach the CLS token again
              if model_config.classifier == "token":
                  restored_posemb = jnp.array(
                      np.concatenate(
                          [cls_tok, restored_posemb_grid], axis=1
                      )
                  )
              else:
                  restored_posemb = restored_posemb_grid
  
          if name == "bottleneck":
              to_params[name] = restored_posemb
          else:
              to_params[name]["pos_embedding"] = restored_posemb
      else:
          logging.info(
              "Not restoring positional encodings from pretrained model"
          )
  
imports: import functools
  import re
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple
  from absl import logging
  import flax
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import classification_model
  from scenic.model_lib.base_models import model_utils
  from scenic.model_lib.base_models.classification_model import ClassificationModel
  from scenic.model_lib.layers import nn_layers
  from scenic.projects.av_mae import model_utils
  from scenic.projects.baselines import vit
  from scenic.projects.mbt import model
  from scenic.projects.vivit import model_utils
  import scipy
label_desc: Use image node_id 11 for calling a global function with example usage: init_posemb(to_params, from_params, init_config, model_config, dataset_config, restored_model_cfg, name, prefix_path) without return types