docstr: Swaps the values of the optimized variables and swa buffers.
  
  It's meant to be called in the end of training to use the collected
  swa running averages. It can also be used to evaluate the running
  averages during training; to continue training `swap_swa_sgd`
  should be called again.
docstr_tok: ["Swaps","the","values","of","the","optimized","variables","and","swa","buffers",".","It","'s","meant","to","be","called","in","the","end","of","training","to","use","the","collected","swa","running","averages",".","It","can","also","be","used","to","evaluate","the","running","averages","during","training",";","to","continue","training","`","swap_swa_sgd","`","should","be","called","again","."]
code: def finalize(self):
      r"""Swaps the values of the optimized variables and swa buffers.
  
      It's meant to be called in the end of training to use the collected
      swa running averages. It can also be used to evaluate the running
      averages during training; to continue training `swap_swa_sgd`
      should be called again.
      """
      for group in self.param_groups:
          for p in group["params"]:
              param_state = self.state[p]
              if "swa_buffer" not in param_state:
                  # If swa wasn't applied we don't swap params
                  warnings.warn(
                      "SWA wasn't applied to param {}; skipping it".format(
                          p
                      )
                  )
                  continue
              buf = param_state["swa_buffer"]
              tmp = torch.empty_like(p.data)
              tmp.copy_(p.data)
              p.data.copy_(buf)
              buf.copy_(tmp)
      return True
  
imports: import warnings
  from collections import defaultdict
  from typing import Optional, Union
  import torch
  from pytext.config.component import create_optimizer
  from pytext.optimizer.lamb import Lamb
  from pytext.optimizer.madgrad import MADGRAD
  from pytext.optimizer.optimizers import Adagrad, Adam, AdamW, Optimizer, SGD
  from pytext.optimizer.radam import RAdam
  from torch.optim import Optimizer
label_desc: Use image node_id 6 for calling the StochasticWeightAveraging obj's underlying member method code with example usage: obj.finalize() and returns: True