class_docstr: Class implements torch model's main methods.
  
  Args:
      model: torch.nn.Model-based neural network model
      device: device to use
      optimizer: name of `torch.optim` optimizer
      optimizer_parameters: dictionary with optimizer parameters
      learning_rate_drop_patience: how many validations with no improvements to wait
      learning_rate_drop_div: the divider of the learning rate after `learning_rate_drop_patience` unsuccessful
          validations
      load_before_drop: whether to load best model before dropping learning rate or not
      min_learning_rate: min value of learning rate if learning rate decay is used
      args:
      kwargs: dictionary with other model parameters
  
  Attributes:
      device: `cpu` or `cuda` device to use
      opt: dictionary with all model parameters
      model: torch model
      epochs_done: number of epochs that were done
      optimizer: `torch.optim` instance
      learning_rate_drop_patience: how many validations with no improvements to wait
      learning_rate_drop_div: the divider of the learning rate after `learning_rate_drop_patience` unsuccessful
          validations
      load_before_drop: whether to load best model before dropping learning rate or not
      min_learning_rate: min value of learning rate if learning rate decay is used
      clip_norm: clip gradients by norm coefficient
class_docstr_tok: ["Class","implements","torch","model","'s","main","methods",".","Args",":","model",":","torch.nn.Model-based","neural","network","model","device",":","device","to","use","optimizer",":","name","of","`","torch.optim","`","optimizer","optimizer_parameters",":","dictionary","with","optimizer","parameters","learning_rate_drop_patience",":","how","many","validations","with","no","improvements","to","wait","learning_rate_drop_div",":","the","divider","of","the","learning","rate","after","`","learning_rate_drop_patience","`","unsuccessful","validations","load_before_drop",":","whether","to","load","best","model","before","dropping","learning","rate","or","not","min_learning_rate",":","min","value","of","learning","rate","if","learning","rate","decay","is","used","args",":","kwargs",":","dictionary","with","other","model","parameters","Attributes",":","device",":","`","cpu","`","or","`","cuda","`","device","to","use","opt",":","dictionary","with","all","model","parameters","model",":","torch","model","epochs_done",":","number","of","epochs","that","were","done","optimizer",":","`","torch.optim","`","instance","learning_rate_drop_patience",":","how","many","validations","with","no","improvements","to","wait","learning_rate_drop_div",":","the","divider","of","the","learning","rate","after","`","learning_rate_drop_patience","`","unsuccessful","validations","load_before_drop",":","whether","to","load","best","model","before","dropping","learning","rate","or","not","min_learning_rate",":","min","value","of","learning","rate","if","learning","rate","decay","is","used","clip_norm",":","clip","gradients","by","norm","coefficient"]
docstr: Process event. After epoch, increase `self.epochs_done`. After validation, decrease learning rate in
      `self.learning_rate_drop_div` times (not lower than `self.min_learning_rate`)
      if given `self.learning_rate_drop_patience`.
  
  Args:
      event_name: whether event is send after epoch or batch.
              Set of values: ``"after_epoch", "after_batch"``
      data: event data (dictionary)
  Returns:
      None
docstr_tok: ["Process","event",".","After","epoch",",","increase","`","self.epochs_done","`",".","After","validation",",","decrease","learning","rate","in","`","self.learning_rate_drop_div","`","times","(","not","lower","than","`","self.min_learning_rate","`",")","if","given","`","self.learning_rate_drop_patience","`",".","Args",":","event_name",":","whether","event","is","send","after","epoch","or","batch",".","Set","of","values",":","``","``","after_epoch","''",",","``","after_batch","''","``","data",":","event","data","(","dictionary",")","Returns",":","None"]
code: def process_event(self, event_name: str, data: dict) -> None:
      """Process event. After epoch, increase `self.epochs_done`. After validation, decrease learning rate in
          `self.learning_rate_drop_div` times (not lower than `self.min_learning_rate`)
          if given `self.learning_rate_drop_patience`.
  
      Args:
          event_name: whether event is send after epoch or batch.
                  Set of values: ``"after_epoch", "after_batch"``
          data: event data (dictionary)
      Returns:
          None
      """
      if event_name == "after_epoch":
          self.epochs_done += 1
  
      if (
          event_name == "after_validation"
          and "impatience" in data
          and self.learning_rate_drop_patience
      ):
          if data["impatience"] == self.learning_rate_drop_patience:
              log.info(
                  f"----------Current LR is decreased in {self.learning_rate_drop_div} times----------"
              )
              if self.load_before_drop:
                  self.load(self.save_path)
                  self.model.eval()
              for param_group in self.optimizer.param_groups:
                  param_group["lr"] = max(
                      param_group["lr"] / self.learning_rate_drop_div,
                      self.min_learning_rate,
                  )
  
file_path: DeepPavlov/deeppavlov/core/models/torch_model.py
imports: from abc import abstractmethod
  from logging import getLogger
  from pathlib import Path
  from typing import Optional, Union
  import torch
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.core.models.nn_model import NNModel
label_desc: Use image node_id 6 for calling the TorchModel obj's underlying member method code with example usage: obj.process_event(event_name, data) without return types