def moving_average_model(self, model, avg_model, beta=0.999):
        """Moving average model weights.

        This trick is commonly used in GAN training, where the weight of the
        generator is life-long averaged

        Args:
            model: The latest model used to update the averaged weights.
            avg_model: The averaged model weights.
            beta: Hyper-parameter used for moving average.
        """
        model_params = dict(self.get_module(model).named_parameters())
        avg_params = dict(self.get_module(avg_model).named_parameters())

        assert len(model_params) == len(avg_params)
        for param_name in avg_params:
            assert param_name in model_params
            avg_params[param_name].data = (
                avg_params[param_name].data * beta +
                model_params[param_name].data * (1 - beta))
Moving average model weights.

        This trick is commonly used in GAN training, where the weight of the
        generator is life-long averaged

        Args:
            model: The latest model used to update the averaged weights.
            avg_model: The averaged model weights.
            beta: Hyper-parameter used for moving average.
        
runners/base_gan_runner.py