def before_backward(self, strategy: Template, *args, **kwargs) -> Any:
        """
        Generate replay data and calculate the loss on the replay data.
        Add weighted loss to the total loss if the user has set the weight_replay_loss
        """
        super().before_backward(strategy, *args, **kwargs)
        if not self.is_weighted_replay:
            # If we are not using weighted loss, ignore this method
            return

        if self.untrained_solver:
            # do not generate on the first experience
            return

        # determine how many replay data points to generate
        if self.replay_size:
            number_replays_to_generate = self.replay_size
        else:
            if self.increasing_replay_size:
                number_replays_to_generate = len(strategy.mbatch[0]) * (
                    strategy.experience.current_experience
                )
            else:
                number_replays_to_generate = len(strategy.mbatch[0])
        replay_data = self.old_generator.generate(number_replays_to_generate).to(
            strategy.device
        )
        # get labels for replay data
        if not self.model_is_generator:
            with torch.no_grad():
                replay_output = self.old_model(replay_data).argmax(dim=-1)
        else:
            # Mock labels:
            replay_output = torch.zeros(replay_data.shape[0])

        # make copy of mbatch
        mbatch = deepcopy(strategy.mbatch)
        # replace mbatch with replay data, calculate loss and add to strategy.loss
        strategy.mbatch = [replay_data, replay_output, strategy.mbatch[-1]]
        strategy.forward()
        strategy.loss += self.weight_replay_loss * strategy.criterion()
        self.weight_replay_loss *= self.weight_replay_loss_factor
        # restore mbatch
        strategy.mbatch = mbatch

        Generate replay data and calculate the loss on the replay data.
        Add weighted loss to the total loss if the user has set the weight_replay_loss
        
avalanche/training/plugins/generative_replay.py