code: def main(cfg):
      if hasattr(cfg.model.optim, "sched"):
          logging.warning(
              "You are using an optimizer scheduler while finetuning. Are you sure this is intended?"
          )
      if cfg.model.optim.lr > 1e-3 or cfg.model.optim.lr < 1e-5:
          logging.warning(
              "The recommended learning rate for finetuning is 2e-4"
          )
  
      trainer = pl.Trainer(**cfg.trainer)
      exp_log_dir = exp_manager(trainer, cfg.get("exp_manager", None))
      # Initialize FastPitchModel
      model = FastPitchModel(
          cfg=update_model_config_to_support_adapter(cfg.model),
          trainer=trainer,
      )
      model.maybe_init_from_pretrained_checkpoint(cfg=cfg)
  
      # Extract adapter parameters
      with open_dict(cfg.model.adapter):
          # Extract the name of the adapter (must be given for training)
          adapter_name = cfg.model.adapter.pop(
              "adapter_name", "adapter"
          )
          # Extract the name of the modules where adapters need to be added (must be given for training)
          adapter_module_name = cfg.model.adapter.pop(
              "adapter_module_name", None
          )
          # Name of the adapter checkpoint which will be saved after training
          adapter_state_dict_name = cfg.model.adapter.pop(
              "adapter_state_dict_name", None
          )
  
          # augment adapter name with module name, if not provided by user
          if (
              adapter_module_name is not None
              and ":" not in adapter_name
          ):
              adapter_name = f"{adapter_module_name}:{adapter_name}"
  
          # Extract the global adapter config, if provided
          adapter_global_cfg = cfg.model.adapter.pop(
              model.adapter_global_cfg_key, None
          )
  
      # Freeze model
      model.freeze()
  
      # Setup adapters
      if adapter_global_cfg is not None:
          add_global_adapter_cfg(model, adapter_global_cfg)
  
      if cfg.model.get("unfreeze_aligner", False):
          for name, param in model.fastpitch.aligner.named_parameters():
              param.requires_grad = True
  
      if cfg.model.get("unfreeze_duration_predictor", False):
          for (
              name,
              param,
          ) in model.fastpitch.duration_predictor.named_parameters():
              param.requires_grad = True
  
      if cfg.model.get("unfreeze_pitch_predictor", False):
          for (
              name,
              param,
          ) in model.fastpitch.pitch_predictor.named_parameters():
              param.requires_grad = True
  
      # Add adapters
      model.add_adapter(name=adapter_name, cfg=cfg.model.adapter)
      assert model.is_adapter_available()
      # enable adapters
      model.set_enabled_adapters(enabled=False)
      model.set_enabled_adapters(adapter_name, enabled=True)
  
      # Set model to training mode.
      model = model.train()
      # Then, Unfreeze just the adapter weights that were enabled above (no part of model)
      model.unfreeze_enabled_adapters()
      # summarize the model
      model.summarize()
  
      lr_logger = pl.callbacks.LearningRateMonitor()
      epoch_time_logger = LogEpochTimeCallback()
      trainer.callbacks.extend([lr_logger, epoch_time_logger])
      trainer.fit(model)
  
      # Save the adapter state dict after training has completed
      if adapter_state_dict_name is not None:
          state_path = (
              exp_log_dir if exp_log_dir is not None else os.getcwd()
          )
          ckpt_path = os.path.join(state_path, "checkpoints")
          if os.path.exists(ckpt_path):
              state_path = ckpt_path
  
          # Save the adapter modules in a seperate file
          model.save_adapters(
              os.path.join(state_path, adapter_state_dict_name)
          )
  
file_path: NeMo/examples/tts/fastpitch_finetune_adapters.py
imports: import os
  from dataclasses import is_dataclass
  import pytorch_lightning
  from omegaconf import DictConfig, OmegaConf, open_dict
  from nemo.collections.common.callbacks import LogEpochTimeCallback
  from nemo.collections.tts.models import FastPitchModel
  from nemo.core import adapter_mixins
  from nemo.core.config import hydra_runner
  from nemo.utils import logging
  from nemo.utils.exp_manager import exp_manager
label_desc: Use image node_id 3 for calling a global function with example usage: main(cfg) without return types