code: def main():
      if not os.path.exists(args.outdir):
          os.makedirs(args.outdir)
  
      prediction_length = args.prediction_length
      context_length = (
          4 * prediction_length
          if not args.context_length
          else args.context_length
      )
      batch_size = args.batch_size
      device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
      params = Params(json_path=args.attack_params)
      params.device = device
      ds = get_dataset(args.dataset, args.max_target_dim)
      target_dim = ds.target_dim
      freq = ds.freq
      if args.gaussian:
          train_ds = get_augmented_dataset(
              ds, num_noises=args.num_noises, sigma=args.sigma
          )
      else:
          train_ds = ds.train_ds
  
      input_size = 1
      if args.dataset in ["electricity", "taxi", "traffic", "solar"]:
          input_size = 47
      elif args.dataset == "wiki":
          input_size = 45
      elif args.dataset == "exchange_rate":
          input_size = 31
  
      estimator = DeepVAREstimator(
          freq=freq,
          rank=args.rank,
          num_parallel_samples=100,
          prediction_length=prediction_length,
          input_size=input_size,
          trainer=Trainer(),
          target_dim=target_dim,
          context_length=context_length,
      )
  
      loader = estimator.get_loader(training_data=train_ds)
      temp = next(iter(loader))
      shape = temp["past_target_cdf"].shape
      sparse_net = SparseNet(
          shape[1],
          shape[2],
          None,
          hidden_dim=40,
          m=args.sparsity,
          max_norm=params.max_norm,
      ).to(device)
      trainer = Trainer_adv(
          sparse_net,
          clamp=args.clamp,
          epochs=args.epochs,
          batch_size=batch_size,
          device=device,
          learning_rate=args.lr,
      )
      estimator.trainer = trainer
      predictor = estimator.train(training_data=train_ds)
      predictor.serialize(Path(args.outdir))
  
file_path: gluonts/src/gluonts/nursery/robust-mts-attack/train_adv.py
imports: import argparse
  import torch
  import warnings
  import os
  from pts.model.deepvar import DeepVAREstimator
  from pts import Trainer_adv, Trainer
  from datasets import DATASETS, get_dataset
  from pathlib import Path
  import os
  from utils import get_augmented_dataset, Params
  from sparse_layer import SparseNet
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types