opacus/privacy_engine.py
def step(self):
        """
        Takes a step for the privacy engine.

        Notes:
            You should not call this method directly. Rather, by attaching your
            ``PrivacyEngine`` to the optimizer, the ``PrivacyEngine`` would have
            the optimizer call this method for you.

        Raises:
            ValueError: If the last batch of training epoch is greater than others.
                This ensures the clipper consumed the right amount of gradients.
                In the last batch of a training epoch, we might get a batch that is
                smaller than others but we should never get a batch that is too large

        """
        self.steps += 1
        self.clipper.clip_and_accumulate()
        clip_values, batch_size = self.clipper.pre_step()

        if batch_size > self.batch_size:
            raise ValueError(
                f"PrivacyEngine expected a batch of size {self.batch_size} "
                f"but received a batch of size {batch_size}"
            )

        if batch_size < self.batch_size:
            warnings.warn(
                f"PrivacyEngine expected a batch of size {self.batch_size} "
                f"but the last step received a batch of size {batch_size}. "
                "This means that the privacy analysis will be a bit more "
                "pessimistic. You can set `drop_last = True` in your PyTorch "
                "dataloader to avoid this problem completely"
            )

        params = (p for p in self.module.parameters() if p.requires_grad)
        for p, clip_value in zip(params, clip_values):
            noise = self._generate_noise(clip_value, p)
            if self.loss_reduction == "mean":
                noise /= batch_size
            p.grad += noise

        Takes a step for the privacy engine.

        Notes:
            You should not call this method directly. Rather, by attaching your
            ``PrivacyEngine`` to the optimizer, the ``PrivacyEngine`` would have
            the optimizer call this method for you.

        Raises:
            ValueError: If the last batch of training epoch is greater than others.
                This ensures the clipper consumed the right amount of gradients.
                In the last batch of a training epoch, we might get a batch that is
                smaller than others but we should never get a batch that is too large

        
Takes a step for the privacy engine.
Notes:
You should not call this method directly.
Takes a step for the privacy engine . Notes : You should not call this method directly .
def step(self):
        self.steps += 1
        self.clipper.clip_and_accumulate()
        clip_values, batch_size = self.clipper.pre_step()
        if batch_size > self.batch_size:
            raise ValueError(
                f"PrivacyEngine expected a batch of size {self.batch_size} "
                f"but received a batch of size {batch_size}"
            )
        if batch_size < self.batch_size:
            warnings.warn(
                f"PrivacyEngine expected a batch of size {self.batch_size} "
                f"but the last step received a batch of size {batch_size}. "
                "This means that the privacy analysis will be a bit more "
                "pessimistic. You can set `drop_last = True` in your PyTorch "
                "dataloader to avoid this problem completely"
            )
        params = (p for p in self.module.parameters() if p.requires_grad)
        for p, clip_value in zip(params, clip_values):
            noise = self._generate_noise(clip_value, p)
            if self.loss_reduction == "mean":
                noise /= batch_size
            p.grad += noise
def step ( self ) : self . steps += 1 self . clipper . clip_and_accumulate ( ) clip_values , batch_size = self . clipper . pre_step ( ) if batch_size > self . batch_size : raise ValueError ( f"PrivacyEngine expected a batch of size {self.batch_size} " f"but received a batch of size {batch_size}" ) if batch_size < self . batch_size : warnings . warn ( f"PrivacyEngine expected a batch of size {self.batch_size} " f"but the last step received a batch of size {batch_size}. " "This means that the privacy analysis will be a bit more " "pessimistic. You can set `drop_last = True` in your PyTorch " "dataloader to avoid this problem completely" ) params = ( p for p in self . module . parameters ( ) if p . requires_grad ) for p , clip_value in zip ( params , clip_values ) : noise = self . _generate_noise ( clip_value , p ) if self . loss_reduction == "mean" : noise /= batch_size p . grad += noise
Takes a step for the privacy engine.
Takes a step for the privacy engine .
"""
        Takes a step for the privacy engine.

        Notes:
            You should not call this method directly. Rather, by attaching your
            ``PrivacyEngine`` to the optimizer, the ``PrivacyEngine`` would have
            the optimizer call this method for you.

        Raises:
            ValueError: If the last batch of training epoch is greater than others.
                This ensures the clipper consumed the right amount of gradients.
                In the last batch of a training epoch, we might get a batch that is
                smaller than others but we should never get a batch that is too large

        """
If the last batch of training epoch is greater than others.
This ensures the clipper consumed the right amount of gradients.
In the last batch of a training epoch, we might get a batch that is
smaller than others but we should never get a batch that is too large
If the last batch of training epoch is greater than others . This ensures the clipper consumed the right amount of gradients . In the last batch of a training epoch we might get a batch that is smaller than others but we should never get a batch that is too large
ValueError
self