class_docstr: Implements RMSprop algorithm.
  
  NOTE: This code is copied from :class:`torch.optim.RMSProp`, with the epsilon
  moved inside the square root to match tensorflow's implementation.
  
  Proposed by G. Hinton in his
  `course <http://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf>`_.
  
  The centered version first appears in `Generating Sequences
  With Recurrent Neural Networks <https://arxiv.org/pdf/1308.0850v5.pdf>`_.
  
  The implementation here takes the square root of the gradient average before
  adding epsilon (note that TensorFlow interchanges these two operations). The
  effective learning rate is thus :math:`\alpha/(\sqrt{v} + \epsilon)` where
  :math:`\alpha` is the scheduled learning rate and :math:`v` is the weighted moving
  average of the squared gradient.
  
  Arguments:
      params (iterable): iterable of parameters to optimize or dicts defining
          parameter groups
      lr (float, optional): learning rate (default: 1e-2)
      momentum (float, optional): momentum factor (default: 0)
      alpha (float, optional): smoothing constant (default: 0.99)
      eps (float, optional): term added to the square root in the denominator to
          improve numerical stability (default: 1e-8)
      centered (bool, optional) : if ``True``, compute the centered RMSProp,
          the gradient is normalized by an estimation of its variance
      weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
class_docstr_tok: ["Implements","RMSprop","algorithm",".","NOTE",":","This","code","is","copied","from",":","class",":","`","torch.optim.RMSProp","`",",","with","the","epsilon","moved","inside","the","square","root","to","match","tensorflow","'s","implementation",".","Proposed","by","G.","Hinton","in","his","`","course","<","http",":","\/\/www.cs.toronto.edu\/~tijmen\/csc321\/slides\/lecture_slides_lec6.pdf",">","`","_",".","The","centered","version","first","appears","in","`","Generating","Sequences","With","Recurrent","Neural","Networks","<","https",":","\/\/arxiv.org\/pdf\/1308.0850v5.pdf",">","`","_",".","The","implementation","here","takes","the","square","root","of","the","gradient","average","before","adding","epsilon","(","note","that","TensorFlow","interchanges","these","two","operations",")",".","The","effective","learning","rate","is","thus",":","math",":","`","\\alpha\/","(","\\sqrt","{","v","}","+","\\epsilon",")","`","where",":","math",":","`","\\alpha","`","is","the","scheduled","learning","rate","and",":","math",":","`","v","`","is","the","weighted","moving","average","of","the","squared","gradient",".","Arguments",":","params","(","iterable",")",":","iterable","of","parameters","to","optimize","or","dicts","defining","parameter","groups","lr","(","float",",","optional",")",":","learning","rate","(","default",":","1e-2",")","momentum","(","float",",","optional",")",":","momentum","factor","(","default",":","0",")","alpha","(","float",",","optional",")",":","smoothing","constant","(","default",":","0.99",")","eps","(","float",",","optional",")",":","term","added","to","the","square","root","in","the","denominator","to","improve","numerical","stability","(","default",":","1e-8",")","centered","(","bool",",","optional",")",":","if","``","True","``",",","compute","the","centered","RMSProp",",","the","gradient","is","normalized","by","an","estimation","of","its","variance","weight_decay","(","float",",","optional",")",":","weight","decay","(","L2","penalty",")","(","default",":","0",")"]
docstr: Performs a single optimization step.
  
  Arguments:
      closure (callable, optional): A closure that reevaluates the model
          and returns the loss.
docstr_tok: ["Performs","a","single","optimization","step",".","Arguments",":","closure","(","callable",",","optional",")",":","A","closure","that","reevaluates","the","model","and","returns","the","loss","."]
code: def step(self, closure=None):
      """Performs a single optimization step.
  
      Arguments:
          closure (callable, optional): A closure that reevaluates the model
              and returns the loss.
      """
      loss = None
      if closure is not None:
          loss = closure()
  
      for group in self.param_groups:
          for p in group["params"]:
              if p.grad is None:
                  continue
              grad = p.grad.data
              if grad.is_sparse:
                  raise RuntimeError(
                      "RMSprop does not support sparse gradients"
                  )
              state = self.state[p]
  
              # State initialization
              if len(state) == 0:
                  state["step"] = 0
                  state["square_avg"] = torch.zeros_like(
                      p.data, memory_format=torch.preserve_format
                  )
                  if group["momentum"] > 0:
                      state["momentum_buffer"] = torch.zeros_like(
                          p.data, memory_format=torch.preserve_format
                      )
                  if group["centered"]:
                      state["grad_avg"] = torch.zeros_like(
                          p.data, memory_format=torch.preserve_format
                      )
  
              square_avg = state["square_avg"]
              alpha = group["alpha"]
  
              state["step"] += 1
  
              if group["weight_decay"] != 0:
                  grad = grad.add(group["weight_decay"], p.data)
  
              square_avg.mul_(alpha).addcmul_(1 - alpha, grad, grad)
  
              if group["centered"]:
                  grad_avg = state["grad_avg"]
                  grad_avg.mul_(alpha).add_(1 - alpha, grad)
                  avg = (
                      square_avg.addcmul(-1, grad_avg, grad_avg)
                      .add_(group["eps"])
                      .sqrt_()
                  )
              else:
                  avg = square_avg.add_(group["eps"]).sqrt_()
  
              if group["momentum"] > 0:
                  buf = state["momentum_buffer"]
                  buf.mul_(group["momentum"]).addcdiv_(grad, avg)
                  p.data.add_(-group["lr"], buf)
              else:
                  p.data.addcdiv_(-group["lr"], grad, avg)
  
      return loss
  
file_path: ClassyVision/classy_vision/optim/rmsprop_tf.py
imports: from typing import Any, Dict
  import torch.optim
  from classy_vision.generic.util import is_pos_float
  from torch.optim import Optimizer
  from .None import ClassyOptimizer, register_optimizer
label_desc: Use image node_id 3 for calling the RMSpropTFOptimizer obj's underlying member method code with example usage: obj.step(closure) and returns: loss