class_docstr: Megatron encoder-decoder base class
class_docstr_tok: ["Megatron","encoder-decoder","base","class"]
code: def model_provider_func(
      self, pre_process, post_process, add_encoder, add_decoder
  ):
      if not hasattr(self.cfg, "encoder") or not hasattr(
          self.cfg, "decoder"
      ):
          logging.warning(
              "Could not find encoder or decoder in config. This is probably because of restoring an old checkpoint. Copying shared model configs to encoder and decoder configs."
          )
          # After the call below, self.cfg.encoder and self.cfg.decoder will be populated with the cfg.model configs from old checkpoints.
          self._populate_encoder_decoder_configs_for_backward_compatibility(
              self.cfg
          )
  
      if (
          parallel_state.get_pipeline_model_parallel_world_size() > 1
          and self.cfg.encoder.arch == "perceiver"
      ):
          raise ValueError(
              f"Perceivers with pipeline parallel > 1 is not supported yet."
          )
  
      if not hasattr(self.cfg, "embedding_init_method_std"):
          embedding_init_method_std = self.cfg.encoder.init_method_std
      else:
          embedding_init_method_std = self.cfg.embedding_init_method_std
  
      if not hasattr(self.cfg, "embedding_dropout"):
          embedding_dropout = self.cfg.encoder.hidden_dropout
      else:
          embedding_dropout = self.cfg.embedding_dropout
  
      model = MegatronTokenLevelEncoderDecoderModule(
          config=self.model_parallel_config,
          encoder_cfg=self.cfg.encoder,
          decoder_cfg=self.cfg.decoder,
          vocab_size=self.padded_vocab_size,
          max_position_embeddings=self.cfg.max_position_embeddings,
          num_tokentypes=0,
          parallel_output=True,
          pre_process=pre_process,
          post_process=post_process,
          fp16_cross_entropy=self.cfg.get(
              "fp16_lm_cross_entropy", False
          ),
          precision=self.cfg.get("precision", 16),
          embedding_init_method_std=embedding_init_method_std,
          embedding_dropout=embedding_dropout,
          label_smoothing=self.cfg.get("label_smoothing", 0.0),
          add_encoder=add_encoder,
          add_decoder=add_decoder,
          share_token_embeddings=self.cfg.get(
              "share_token_embeddings", True
          ),
          share_decoder_tokens_head_embeddings=self.cfg.get(
              "share_decoder_tokens_head_embeddings", True
          ),
          tokens_head_bias=self.cfg.get("tokens_head_bias", True),
          hiddens_cfg=self.cfg.get("hiddens", None),
      )
      return model
  
imports: import copy
  import functools
  import inspect
  from typing import Any, Dict, List, Optional
  import torch
  from omegaconf import OmegaConf, open_dict
  from omegaconf.dictconfig import DictConfig
  from pytorch_lightning.accelerators import CPUAccelerator
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingRandomSampler, MegatronPretrainingSampler
  from nemo.collections.nlp.models.language_modeling.megatron_base_model import MegatronBaseModel
  from nemo.collections.nlp.modules.common.megatron.build_model import build_model
  from nemo.collections.nlp.modules.common.megatron.module import Float16Module
  from nemo.collections.nlp.modules.common.megatron.token_level_encoder_decoder import MegatronTokenLevelEncoderDecoderModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults, average_losses_across_data_parallel_group, get_params_for_weight_decay_optimization
  from nemo.collections.nlp.modules.common.text_generation_utils import compute_beam_search_len_penalty, get_sampling_token_fn
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.utils import AppState, logging
label_desc: Use image node_id 6 for calling the MegatronLMEncoderDecoderModel obj's underlying member method code with example usage: obj.model_provider_func(pre_process, post_process, add_encoder, add_decoder) and returns: model