Thanks for clarifying the question!
Using the provided code snippet to update the batchnorm stats using the training dataset sounds right. I wouldn’t update the stats using the validation dataset, as I would consider it a data leak (similar to updating them without the SWA util).