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 sample_timesteps(
      self, batch_size, device, method="uniform", uniform_prob=0.001
  ):
      if method == "importance":  # importance sampling
          if not (self.Lt_count == self.history_num_per_term).all():
              return self.sample_timesteps(
                  batch_size, device, method="uniform"
              )
  
          Lt_sqrt = torch.sqrt(
              torch.mean(self.Lt_history**2, axis=-1)
          )
          pt_all = Lt_sqrt / torch.sum(Lt_sqrt)
          pt_all *= 1 - uniform_prob
          pt_all += uniform_prob / len(
              pt_all
          )  # ensure the least prob > uniform_prob
  
          assert pt_all.sum(-1) - 1.0 < 1e-5
  
          t = torch.multinomial(
              pt_all, num_samples=batch_size, replacement=True
          )
          pt = pt_all.gather(dim=0, index=t) * len(pt_all)
  
          return t, pt
  
      elif method == "uniform":  # uniform sampling
          t = torch.randint(
              0, self.steps, (batch_size,), device=device
          ).long()
          pt = torch.ones_like(t).float()
  
          return t, pt
  
      else:
          raise ValueError
  
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 11 for calling the DiffRec obj's underlying member method code with example usage: obj.sample_timesteps(batch_size, device, method, uniform_prob) and returns: t,  pt, self, t,  pt