class_docstr: An `Estimator` type with utilities for creating PyTorch-Lightning-based
  models.
  
  To extend this class, one needs to implement three methods:
  `create_transformation`, `create_training_network`, `create_predictor`,
  `create_training_data_loader`, and `create_validation_data_loader`.
class_docstr_tok: ["An","`","Estimator","`","type","with","utilities","for","creating","PyTorch-Lightning-based","models",".","To","extend","this","class",",","one","needs","to","implement","three","methods",":","`","create_transformation","`",",","`","create_training_network","`",",","`","create_predictor","`",",","`","create_training_data_loader","`",",","and","`","create_validation_data_loader","`","."]
code: def train_model(
      self,
      training_data: Dataset,
      validation_data: Optional[Dataset] = None,
      from_predictor: Optional[PyTorchPredictor] = None,
      shuffle_buffer_length: Optional[int] = None,
      cache_data: bool = False,
      ckpt_path: Optional[str] = None,
      **kwargs,
  ) -> TrainOutput:
      transformation = self.create_transformation()
  
      with env._let(max_idle_transforms=max(len(training_data), 100)):
          transformed_training_data: Dataset = transformation.apply(
              training_data, is_train=True
          )
          if cache_data:
              transformed_training_data = Cached(
                  transformed_training_data
              )
  
          training_network = self.create_lightning_module()
  
          training_data_loader = self.create_training_data_loader(
              transformed_training_data,
              training_network,
              shuffle_buffer_length=shuffle_buffer_length,
          )
  
      validation_data_loader = None
  
      if validation_data is not None:
          with env._let(
              max_idle_transforms=max(len(validation_data), 100)
          ):
              transformed_validation_data: Dataset = (
                  transformation.apply(validation_data, is_train=True)
              )
              if cache_data:
                  transformed_validation_data = Cached(
                      transformed_validation_data
                  )
  
              validation_data_loader = (
                  self.create_validation_data_loader(
                      transformed_validation_data,
                      training_network,
                  )
              )
  
      if from_predictor is not None:
          training_network.load_state_dict(
              from_predictor.network.state_dict()
          )
  
      monitor = "train_loss" if validation_data is None else "val_loss"
      checkpoint = pl.callbacks.ModelCheckpoint(
          monitor=monitor, mode="min", verbose=True
      )
  
      custom_callbacks = self.trainer_kwargs.pop("callbacks", [])
      trainer = pl.Trainer(
          **{
              "accelerator": "auto",
              "callbacks": [checkpoint] + custom_callbacks,
              **self.trainer_kwargs,
          }
      )
  
      trainer.fit(
          model=training_network,
          train_dataloaders=training_data_loader,
          val_dataloaders=validation_data_loader,
          ckpt_path=ckpt_path,
      )
  
      if checkpoint.best_model_path != "":
          logger.info(
              f"Loading best model from {checkpoint.best_model_path}"
          )
          best_model = training_network.__class__.load_from_checkpoint(
              checkpoint.best_model_path
          )
      else:
          best_model = training_network
  
      return TrainOutput(
          transformation=transformation,
          trained_net=best_model,
          trainer=trainer,
          predictor=self.create_predictor(transformation, best_model),
      )
  
imports: from typing import NamedTuple, Optional, Iterable, Dict, Any
  import logging
  import numpy
  import lightning.pytorch
  import torch.nn
  from gluonts.core.component import validated
  from gluonts.dataset.common import Dataset
  from gluonts.env import env
  from gluonts.itertools import Cached
  from gluonts.model import Estimator, Predictor
  from gluonts.torch.model.predictor import PyTorchPredictor
  from gluonts.transform import Transformation
label_desc: Use image node_id 7 for calling the PyTorchLightningEstimator obj's underlying member method code with example usage: obj.train_model(training_data, validation_data, from_predictor, shuffle_buffer_length, cache_data, ckpt_path) and returns: TrainOutput