class_docstr: Megatron encoder-decoder base class
class_docstr_tok: ["Megatron","encoder-decoder","base","class"]
docstr: Populate encoder and decoder configs for backward compatibility with a checkpoint that has a common enc/dec config.
docstr_tok: ["Populate","encoder","and","decoder","configs","for","backward","compatibility","with","a","checkpoint","that","has","a","common","enc\/dec","config","."]
code: def _populate_encoder_decoder_configs_for_backward_compatibility(
      self, cfg
  ):
      """
      Populate encoder and decoder configs for backward compatibility with a checkpoint that has a common enc/dec config.
      """
      # TODO: This will not remove redundant args that are already present in the new yaml file's config.model
      encoder_cfg = copy.deepcopy(cfg)
      decoder_cfg = copy.deepcopy(cfg)
  
      OmegaConf.set_struct(encoder_cfg, True)
      OmegaConf.set_struct(decoder_cfg, True)
      OmegaConf.set_struct(cfg, True)
  
      with open_dict(encoder_cfg), open_dict(decoder_cfg), open_dict(
          cfg
      ):
          encoder_cfg.arch = cfg.get("encoder_arch", "transformer")
          decoder_cfg.arch = cfg.get("decoder_arch", "transformer")
  
          self._handle_bias_activation_fusion_args(encoder_cfg)
          self._handle_bias_activation_fusion_args(decoder_cfg)
  
          cfg.encoder = encoder_cfg
          cfg.decoder = decoder_cfg
  
          # NOTE: For old models there are two scenarios:
          # 1. If we share decoder embeddings with the output layer, we would always set tokens_head_bias=True
          # 2. If we do not share decoder embeddings with the output layer, we would always set tokens_head_bias=False
          cfg.tokens_head_bias = (
              True
              if cfg.get("share_decoder_tokens_head_embeddings", True)
              else False
          )
  
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 5 for calling the MegatronLMEncoderDecoderModel obj's underlying member method code with example usage: obj._populate_encoder_decoder_configs_for_backward_compatibility(cfg) without return types