code: def run_app_in_certain_mode(
      cfg: TrainAppConf, mode: str, env: str = "oss"
  ) -> TrainOutput:
      os.environ["PTV_TRAINER_ENV"] = env
  
      rank_zero_info(OmegaConf.to_yaml(cfg))
  
      # TODO: Move this to config and replace with `seed_everything`
      np.random.seed(0)
      torch.manual_seed(0)
      app = hydra.utils.instantiate(cfg, _recursive_=False)
  
      if mode == "train":
          rank_zero_info("MODE set to train, run train only.")
          return app.train()
      elif mode == "test":
          rank_zero_info("MODE set to test, run test only.")
          return app.test()
      elif mode == "predict":
          rank_zero_info("MODE set to predict, run train and predict.")
          app.train()
          return app.predict()
      else:
          # By default, run train and test
          app.train()
          return app.test()
  
imports: import os
  from dataclasses import dataclass, field
  from typing import Any, Dict, List, Optional, Union
  import hydra
  import numpy
  import submitit
  import torch
  from hydra.core.config_store import ConfigStore
  from omegaconf import MISSING, OmegaConf
  from omegaconf.dictconfig import DictConfig
  from pytorch_lightning import LightningDataModule, LightningModule
  from pytorch_lightning.callbacks import Callback, LearningRateMonitor
  from pytorch_lightning.loggers import TensorBoardLogger
  from pytorch_lightning.utilities import rank_zero_info, rank_zero_only
  from pytorchvideo_trainer.datamodule.datamodule import VideoClassificationDataModuleConf
  from pytorchvideo_trainer.module.video_classification import VideoClassificationModuleConf
  from torchrecipes.core.base_train_app import BaseTrainApp, TrainOutput
  from torchrecipes.core.conf import TrainAppConf, TrainerConf
  from torchrecipes.utils.config_utils import get_class_name_str
label_desc: Use image node_id 1 for calling a global function with example usage: run_app_in_certain_mode(cfg, mode, env) and returns: app, app, app, app