def update_momentum(model: nn.Module, model_ema: nn.Module, m: float):
    """Updates parameters of `model_ema` with Exponential Moving Average of `model`

    Momentum encoders are a crucial component for models such as MoCo or BYOL.

    Args:
        model:
            The current model.
        model_ema:
            The model with exponential moving average (EMA) parameters.
        m:
            The momentum factor, between 0 and 1.

    Examples:
        >>> backbone = resnet18()
        >>> projection_head = MoCoProjectionHead()
        >>> backbone_momentum = copy.deepcopy(moco)
        >>> projection_head_momentum = copy.deepcopy(projection_head)
        >>>
        >>> # update momentum
        >>> update_momentum(moco, moco_momentum, m=0.999)
        >>> update_momentum(projection_head, projection_head_momentum, m=0.999)
    """
    for model_ema, model in zip(model_ema.parameters(), model.parameters()):
        model_ema.data = model_ema.data * m + model.data * (1.0 - m)
Updates parameters of `model_ema` with Exponential Moving Average of `model`

    Momentum encoders are a crucial component for models such as MoCo or BYOL.

    Args:
        model:
            The current model.
        model_ema:
            The model with exponential moving average (EMA) parameters.
        m:
            The momentum factor, between 0 and 1.

    Examples:
        >>> backbone = resnet18()
        >>> projection_head = MoCoProjectionHead()
        >>> backbone_momentum = copy.deepcopy(moco)
        >>> projection_head_momentum = copy.deepcopy(projection_head)
        >>>
        >>> # update momentum
        >>> update_momentum(moco, moco_momentum, m=0.999)
        >>> update_momentum(projection_head, projection_head_momentum, m=0.999)
    
lightly/models/utils.py