Skip to content

Base Noise Schedule

Base class for noise schedules in diffusion models.

BaseNoiseSchedule

Bases: ABC

Abstract base class defining the interface for noise schedules.

All noise schedule implementations should inherit from this class and implement the required abstract methods.

Source code in image_gen\noise\base.py
class BaseNoiseSchedule(ABC):
    """Abstract base class defining the interface for noise schedules.

    All noise schedule implementations should inherit from this class
    and implement the required abstract methods.
    """

    @abstractmethod
    def __call__(self, t: Tensor, *args: Any, **kwargs: Any) -> Tensor:
        """Calculate noise at specific timesteps.

        Args:
            t: Tensor containing timestep values.
            *args: Additional positional arguments.
            **kwargs: Additional keyword arguments.

        Returns:
            Tensor: Noise values corresponding to the input timesteps.
        """
        ...

    @abstractmethod
    def integral_beta(self, t: Tensor, *args: Any, **kwargs: Any) -> Tensor:
        """Calculate the integral of the noise function up to timestep t.

        Args:
            t: Tensor containing timestep values.
            *args: Additional positional arguments.
            **kwargs: Additional keyword arguments.

        Returns:
            Tensor: Integrated noise values corresponding to the input timesteps.
        """
        ...

    def config(self) -> dict:
        """Get the configuration parameters of the noise schedule.

        Returns:
            dict: Configuration parameters of the noise schedule.
        """
        return {}

    def __str__(self) -> str:
        """Generate a string representation of the noise schedule.

        Returns:
            str: String representation including class name and parameters.
        """
        config = self.config()
        params = ", ".join(f"{k}: {v}" for k, v in config.items())
        return f"{self._class_name}({params})"

    @property
    def _class_name(self) -> str:
        """Get the class name of the noise schedule.

        This property will be automatically overridden in custom classes
        made by users.

        Returns:
            str: Name of the class.
        """
        # This will be automatically overridden in custom classes made by users
        return self.__class__.__name__

__call__(t, *args, **kwargs) abstractmethod

Calculate noise at specific timesteps.

Parameters:

Name Type Description Default
t Tensor

Tensor containing timestep values.

required
*args Any

Additional positional arguments.

()
**kwargs Any

Additional keyword arguments.

{}

Returns:

Name Type Description
Tensor Tensor

Noise values corresponding to the input timesteps.

Source code in image_gen\noise\base.py
@abstractmethod
def __call__(self, t: Tensor, *args: Any, **kwargs: Any) -> Tensor:
    """Calculate noise at specific timesteps.

    Args:
        t: Tensor containing timestep values.
        *args: Additional positional arguments.
        **kwargs: Additional keyword arguments.

    Returns:
        Tensor: Noise values corresponding to the input timesteps.
    """
    ...

__str__()

Generate a string representation of the noise schedule.

Returns:

Name Type Description
str str

String representation including class name and parameters.

Source code in image_gen\noise\base.py
def __str__(self) -> str:
    """Generate a string representation of the noise schedule.

    Returns:
        str: String representation including class name and parameters.
    """
    config = self.config()
    params = ", ".join(f"{k}: {v}" for k, v in config.items())
    return f"{self._class_name}({params})"

config()

Get the configuration parameters of the noise schedule.

Returns:

Name Type Description
dict dict

Configuration parameters of the noise schedule.

Source code in image_gen\noise\base.py
def config(self) -> dict:
    """Get the configuration parameters of the noise schedule.

    Returns:
        dict: Configuration parameters of the noise schedule.
    """
    return {}

integral_beta(t, *args, **kwargs) abstractmethod

Calculate the integral of the noise function up to timestep t.

Parameters:

Name Type Description Default
t Tensor

Tensor containing timestep values.

required
*args Any

Additional positional arguments.

()
**kwargs Any

Additional keyword arguments.

{}

Returns:

Name Type Description
Tensor Tensor

Integrated noise values corresponding to the input timesteps.

Source code in image_gen\noise\base.py
@abstractmethod
def integral_beta(self, t: Tensor, *args: Any, **kwargs: Any) -> Tensor:
    """Calculate the integral of the noise function up to timestep t.

    Args:
        t: Tensor containing timestep values.
        *args: Additional positional arguments.
        **kwargs: Additional keyword arguments.

    Returns:
        Tensor: Integrated noise values corresponding to the input timesteps.
    """
    ...