class_docstr: Estimator class to train a Temporal Fusion Transformer (TFT) model, as described in [LAL+21]_.
  
  TFT internally performs feature selection when making forecasts. For this
  reason, the dimensions of real-valued features can be grouped together if
  they correspond to the same variable (e.g., treat weather features as a
  one feature and holiday indicators as another feature).
  
  For example, if the dataset contains key "feat_static_real" with shape
  [batch_size, 3], we can, e.g.,
  - set ``static_dims = [3]`` to treat all three dimensions as a single feature
  - set ``static_dims = [1, 1, 1]`` to treat each dimension as a separate feature
  - set ``static_dims = [2, 1]`` to treat the first two dims as a single feature
  
  See ``gluonts.torch.model.tft.TemporalFusionTransformerModel.input_shapes``
  for more details on how the model configuration corresponds to the expected
  input shapes.
  
  
  Parameters
  ----------
  freq
      Frequency of the data to train on and predict.
  prediction_length
      Length of the prediction horizon.
  context_length
      Number of previous time series values provided as input to the encoder.
      (default: None, in which case context_length = prediction_length).
  quantiles
      List of quantiles that the model will learn to predict.
      Defaults to [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
  distr_output
      Distribution output to use (default: ``QuantileOutput``).
  num_heads
      Number of attention heads in self-attention layer in the decoder.
  hidden_dim
      Size of the LSTM & transformer hidden states.
  variable_dim
      Size of the feature embeddings.
  static_dims
      Sizes of the real-valued static features.
  dynamic_dims
      Sizes of the real-valued dynamic features that are known in the future.
  past_dynamic_dims
      Sizes of the real-valued dynamic features that are only known in the past.
  static_cardinalities
      Cardinalities of the categorical static features.
  dynamic_cardinalities
      Cardinalities of the categorical dynamic features that are known in the future.
  past_dynamic_cardinalities
      Cardinalities of the categorical dynamic features that are ony known in the past.
  time_features
      List of time features, from :py:mod:`gluonts.time_feature`, to use as
      dynamic real features in addition to the provided data (default: None,
      in which case these are automatically determined based on freq).
  lr
      Learning rate (default: ``1e-3``).
  weight_decay
      Weight decay (default: ``1e-8``).
  dropout_rate
      Dropout regularization parameter (default: 0.1).
  patience
      Patience parameter for learning rate scheduler.
  batch_size
      The size of the batches to be used for training (default: 32).
  num_batches_per_epoch: int = 50,
      Number of batches to be processed in each training epoch (default: 50).
  trainer_kwargs
      Additional arguments to provide to ``pl.Trainer`` for construction.
  train_sampler
      Controls the sampling of windows during training.
  validation_sampler
      Controls the sampling of windows during validation.
class_docstr_tok: ["Estimator","class","to","train","a","Temporal","Fusion","Transformer","(","TFT",")","model",",","as","described","in","[","LAL+21","]","_.","TFT","internally","performs","feature","selection","when","making","forecasts",".","For","this","reason",",","the","dimensions","of","real-valued","features","can","be","grouped","together","if","they","correspond","to","the","same","variable","(","e.g.",",","treat","weather","features","as","a","one","feature","and","holiday","indicators","as","another","feature",")",".","For","example",",","if","the","dataset","contains","key","``","feat_static_real","''","with","shape","[","batch_size",",","3","]",",","we","can",",","e.g.",",","-","set","``","static_dims","=","[","3","]","``","to","treat","all","three","dimensions","as","a","single","feature","-","set","``","static_dims","=","[","1",",","1",",","1","]","``","to","treat","each","dimension","as","a","separate","feature","-","set","``","static_dims","=","[","2",",","1","]","``","to","treat","the","first","two","dims","as","a","single","feature","See","``","gluonts.torch.model.tft.TemporalFusionTransformerModel.input_shapes","``","for","more","details","on","how","the","model","configuration","corresponds","to","the","expected","input","shapes",".","Parameters","--","--","--","--","--","freq","Frequency","of","the","data","to","train","on","and","predict",".","prediction_length","Length","of","the","prediction","horizon",".","context_length","Number","of","previous","time","series","values","provided","as","input","to","the","encoder",".","(","default",":","None",",","in","which","case","context_length","=","prediction_length",")",".","quantiles","List","of","quantiles","that","the","model","will","learn","to","predict",".","Defaults","to","[","0.1",",","0.2",",","0.3",",","0.4",",","0.5",",","0.6",",","0.7",",","0.8",",","0.9","]","distr_output","Distribution","output","to","use","(","default",":","``","QuantileOutput","``",")",".","num_heads","Number","of","attention","heads","in","self-attention","layer","in","the","decoder",".","hidden_dim","Size","of","the","LSTM","&","transformer","hidden","states",".","variable_dim","Size","of","the","feature","embeddings",".","static_dims","Sizes","of","the","real-valued","static","features",".","dynamic_dims","Sizes","of","the","real-valued","dynamic","features","that","are","known","in","the","future",".","past_dynamic_dims","Sizes","of","the","real-valued","dynamic","features","that","are","only","known","in","the","past",".","static_cardinalities","Cardinalities","of","the","categorical","static","features",".","dynamic_cardinalities","Cardinalities","of","the","categorical","dynamic","features","that","are","known","in","the","future",".","past_dynamic_cardinalities","Cardinalities","of","the","categorical","dynamic","features","that","are","ony","known","in","the","past",".","time_features","List","of","time","features",",","from",":","py",":","mod",":","`","gluonts.time_feature","`",",","to","use","as","dynamic","real","features","in","addition","to","the","provided","data","(","default",":","None",",","in","which","case","these","are","automatically","determined","based","on","freq",")",".","lr","Learning","rate","(","default",":","``","1e-3","``",")",".","weight_decay","Weight","decay","(","default",":","``","1e-8","``",")",".","dropout_rate","Dropout","regularization","parameter","(","default",":","0.1",")",".","patience","Patience","parameter","for","learning","rate","scheduler",".","batch_size","The","size","of","the","batches","to","be","used","for","training","(","default",":","32",")",".","num_batches_per_epoch",":","int","=","50",",","Number","of","batches","to","be","processed","in","each","training","epoch","(","default",":","50",")",".","trainer_kwargs","Additional","arguments","to","provide","to","``","pl.Trainer","``","for","construction",".","train_sampler","Controls","the","sampling","of","windows","during","training",".","validation_sampler","Controls","the","sampling","of","windows","during","validation","."]
code: def create_training_data_loader(
      self,
      data: Dataset,
      module: TemporalFusionTransformerLightningModule,
      shuffle_buffer_length: Optional[int] = None,
      **kwargs,
  ) -> Iterable:
      data = Cyclic(data).stream()
      instances = self._create_instance_splitter("training").apply(
          data, is_train=True
      )
      return as_stacked_batches(
          instances,
          batch_size=self.batch_size,
          shuffle_buffer_length=shuffle_buffer_length,
          field_names=self.input_names(),
          output_type=torch.tensor,
          num_batches_per_epoch=self.num_batches_per_epoch,
      )
  
imports: from typing import Any, Dict, Iterable, List, Optional
  import numpy
  import torch
  from gluonts.core.component import validated
  from gluonts.dataset.common import Dataset
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.loader import as_stacked_batches
  from gluonts.itertools import Cyclic
  from gluonts.time_feature import TimeFeature, time_features_from_frequency_str
  from gluonts.torch.distributions import Output, QuantileOutput
  from gluonts.torch.model.estimator import PyTorchLightningEstimator
  from gluonts.torch.model.predictor import PyTorchPredictor
  from gluonts.transform import AddConstFeature, AddObservedValuesIndicator, AddTimeFeatures, AsNumpyArray, Chain, ExpectedNumInstanceSampler, RemoveFields, SetField, TestSplitSampler, Transformation, ValidationSplitSampler, VstackFeatures
  from gluonts.transform.sampler import InstanceSampler
  from gluonts.transform.split import TFTInstanceSplitter
  from .lightning_module import TemporalFusionTransformerLightningModule
label_desc: Use image node_id 5 for calling the TemporalFusionTransformerEstimator obj's underlying member method code with example usage: obj.create_training_data_loader(data, module, shuffle_buffer_length) and returns: as_stacked_batches