class_docstr: Controller class for optimization.
  
  Mostly a thin wrapper for `optim`, but also useful for implementing learning rate
  scheduling beyond what is currently available. Also implements necessary methods for
  training RNNs such as grad manipulations.
  
  Args:
      method (string):
          One of [sgd, adagrad, adadelta, adam].
      lr (float):
          Learning rate.
      lr_decay (float):
          Learning rate decay multiplier.
      start_decay_at (int):
          Epoch to start learning rate decay. If None, starts decay when the validation
          accuracy stops improving. Defaults to 1.
      beta1, beta2 (float):
          Hyperarameters for adam.
      adagrad_accum (float, optional):
          Initialization hyperparameter for adagrad.
class_docstr_tok: ["Controller","class","for","optimization",".","Mostly","a","thin","wrapper","for","`","optim","`",",","but","also","useful","for","implementing","learning","rate","scheduling","beyond","what","is","currently","available",".","Also","implements","necessary","methods","for","training","RNNs","such","as","grad","manipulations",".","Args",":","method","(","string",")",":","One","of","[","sgd",",","adagrad",",","adadelta",",","adam","]",".","lr","(","float",")",":","Learning","rate",".","lr_decay","(","float",")",":","Learning","rate","decay","multiplier",".","start_decay_at","(","int",")",":","Epoch","to","start","learning","rate","decay",".","If","None",",","starts","decay","when","the","validation","accuracy","stops","improving",".","Defaults","to","1.","beta1",",","beta2","(","float",")",":","Hyperarameters","for","adam",".","adagrad_accum","(","float",",","optional",")",":","Initialization","hyperparameter","for","adagrad","."]
docstr: Sets the model parameters and initializes the base optimizer.
  
  Args:
      params:
          Dictionary of named model parameters. Parameters that do not require
          gradients will be filtered out for optimization.
docstr_tok: ["Sets","the","model","parameters","and","initializes","the","base","optimizer",".","Args",":","params",":","Dictionary","of","named","model","parameters",".","Parameters","that","do","not","require","gradients","will","be","filtered","out","for","optimization","."]
code: def set_parameters(self, params):
      """Sets the model parameters and initializes the base optimizer.
  
      Args:
          params:
              Dictionary of named model parameters. Parameters that do not require
              gradients will be filtered out for optimization.
      """
      self.params = []
      for k, p in params:
          if p.requires_grad:
              self.params.append(p)
      if self.method == "sgd":
          self.base_optimizer = optim.SGD(self.params, lr=self.lr)
      elif self.method == "adagrad":
          self.base_optimizer = optim.Adagrad(self.params, lr=self.lr)
          for group in self.base_optimizer.param_groups:
              for p in group["params"]:
                  self.base_optimizer.state[p][
                      "sum"
                  ] = self.base_optimizer.state[p]["sum"].fill_(
                      self.adagrad_accum
                  )
      elif self.method == "adadelta":
          self.base_optimizer = optim.Adadelta(self.params, lr=self.lr)
      elif self.method == "adam":
          self.base_optimizer = optim.Adam(
              self.params, lr=self.lr, betas=self.betas, eps=1e-9
          )
      else:
          raise RuntimeError("Invalid optim method: " + self.method)
  
file_path: deepmatcher/deepmatcher/optim.py
imports: import logging
  import torch
  import torch.nn
  import torch.optim
  from torch.autograd import Variable
  from torch.nn.utils import clip_grad_norm_
label_desc: Use image node_id 2 for calling the Optimizer obj's underlying member method code with example usage: obj.set_parameters(params) without return types