class_docstr: DNN Model
  Parameters
  ----------
  input_dim : int
      input dimension
  output_dim : int
      output dimension
  layers : tuple
      layer sizes
  lr : float
      learning rate
  optimizer : str
      optimizer name
  GPU : int
      the GPU ID used for training
class_docstr_tok: ["DNN","Model","Parameters","--","--","--","--","--","input_dim",":","int","input","dimension","output_dim",":","int","output","dimension","layers",":","tuple","layer","sizes","lr",":","float","learning","rate","optimizer",":","str","optimizer","name","GPU",":","int","the","GPU","ID","used","for","training"]
code: def __init__(
      self,
      lr=0.001,
      max_steps=300,
      batch_size=2000,
      early_stop_rounds=50,
      eval_steps=20,
      optimizer="gd",
      loss="mse",
      GPU=0,
      seed=None,
      weight_decay=0.0,
      data_parall=False,
      scheduler: Optional[
          Union[Callable]
      ] = "default",  # when it is Callable, it accept one argument named optimizer
      init_model=None,
      eval_train_metric=False,
      pt_model_uri="qlib.contrib.model.pytorch_nn.Net",
      pt_model_kwargs={
          "input_dim": 360,
          "layers": (256,),
      },
      valid_key=DataHandlerLP.DK_L,
      # TODO: Infer Key is a more reasonable key. But it requires more detailed processing on label processing
  ):
      # Set logger.
      self.logger = get_module_logger("DNNModelPytorch")
      self.logger.info("DNN pytorch version...")
  
      # set hyper-parameters.
      self.lr = lr
      self.max_steps = max_steps
      self.batch_size = batch_size
      self.early_stop_rounds = early_stop_rounds
      self.eval_steps = eval_steps
      self.optimizer = optimizer.lower()
      self.loss_type = loss
      if isinstance(GPU, str):
          self.device = torch.device(GPU)
      else:
          self.device = torch.device(
              "cuda:%d" % (GPU)
              if torch.cuda.is_available() and GPU >= 0
              else "cpu"
          )
      self.seed = seed
      self.weight_decay = weight_decay
      self.data_parall = data_parall
      self.eval_train_metric = eval_train_metric
      self.valid_key = valid_key
  
      self.best_step = None
  
      self.logger.info(
          "DNN parameters setting:"
          f"\nlr : {lr}"
          f"\nmax_steps : {max_steps}"
          f"\nbatch_size : {batch_size}"
          f"\nearly_stop_rounds : {early_stop_rounds}"
          f"\neval_steps : {eval_steps}"
          f"\noptimizer : {optimizer}"
          f"\nloss_type : {loss}"
          f"\nseed : {seed}"
          f"\ndevice : {self.device}"
          f"\nuse_GPU : {self.use_gpu}"
          f"\nweight_decay : {weight_decay}"
          f"\nenable data parall : {self.data_parall}"
          f"\npt_model_uri: {pt_model_uri}"
          f"\npt_model_kwargs: {pt_model_kwargs}"
      )
  
      if self.seed is not None:
          np.random.seed(self.seed)
          torch.manual_seed(self.seed)
  
      if loss not in {"mse", "binary"}:
          raise NotImplementedError(
              "loss {} is not supported!".format(loss)
          )
      self._scorer = (
          mean_squared_error if loss == "mse" else roc_auc_score
      )
  
      if init_model is None:
          self.dnn_model = init_instance_by_config(
              {"class": pt_model_uri, "kwargs": pt_model_kwargs}
          )
  
          if self.data_parall:
              self.dnn_model = DataParallel(self.dnn_model).to(
                  self.device
              )
      else:
          self.dnn_model = init_model
  
      self.logger.info("model:\n{:}".format(self.dnn_model))
      self.logger.info(
          "model size: {:.4f} MB".format(
              count_parameters(self.dnn_model)
          )
      )
  
      if optimizer.lower() == "adam":
          self.train_optimizer = optim.Adam(
              self.dnn_model.parameters(),
              lr=self.lr,
              weight_decay=self.weight_decay,
          )
      elif optimizer.lower() == "gd":
          self.train_optimizer = optim.SGD(
              self.dnn_model.parameters(),
              lr=self.lr,
              weight_decay=self.weight_decay,
          )
      else:
          raise NotImplementedError(
              "optimizer {} is not supported!".format(optimizer)
          )
  
      if scheduler == "default":
          # Reduce learning rate when loss has stopped decrease
          self.scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(
              self.train_optimizer,
              mode="min",
              factor=0.5,
              patience=10,
              verbose=True,
              threshold=0.0001,
              threshold_mode="rel",
              cooldown=0,
              min_lr=0.00001,
              eps=1e-08,
          )
      elif scheduler is None:
          self.scheduler = None
      else:
          self.scheduler = scheduler(optimizer=self.train_optimizer)
  
      self.fitted = False
      self.dnn_model.to(self.device)
  
imports: from __future__ import division
  from __future__ import print_function
  from collections import defaultdict
  import os
  import gc
  import numpy
  import pandas
  from typing import Callable, Optional, Text, Union
  from sklearn.metrics import roc_auc_score, mean_squared_error
  import torch
  import torch.nn
  import torch.optim
  from .pytorch_utils import count_parameters
  from ...model.base import Model
  from ...data.dataset import DatasetH
  from ...data.dataset.handler import DataHandlerLP
  from ...data.dataset.weight import Reweighter
  from ...utils import auto_filter_kwargs, init_instance_by_config, unpack_archive_with_buffer, save_multiple_parts_file, get_or_create_path
  from ...log import get_module_logger
  from ...workflow import R
  from qlib.contrib.meta.data_selection.utils import ICLoss
  from torch.nn import DataParallel
label_desc: Use image node_id 1 to create a new DNNModelPytorch object from inherited base classes: Model with example: obj = DNNModelPytorch(lr, max_steps, batch_size, early_stop_rounds, eval_steps, optimizer, loss, GPU, seed, weight_decay, data_parall, scheduler, init_model, eval_train_metric, pt_model_uri, pt_model_kwargs, valid_key)