In diffusion models such as DDPM, maintaining an Exponential Moving Average (EMA) of model weights during training is a widely adopted technique. Instead of using the raw trained weights for inference, a shadow copy of the parameters is updated at each training step using a weighted combination of its previous value and the current training weights. This shadow copy tends to produce significantly higher quality samples.
Given an initial set of EMA parameters, a sequence of model parameter snapshots collected at successive training steps, and a decay rate, implement a function that processes all training steps and returns the final EMA parameters.
Your Task:
Write a function ema_update(ema_params, model_params_list, decay) that takes:
ema_params: A numpy array (of any shape) representing the initial EMA parameters (typically initialized to the model's initial weights).model_params_list: A list of numpy arrays, where each array represents the model's parameters at a given training step. Each array has the same shape as ema_params.decay: A float in [0, 1] representing the EMA decay rate.The function should apply the EMA update for each snapshot in order and return the final EMA parameters as a Python list (using .tolist()), with values rounded to 4 decimal places.
Notes: