code: def run_train(
      forecaster: Estimator,
      train_dataset: Dataset,
      hyperparameters: dict,
      validation_dataset: Optional[Dataset],
      from_predictor: Optional[Predictor],
  ) -> Predictor:
      num_workers = (
          int(hyperparameters["num_workers"])
          if "num_workers" in hyperparameters
          else None
      )
      shuffle_buffer_length = (
          int(hyperparameters["shuffle_buffer_length"])
          if "shuffle_buffer_length" in hyperparameters
          else None
      )
      num_prefetch = (
          int(hyperparameters["num_prefetch"])
          if "num_prefetch" in hyperparameters
          else None
      )
  
      if from_predictor is not None:
          assert isinstance(forecaster, IncrementallyTrainable), (
              "The model provided does not implement the "
              "IncrementallyTrainable protocol"
          )
          return invoke_with(
              forecaster.train_from,
              from_predictor,
              training_data=train_dataset,
              validation_data=validation_dataset,
              num_workers=num_workers,
              num_prefetch=num_prefetch,
              shuffle_buffer_length=shuffle_buffer_length,
          )
  
      return invoke_with(
          forecaster.train,
          training_data=train_dataset,
          validation_data=validation_dataset,
          num_workers=num_workers,
          num_prefetch=num_prefetch,
          shuffle_buffer_length=shuffle_buffer_length,
      )
  
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 4 for calling a global function with example usage: run_train(forecaster, train_dataset, hyperparameters, validation_dataset, from_predictor) and returns: invoke_with, invoke_with