class_docstr: DiffRec is a generative recommender model which infers users' interaction probabilities in a denoising manner.
  Note that DiffRec simultaneously ranks all items for each user.
  We implement the the DiffRec model with only user dataloader.
class_docstr_tok: ["DiffRec","is","a","generative","recommender","model","which","infers","users","'","interaction","probabilities","in","a","denoising","manner",".","Note","that","DiffRec","simultaneously","ranks","all","items","for","each","user",".","We","implement","the","the","DiffRec","model","with","only","user","dataloader","."]
code: def reweight_loss(
      self, x_start, x_t, mse, ts, target, model_output, device
  ):
      if self.reweight:
          if self.mean_type == ModelMeanType.START_X:
              # Eq.11
              weight = self.SNR(ts - 1) - self.SNR(ts)
              # Eq.12
              weight = torch.where((ts == 0), 1.0, weight)
              loss = mse
          elif self.mean_type == ModelMeanType.EPSILON:
              weight = (1 - self.alphas_cumprod[ts]) / (
                  (1 - self.alphas_cumprod_prev[ts]) ** 2
                  * (1 - self.betas[ts])
              )
              weight = torch.where((ts == 0), 1.0, weight)
              likelihood = mean_flat(
                  (
                      x_start
                      - self._predict_xstart_from_eps(
                          x_t, ts, model_output
                      )
                  )
                  ** 2
                  / 2.0
              )
              loss = torch.where((ts == 0), likelihood, mse)
      else:
          weight = torch.tensor([1.0] * len(target)).to(device)
          loss = mse
      reloss = weight * loss
      return reloss
  
imports: import enum
  import math
  import copy
  import numpy
  import torch
  import torch.nn.functional
  import torch.nn
  from recbole.model.init import xavier_normal_initialization
  from recbole.utils.enum_type import InputType
  from recbole.model.abstract_recommender import AutoEncoderMixin, GeneralRecommender
  from recbole.model.layers import MLPLayers
  import typing
label_desc: Use image node_id 9 for calling the DiffRec obj's underlying member method code with example usage: obj.reweight_loss(x_start, x_t, mse, ts, target, model_output, device) and returns: reloss