(
        self,
        loss: GANLoss,
        dis_optim: Optimizer,
        noise: Tensor,
        real_batch: Tensor,
        depth: int,
        alpha: float,
        labels: Optional[Tensor] = None,
    )
return dis_loss.item()
performs a single weight update step on discriminator using the batch of data
        and the noise
        Args:
            loss: the loss function to be used for the optimization
            dis_optim: discriminator optimizer
            noise: input noise for sample generation
            real_batch: real samples batch
            depth: current depth of optimization
            alpha: current alpha for fade-in
            labels: labels for conditional discrimination

        Returns: discriminator loss value
performs a single weight update step on discriminator using the batch of data
        and the noise
        Args:
            loss: the loss function to be used for the optimization
            dis_optim: discriminator optimizer
            noise: input noise for sample generation
            real_batch: real samples batch
            depth: current depth of optimization
            alpha: current alpha for fade-in
            labels: labels for conditional discrimination
performs a single weight update step on discriminator using the batch of data and the noise Args : loss : the loss function to be used for the optimization dis_optim : discriminator optimizer noise : input noise for sample generation real_batch : real samples batch depth : current depth of optimization alpha : current alpha for fade - in labels : labels for conditional discrimination
def optimize_discriminator(
        self,
        loss: GANLoss,
        dis_optim: Optimizer,
        noise: Tensor,
        real_batch: Tensor,
        depth: int,
        alpha: float,
        labels: Optional[Tensor] = None,
    ) -> float:
        """
        performs a single weight update step on discriminator using the batch of data
        and the noise
        Args:
            loss: the loss function to be used for the optimization
            dis_optim: discriminator optimizer
            noise: input noise for sample generation
            real_batch: real samples batch
            depth: current depth of optimization
            alpha: current alpha for fade-in
            labels: labels for conditional discrimination

        Returns: discriminator loss value
        """
        real_samples = self.progressive_downsample_batch(real_batch, depth, alpha)

        # generate a batch of samples
        fake_samples = self.gen(noise, depth, alpha).detach()
        dis_loss = loss.dis_loss(
            self.dis, real_samples, fake_samples, depth, alpha, labels=labels
        )

        # optimize discriminator
        dis_optim.zero_grad()
        dis_loss.backward()
        if self._check_grad_ok(self.dis):
            dis_optim.step()
        else:
            self.dis_overflow_count += 1

        return dis_loss.item()
def optimize_discriminator ( self , loss : GANLoss , dis_optim : Optimizer , noise : Tensor , real_batch : Tensor , depth : int , alpha : float , labels : Optional [ Tensor ] = None , ) -> float : real_samples = self . progressive_downsample_batch ( real_batch , depth , alpha ) # generate a batch of samples fake_samples = self . gen ( noise , depth , alpha ) . detach ( ) dis_loss = loss . dis_loss ( self . dis , real_samples , fake_samples , depth , alpha , labels = labels ) # optimize discriminator dis_optim . zero_grad ( ) dis_loss . backward ( ) if self . _check_grad_ok ( self . dis ) : dis_optim . step ( ) else : self . dis_overflow_count += 1 return dis_loss . item ( )