code: def init_encoder(
      encoder: ImageTextEncoder,
      input_spec: Sequence[tuple[tuple[int, ...], Any]],
      config: ml_collections.ConfigDict,
      rng: Optional[jnp.ndarray] = None,
      method: Optional[
          Callable[..., Any]
      ] = None,  # pylint: disable=unused-argument
      strict_for_missing: bool = False,
      strict_for_unexpected: bool = True,
  ) -> tuple[FrozenDict, FrozenDict]:
      """Creates an instance of the given model class and the train state."""
      rng = jax.random.PRNGKey(0) if rng is None else rng
  
      params, model_state, _, _ = train_utils.initialize_model(
          model_def=encoder,
          input_spec=input_spec,
          # method=method,
          config=config,
          rngs=rng,
      )
  
      if config.model.get("load_pretrained_vars"):
          logging.info("Loading the pretrained model…")
          (
              pretrained_params,
              pretrained_model_state,
          ) = encoder.get_pretrained_vars()
          logging.info("Pretrained model loaded.")
  
          msgs = []
  
          (
              params,
              missing_param_keys,
              unexpected_param_keys,
          ) = _recursively_merge_frozen_dicts(params, pretrained_params)
  
          if missing_param_keys:
              msgs.append(
                  f"Missing params in the pretrained model: {missing_param_keys}"
              )
  
          if unexpected_param_keys:
              msgs.append(
                  "Unexpected params in the pretrained model:"
                  f" {unexpected_param_keys}"
              )
  
          (
              model_state,
              missing_model_state_keys,
              unexpected_model_state_keys,
          ) = _recursively_merge_frozen_dicts(
              model_state, pretrained_model_state
          )
  
          if missing_model_state_keys:
              msgs.append(
                  "Missing model state keys in the pretrained model:"
                  f" {missing_model_state_keys}"
              )
  
          if unexpected_model_state_keys:
              msgs.append(
                  "Unexpected model state keys in the pretrained model:"
                  f" {unexpected_model_state_keys}"
              )
  
          if msgs:
              if strict_for_missing and (
                  missing_param_keys or missing_model_state_keys
              ):
                  raise RuntimeError(
                      "Error loading the pretrained model:\n"
                      + "\n\t".join(msgs)
                  )
              elif strict_for_unexpected and (
                  unexpected_param_keys or unexpected_model_state_keys
              ):
                  raise RuntimeError(
                      "Error loading the pretrained model:\n"
                      + "\n\t".join(msgs)
                  )
              else:
                  for msg in msgs:
                      logging.warning(msg)
  
      logging.info(
          "Params dtype counts: %s",
          collections.Counter(
              t.dtype
              for t in traverse_util.flatten_dict(params).values()
          ),
      )
  
      logging.info("Encoder: %s", encoder)
  
      return params, model_state
  
imports: import collections
  from collections.abc import Callable
  from collections.abc import Iterable
  from collections.abc import Mapping
  import functools
  from typing import Any
  from typing import Hashable
  from typing import Literal
  from typing import Optional
  from typing import Sequence
  from typing import TypeVar
  from typing import Union
  from absl import logging
  from clu import metric_writers
  import flax
  from flax import jax_utils
  from flax import traverse_util
  from flax.core.frozen_dict import FrozenDict
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.dataset_lib import dataset_utils
  from scenic.projects.lang4video import util
  from scenic.projects.lang4video.model.base_encoders import ImageTextEncoder
  from scenic.train_lib import train_utils
label_desc: Use image node_id 2 for calling a global function with example usage: init_encoder(encoder, input_spec, config, rng, method, strict_for_missing, strict_for_unexpected) and returns: params,  model_state