code: def train(arguments):
      """
      Generic train method that trains a specified estimator on a specified
      dataset.
      """
  
      logger.info("Downloading estimator config.")
      estimator_config = Path(arguments.estimator) / "estimator.json"
      with estimator_config.open() as config_file:
          estimator = serde.load_json(config_file.read())
  
      logger.info("Downloading dataset.")
      if arguments.s3_dataset is None:
          # load built in dataset
          dataset = datasets.get_dataset(arguments.dataset)
      else:
          # load custom dataset
          s3_dataset_dir = Path(arguments.s3_dataset)
          dataset = common.load_datasets(
              metadata=s3_dataset_dir,
              train=s3_dataset_dir / "train",
              test=s3_dataset_dir / "test",
          )
  
      logger.info("Starting model training.")
      predictor = estimator.train(dataset.train)
      forecast_it, ts_it = backtest.make_evaluation_predictions(
          dataset=dataset.test,
          predictor=predictor,
          num_samples=int(arguments.num_samples),
      )
  
      logger.info("Starting model evaluation.")
      evaluator = Evaluator(quantiles=eval(arguments.quantiles))
  
      agg_metrics, item_metrics = evaluator(
          ts_it, forecast_it, num_series=len(list(dataset.test))
      )
  
      # required for metric tracking.
      for name, value in agg_metrics.items():
          logger.info(f"gluonts[metric-{name}]: {value}")
  
      # save the evaluation results
      metrics_output_dir = Path(arguments.output_data_dir)
      with open(metrics_output_dir / "agg_metrics.json", "w") as f:
          json.dump(agg_metrics, f)
      with open(metrics_output_dir / "item_metrics.csv", "w") as f:
          item_metrics.to_csv(f, index=False)
  
      # save the model
      model_output_dir = Path(arguments.model_dir)
      predictor.serialize(model_output_dir)
  
file_path: gluonts/src/gluonts/nursery/sagemaker_sdk/entry_point_scripts/train_entry_point.py
imports: import argparse
  import json
  import logging
  import os
  from pathlib import Path
  from gluonts.core import serde
  from gluonts.dataset import common
  from gluonts.dataset.repository import datasets
  from gluonts.evaluation import Evaluator, backtest
label_desc: Use image node_id 1 for calling a global function with example usage: train(arguments) without return types