code: def run_train_and_test(
      env: TrainEnv, forecaster_type: Type[Union[Estimator, Predictor]]
  ) -> None:
      log_version(forecaster_type)
  
      logger.info(
          "Using the following data channels: %s",
          ", ".join(env.datasets),
      )
  
      forecaster = forecaster_type.from_inputs(
          env.datasets["train"], **env.hyperparameters
      )
      logger.info(
          "The forecaster can be reconstructed with the following expression: "
          f"{forecaster}"
      )
  
      if isinstance(forecaster, Predictor):
          predictor = forecaster
      else:
          predictor = run_train(
              forecaster=forecaster,
              train_dataset=env.datasets["train"],
              validation_dataset=env.datasets.get("validation"),
              hyperparameters=env.hyperparameters,
              from_predictor=env.datasets.get("model"),
          )
  
      predictor.serialize(env.path.model)
  
      if "test" in env.datasets:
          run_test(
              env, predictor, env.datasets["test"], env.hyperparameters
          )
  
file_path: gluonts/src/gluonts/shell/train.py
imports: import json
  import logging
  from typing import Any, Optional, Type, Union
  import gluonts
  from gluonts.core import fqname_for
  from gluonts.dataset.common import Dataset
  from gluonts.evaluation import Evaluator, backtest
  from gluonts.model.estimator import Estimator, IncrementallyTrainable
  from gluonts.model.forecast import Quantile
  from gluonts.model.predictor import Predictor
  from gluonts.itertools import maybe_len
  from gluonts.transform import FilterTransformation
  from .env import TrainEnv
  from .util import invoke_with
label_desc: Use image node_id 3 for calling a global function with example usage: run_train_and_test(env, forecaster_type) without return types