docstr: Adapted from https://github.com/pytorch/pytorch/blob/v1.7.1/torch/optim/swa_utils.py#L104-L112.
docstr_tok: ["Adapted","from","https",":","\/\/github.com\/pytorch\/pytorch\/blob\/v1.7.1\/torch\/optim\/swa_utils.py","#","L104-L112","."]
code: def update_parameters(
      average_model: "pl.LightningModule",
      model: "pl.LightningModule",
      n_averaged: Tensor,
      avg_fn: _AVG_FN,
  ) -> None:
      """Adapted from https://github.com/pytorch/pytorch/blob/v1.7.1/torch/optim/swa_utils.py#L104-L112."""
      for p_swa, p_model in zip(
          average_model.parameters(), model.parameters()
      ):
          device = p_swa.device
          p_swa_ = p_swa.detach()
          p_model_ = p_model.detach().to(device)
          src = (
              p_model_
              if n_averaged == 0
              else avg_fn(p_swa_, p_model_, n_averaged.to(device))
          )
          p_swa_.copy_(src)
      n_averaged += 1
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Union, cast
  import torch
  from torch import Tensor, nn
  from torch.optim.swa_utils import SWALR
  from typing_extensions import override
  import lightning.pytorch
  from lightning.fabric.utilities.types import LRScheduler
  from lightning.pytorch.callbacks.callback import Callback
  from lightning.pytorch.strategies import DeepSpeedStrategy
  from lightning.pytorch.strategies.fsdp import FSDPStrategy
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.rank_zero import rank_zero_info, rank_zero_warn
  from lightning.pytorch.utilities.types import LRSchedulerConfig
label_desc: Use image node_id 13 for calling the StochasticWeightAveraging obj's underlying member method code with example usage: obj.update_parameters(average_model, model, n_averaged, avg_fn) without return types