scheduling_utils.py 1.64 KB
Newer Older
Patrick von Platen's avatar
up  
Patrick von Platen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
14
import warnings
15
from dataclasses import dataclass
Patrick von Platen's avatar
Patrick von Platen committed
16

Patrick von Platen's avatar
up  
Patrick von Platen committed
17
18
import torch

19
20
from ..utils import BaseOutput

Patrick von Platen's avatar
up  
Patrick von Platen committed
21

Patrick von Platen's avatar
Patrick von Platen committed
22
23
24
SCHEDULER_CONFIG_NAME = "scheduler_config.json"


25
26
27
28
29
30
31
32
33
34
35
36
37
38
@dataclass
class SchedulerOutput(BaseOutput):
    """
    Base class for the scheduler's step function output.

    Args:
        prev_sample (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)` for images):
            Computed sample (x_{t-1}) of previous timestep. `prev_sample` should be used as next model input in the
            denoising loop.
    """

    prev_sample: torch.FloatTensor


Patrick von Platen's avatar
Patrick von Platen committed
39
class SchedulerMixin:
40
41
42
    """
    Mixin containing common functions for the schedulers.
    """
Patrick von Platen's avatar
Patrick von Platen committed
43
44

    config_name = SCHEDULER_CONFIG_NAME
45
46
47
48
49
50
51
52
53

    def set_format(self, tensor_format="pt"):
        warnings.warn(
            "The method `set_format` is deprecated and will be removed in version `0.5.0`."
            "If you're running your code in PyTorch, you can safely remove this function as the schedulers"
            "are always in Pytorch",
            DeprecationWarning,
        )
        return self