original_docstring: 
          Infer approximate posterior with stochastic variational inference.
  
          This runs :class:`~pyro.infer.svi.SVI`. It is an approximate inference
          method useful for quickly iterating on probabilistic models.
  
          :param ~torch.utils.data.Dataset dataset: The training dataset.
          :param int epochs: Number of epochs of training.
          :param int batch_size: Minibatch size (number of sequences).
          :param pyro.optim.MultiStepLR scheduler: Optimization scheduler.
              (Default: Adam optimizer, 0.01 constant learning rate.)
          :param bool jit: Whether to use a jit compiled ELBO.
          
docstring: Infer approximate posterior with stochastic variational inference.
docstring_tokens: Infer approximate posterior with stochastic variational inference .
code: def fit_svi(
          self,
          dataset,
          epochs=2,
          batch_size=1,
          scheduler=None,
          jit=False,
      ):
          """
          Infer approximate posterior with stochastic variational inference.
  
          This runs :class:`~pyro.infer.svi.SVI`. It is an approximate inference
          method useful for quickly iterating on probabilistic models.
  
          :param ~torch.utils.data.Dataset dataset: The training dataset.
          :param int epochs: Number of epochs of training.
          :param int batch_size: Minibatch size (number of sequences).
          :param pyro.optim.MultiStepLR scheduler: Optimization scheduler.
              (Default: Adam optimizer, 0.01 constant learning rate.)
          :param bool jit: Whether to use a jit compiled ELBO.
          """
  
          # Setup.
          if batch_size is not None:
              self.batch_size = batch_size
          if scheduler is None:
              scheduler = MultiStepLR(
                  {
                      "optimizer": Adam,
                      "optim_args": {"lr": 0.01},
                      "milestones": [],
                      "gamma": 0.5,
                  }
              )
          if self.is_cuda:
              device = torch.device("cuda")
          else:
              device = torch.device("cpu")
          # Initialize guide.
          self.guide(None, None)
          dataload = DataLoader(
              dataset,
              batch_size=batch_size,
              shuffle=True,
              pin_memory=self.pin_memory,
              generator=torch.Generator(device=device),
          )
          # Setup stochastic variational inference.
          if jit:
              elbo = JitTrace_ELBO(ignore_jit_warnings=True)
          else:
              elbo = Trace_ELBO()
          svi = SVI(self.model, self.guide, scheduler, loss=elbo)
  
          # Run inference.
          losses = []
          t0 = datetime.datetime.now()
          for epoch in range(epochs):
              for seq_data, L_data in dataload:
                  if self.is_cuda:
                      seq_data = seq_data.cuda()
                  loss = svi.step(
                      seq_data, torch.tensor(len(dataset) / seq_data.shape[0])
                  )
                  losses.append(loss)
                  scheduler.step()
              print(epoch, loss, " ", datetime.datetime.now() - t0)
          return losses
code_tokens: def fit_svi ( self , dataset , epochs = 2 , batch_size = 1 , scheduler = None , jit = False , ) : if batch_size is not None : self . batch_size = batch_size if scheduler is None : scheduler = MultiStepLR ( { "optimizer" : Adam , "optim_args" : { "lr" : 0.01 } , "milestones" : [ ] , "gamma" : 0.5 , } ) if self . is_cuda : device = torch . device ( "cuda" ) else : device = torch . device ( "cpu" ) self . guide ( None , None ) dataload = DataLoader ( dataset , batch_size = batch_size , shuffle = True , pin_memory = self . pin_memory , generator = torch . Generator ( device = device ) , ) if jit : elbo = JitTrace_ELBO ( ignore_jit_warnings = True ) else : elbo = Trace_ELBO ( ) svi = SVI ( self . model , self . guide , scheduler , loss = elbo ) losses = [ ] t0 = datetime . datetime . now ( ) for epoch in range ( epochs ) : for seq_data , L_data in dataload : if self . is_cuda : seq_data = seq_data . cuda ( ) loss = svi . step ( seq_data , torch . tensor ( len ( dataset ) / seq_data . shape [ 0 ] ) ) losses . append ( loss ) scheduler . step ( ) print ( epoch , loss , " " , datetime . datetime . now ( ) - t0 ) return losses
short_docstring: Infer approximate posterior with stochastic variational inference.
short_docstring_tokens: Infer approximate posterior with stochastic variational inference .
comment: """
          Infer approximate posterior with stochastic variational inference.
  
          This runs :class:`~pyro.infer.svi.SVI`. It is an approximate inference
          method useful for quickly iterating on probabilistic models.
  
          :param ~torch.utils.data.Dataset dataset: The training dataset.
          :param int epochs: Number of epochs of training.
          :param int batch_size: Minibatch size (number of sequences).
          :param pyro.optim.MultiStepLR scheduler: Optimization scheduler.
              (Default: Adam optimizer, 0.01 constant learning rate.)
          :param bool jit: Whether to use a jit compiled ELBO.
          """$SEP$# Setup.$SEP$# Initialize guide.$SEP$# Setup stochastic variational inference.$SEP$# Run inference.