"docs/vscode:/vscode.git/clone" did not exist on "fb39e1e568c49fcd97f9a56cb70a89d6693738c7"
test_scheduler.py 17.3 KB
Newer Older
Patrick von Platen's avatar
Patrick von Platen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# coding=utf-8
# Copyright 2022 HuggingFace Inc.
#
# 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.


Patrick von Platen's avatar
Patrick von Platen committed
17
import tempfile
Patrick von Platen's avatar
Patrick von Platen committed
18
import unittest
Patrick von Platen's avatar
Patrick von Platen committed
19

Patrick von Platen's avatar
Patrick von Platen committed
20
21
22
import numpy as np
import torch

Patrick von Platen's avatar
Patrick von Platen committed
23
from diffusers import DDIMScheduler, DDPMScheduler, PNDMScheduler
Patrick von Platen's avatar
Patrick von Platen committed
24
25
26
27
28
29


torch.backends.cuda.matmul.allow_tf32 = False


class SchedulerCommonTest(unittest.TestCase):
Patrick von Platen's avatar
Patrick von Platen committed
30
31
    scheduler_classes = ()
    forward_default_kwargs = ()
Patrick von Platen's avatar
Patrick von Platen committed
32
33

    @property
34
    def dummy_sample(self):
Patrick von Platen's avatar
Patrick von Platen committed
35
36
37
38
39
        batch_size = 4
        num_channels = 3
        height = 8
        width = 8

40
        sample = np.random.rand(batch_size, num_channels, height, width)
Patrick von Platen's avatar
Patrick von Platen committed
41

42
        return sample
Patrick von Platen's avatar
Patrick von Platen committed
43
44

    @property
45
    def dummy_sample_deter(self):
Patrick von Platen's avatar
Patrick von Platen committed
46
47
48
49
50
51
        batch_size = 4
        num_channels = 3
        height = 8
        width = 8

        num_elems = batch_size * num_channels * height * width
52
53
54
55
        sample = np.arange(num_elems)
        sample = sample.reshape(num_channels, height, width, batch_size)
        sample = sample / num_elems
        sample = sample.transpose(3, 0, 1, 2)
Patrick von Platen's avatar
Patrick von Platen committed
56

57
        return sample
Patrick von Platen's avatar
Patrick von Platen committed
58
59
60
61
62

    def get_scheduler_config(self):
        raise NotImplementedError

    def dummy_model(self):
63
64
        def model(sample, t, *args):
            return sample * t / (t + 1)
Patrick von Platen's avatar
Patrick von Platen committed
65
66
67

        return model

Patrick von Platen's avatar
Patrick von Platen committed
68
69
70
71
72
    def check_over_configs(self, time_step=0, **config):
        kwargs = dict(self.forward_default_kwargs)

        for scheduler_class in self.scheduler_classes:
            scheduler_class = self.scheduler_classes[0]
73
74
            sample = self.dummy_sample
            residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
75
76
77
78
79
80
81
82

            scheduler_config = self.get_scheduler_config(**config)
            scheduler = scheduler_class(**scheduler_config)

            with tempfile.TemporaryDirectory() as tmpdirname:
                scheduler.save_config(tmpdirname)
                new_scheduler = scheduler_class.from_config(tmpdirname)

83
84
            output = scheduler.step(residual, sample, time_step, **kwargs)
            new_output = new_scheduler.step(residual, sample, time_step, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
85

Patrick von Platen's avatar
Patrick von Platen committed
86
            assert np.sum(np.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical"
Patrick von Platen's avatar
Patrick von Platen committed
87
88
89
90
91
92

    def check_over_forward(self, time_step=0, **forward_kwargs):
        kwargs = dict(self.forward_default_kwargs)
        kwargs.update(forward_kwargs)

        for scheduler_class in self.scheduler_classes:
93
94
            sample = self.dummy_sample
            residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
95

Patrick von Platen's avatar
Patrick von Platen committed
96
            scheduler_class = self.scheduler_classes[0]
Patrick von Platen's avatar
Patrick von Platen committed
97
98
99
100
101
102
103
            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)

            with tempfile.TemporaryDirectory() as tmpdirname:
                scheduler.save_config(tmpdirname)
                new_scheduler = scheduler_class.from_config(tmpdirname)

104
105
            output = scheduler.step(residual, sample, time_step, **kwargs)
            new_output = new_scheduler.step(residual, sample, time_step, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
106

Patrick von Platen's avatar
Patrick von Platen committed
107
            assert np.sum(np.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical"
Patrick von Platen's avatar
Patrick von Platen committed
108

Patrick von Platen's avatar
Patrick von Platen committed
109
    def test_from_pretrained_save_pretrained(self):
Patrick von Platen's avatar
Patrick von Platen committed
110
111
112
        kwargs = dict(self.forward_default_kwargs)

        for scheduler_class in self.scheduler_classes:
113
114
            sample = self.dummy_sample
            residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
115
116
117
118
119
120
121
122

            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)

            with tempfile.TemporaryDirectory() as tmpdirname:
                scheduler.save_config(tmpdirname)
                new_scheduler = scheduler_class.from_config(tmpdirname)

123
124
            output = scheduler.step(residual, sample, 1, **kwargs)
            new_output = new_scheduler.step(residual, sample, 1, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
125

Patrick von Platen's avatar
Patrick von Platen committed
126
            assert np.sum(np.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical"
Patrick von Platen's avatar
Patrick von Platen committed
127
128
129
130
131
132
133
134

    def test_step_shape(self):
        kwargs = dict(self.forward_default_kwargs)

        for scheduler_class in self.scheduler_classes:
            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)

135
136
            sample = self.dummy_sample
            residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
137

138
139
            output_0 = scheduler.step(residual, sample, 0, **kwargs)
            output_1 = scheduler.step(residual, sample, 1, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
140

141
            self.assertEqual(output_0.shape, sample.shape)
Patrick von Platen's avatar
Patrick von Platen committed
142
143
            self.assertEqual(output_0.shape, output_1.shape)

Patrick von Platen's avatar
Patrick von Platen committed
144
145
146
147
    def test_pytorch_equal_numpy(self):
        kwargs = dict(self.forward_default_kwargs)

        for scheduler_class in self.scheduler_classes:
148
149
            sample = self.dummy_sample
            residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
150

151
152
            sample_pt = torch.tensor(sample)
            residual_pt = 0.1 * sample_pt
Patrick von Platen's avatar
Patrick von Platen committed
153
154
155
156
157
158

            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)

            scheduler_pt = scheduler_class(tensor_format="pt", **scheduler_config)

159
160
            output = scheduler.step(residual, sample, 1, **kwargs)
            output_pt = scheduler_pt.step(residual_pt, sample_pt, 1, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
161

Patrick von Platen's avatar
Patrick von Platen committed
162
            assert np.sum(np.abs(output - output_pt.numpy())) < 1e-4, "Scheduler outputs are not identical"
Patrick von Platen's avatar
Patrick von Platen committed
163

Patrick von Platen's avatar
Patrick von Platen committed
164
165

class DDPMSchedulerTest(SchedulerCommonTest):
Patrick von Platen's avatar
Patrick von Platen committed
166
    scheduler_classes = (DDPMScheduler,)
Patrick von Platen's avatar
Patrick von Platen committed
167
168
169
170
171
172
173
174

    def get_scheduler_config(self, **kwargs):
        config = {
            "timesteps": 1000,
            "beta_start": 0.0001,
            "beta_end": 0.02,
            "beta_schedule": "linear",
            "variance_type": "fixed_small",
Patrick von Platen's avatar
Patrick von Platen committed
175
            "clip_sample": True,
Patrick von Platen's avatar
Patrick von Platen committed
176
177
178
179
        }

        config.update(**kwargs)
        return config
Patrick von Platen's avatar
update  
Patrick von Platen committed
180

Patrick von Platen's avatar
Patrick von Platen committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    def test_timesteps(self):
        for timesteps in [1, 5, 100, 1000]:
            self.check_over_configs(timesteps=timesteps)

    def test_betas(self):
        for beta_start, beta_end in zip([0.0001, 0.001, 0.01, 0.1], [0.002, 0.02, 0.2, 2]):
            self.check_over_configs(beta_start=beta_start, beta_end=beta_end)

    def test_schedules(self):
        for schedule in ["linear", "squaredcos_cap_v2"]:
            self.check_over_configs(beta_schedule=schedule)

    def test_variance_type(self):
        for variance in ["fixed_small", "fixed_large", "other"]:
            self.check_over_configs(variance_type=variance)

197
    def test_clip_sample(self):
Patrick von Platen's avatar
Patrick von Platen committed
198
199
        for clip_sample in [True, False]:
            self.check_over_configs(clip_sample=clip_sample)
Patrick von Platen's avatar
Patrick von Platen committed
200
201
202
203
204
205
206
207
208
209

    def test_time_indices(self):
        for t in [0, 500, 999]:
            self.check_over_forward(time_step=t)

    def test_variance(self):
        scheduler_class = self.scheduler_classes[0]
        scheduler_config = self.get_scheduler_config()
        scheduler = scheduler_class(**scheduler_config)

Patrick von Platen's avatar
Patrick von Platen committed
210
211
212
        assert np.sum(np.abs(scheduler.get_variance(0) - 0.0)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(487) - 0.00979)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(999) - 0.02)) < 1e-5
Patrick von Platen's avatar
Patrick von Platen committed
213
214
215

    def test_full_loop_no_noise(self):
        scheduler_class = self.scheduler_classes[0]
Patrick von Platen's avatar
Patrick von Platen committed
216
        scheduler_config = self.get_scheduler_config()
Patrick von Platen's avatar
Patrick von Platen committed
217
218
219
220
221
        scheduler = scheduler_class(**scheduler_config)

        num_trained_timesteps = len(scheduler)

        model = self.dummy_model()
222
        sample = self.dummy_sample_deter
Patrick von Platen's avatar
Patrick von Platen committed
223
224
225

        for t in reversed(range(num_trained_timesteps)):
            # 1. predict noise residual
226
            residual = model(sample, t)
Patrick von Platen's avatar
Patrick von Platen committed
227

228
229
            # 2. predict previous mean of sample x_t-1
            pred_prev_sample = scheduler.step(residual, sample, t)
Patrick von Platen's avatar
Patrick von Platen committed
230
231

            if t > 0:
232
                noise = self.dummy_sample_deter
Patrick von Platen's avatar
Patrick von Platen committed
233
                variance = scheduler.get_variance(t) ** (0.5) * noise
Patrick von Platen's avatar
Patrick von Platen committed
234

235
            sample = pred_prev_sample + variance
Patrick von Platen's avatar
Patrick von Platen committed
236

237
238
        result_sum = np.sum(np.abs(sample))
        result_mean = np.mean(np.abs(sample))
Patrick von Platen's avatar
Patrick von Platen committed
239

Patrick von Platen's avatar
Patrick von Platen committed
240
241
        assert abs(result_sum.item() - 732.9947) < 1e-2
        assert abs(result_mean.item() - 0.9544) < 1e-3
Patrick von Platen's avatar
Patrick von Platen committed
242

Patrick von Platen's avatar
update  
Patrick von Platen committed
243

Patrick von Platen's avatar
Patrick von Platen committed
244
245
246
class DDIMSchedulerTest(SchedulerCommonTest):
    scheduler_classes = (DDIMScheduler,)
    forward_default_kwargs = (("num_inference_steps", 50), ("eta", 0.0))
Patrick von Platen's avatar
update  
Patrick von Platen committed
247

Patrick von Platen's avatar
Patrick von Platen committed
248
249
250
251
252
253
    def get_scheduler_config(self, **kwargs):
        config = {
            "timesteps": 1000,
            "beta_start": 0.0001,
            "beta_end": 0.02,
            "beta_schedule": "linear",
Patrick von Platen's avatar
Patrick von Platen committed
254
            "clip_sample": True,
Patrick von Platen's avatar
Patrick von Platen committed
255
        }
Patrick von Platen's avatar
Patrick von Platen committed
256

Patrick von Platen's avatar
Patrick von Platen committed
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
        config.update(**kwargs)
        return config

    def test_timesteps(self):
        for timesteps in [1, 5, 100, 1000]:
            self.check_over_configs(timesteps=timesteps)

    def test_betas(self):
        for beta_start, beta_end in zip([0.0001, 0.001, 0.01, 0.1], [0.002, 0.02, 0.2, 2]):
            self.check_over_configs(beta_start=beta_start, beta_end=beta_end)

    def test_schedules(self):
        for schedule in ["linear", "squaredcos_cap_v2"]:
            self.check_over_configs(beta_schedule=schedule)

272
    def test_clip_sample(self):
Patrick von Platen's avatar
Patrick von Platen committed
273
274
        for clip_sample in [True, False]:
            self.check_over_configs(clip_sample=clip_sample)
Patrick von Platen's avatar
Patrick von Platen committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

    def test_time_indices(self):
        for t in [1, 10, 49]:
            self.check_over_forward(time_step=t)

    def test_inference_steps(self):
        for t, num_inference_steps in zip([1, 10, 50], [10, 50, 500]):
            self.check_over_forward(time_step=t, num_inference_steps=num_inference_steps)

    def test_eta(self):
        for t, eta in zip([1, 10, 49], [0.0, 0.5, 1.0]):
            self.check_over_forward(time_step=t, eta=eta)

    def test_variance(self):
        scheduler_class = self.scheduler_classes[0]
Patrick von Platen's avatar
Patrick von Platen committed
290
        scheduler_config = self.get_scheduler_config()
Patrick von Platen's avatar
Patrick von Platen committed
291
292
        scheduler = scheduler_class(**scheduler_config)

Patrick von Platen's avatar
Patrick von Platen committed
293
294
295
296
297
298
        assert np.sum(np.abs(scheduler.get_variance(0, 50) - 0.0)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(21, 50) - 0.14771)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(49, 50) - 0.32460)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(0, 1000) - 0.0)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(487, 1000) - 0.00979)) < 1e-5
        assert np.sum(np.abs(scheduler.get_variance(999, 1000) - 0.02)) < 1e-5
Patrick von Platen's avatar
Patrick von Platen committed
299
300
301
302
303
304
305
306
307
308
309
310

    def test_full_loop_no_noise(self):
        scheduler_class = self.scheduler_classes[0]
        scheduler_config = self.get_scheduler_config()
        scheduler = scheduler_class(**scheduler_config)

        num_inference_steps, eta = 10, 0.1
        num_trained_timesteps = len(scheduler)

        inference_step_times = range(0, num_trained_timesteps, num_trained_timesteps // num_inference_steps)

        model = self.dummy_model()
311
        sample = self.dummy_sample_deter
Patrick von Platen's avatar
Patrick von Platen committed
312
313

        for t in reversed(range(num_inference_steps)):
314
            residual = model(sample, inference_step_times[t])
Patrick von Platen's avatar
Patrick von Platen committed
315

316
            pred_prev_sample = scheduler.step(residual, sample, t, num_inference_steps, eta)
Patrick von Platen's avatar
Patrick von Platen committed
317
318
319

            variance = 0
            if eta > 0:
320
                noise = self.dummy_sample_deter
Patrick von Platen's avatar
Patrick von Platen committed
321
                variance = scheduler.get_variance(t, num_inference_steps) ** (0.5) * eta * noise
Patrick von Platen's avatar
Patrick von Platen committed
322

323
            sample = pred_prev_sample + variance
Patrick von Platen's avatar
Patrick von Platen committed
324

325
326
        result_sum = np.sum(np.abs(sample))
        result_mean = np.mean(np.abs(sample))
Patrick von Platen's avatar
Patrick von Platen committed
327

Patrick von Platen's avatar
Patrick von Platen committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
        assert abs(result_sum.item() - 270.6214) < 1e-2
        assert abs(result_mean.item() - 0.3524) < 1e-3


class PNDMSchedulerTest(SchedulerCommonTest):
    scheduler_classes = (PNDMScheduler,)
    forward_default_kwargs = (("num_inference_steps", 50),)

    def get_scheduler_config(self, **kwargs):
        config = {
            "timesteps": 1000,
            "beta_start": 0.0001,
            "beta_end": 0.02,
            "beta_schedule": "linear",
        }

        config.update(**kwargs)
        return config

    def check_over_configs_pmls(self, time_step=0, **config):
        kwargs = dict(self.forward_default_kwargs)
349
350
        sample = self.dummy_sample
        residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
        dummy_past_residuals = [residual + 0.2, residual + 0.15, residual + 0.1, residual + 0.05]

        for scheduler_class in self.scheduler_classes:
            scheduler_class = self.scheduler_classes[0]
            scheduler_config = self.get_scheduler_config(**config)
            scheduler = scheduler_class(**scheduler_config)
            # copy over dummy past residuals
            scheduler.ets = dummy_past_residuals[:]
            scheduler.set_plms_mode()

            with tempfile.TemporaryDirectory() as tmpdirname:
                scheduler.save_config(tmpdirname)
                new_scheduler = scheduler_class.from_config(tmpdirname)
                # copy over dummy past residuals
                new_scheduler.ets = dummy_past_residuals[:]
                new_scheduler.set_plms_mode()

368
369
            output = scheduler.step(residual, sample, time_step, **kwargs)
            new_output = new_scheduler.step(residual, sample, time_step, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
370
371
372
373
374
375

            assert np.sum(np.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical"

    def check_over_forward_pmls(self, time_step=0, **forward_kwargs):
        kwargs = dict(self.forward_default_kwargs)
        kwargs.update(forward_kwargs)
376
377
        sample = self.dummy_sample
        residual = 0.1 * sample
Patrick von Platen's avatar
Patrick von Platen committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
        dummy_past_residuals = [residual + 0.2, residual + 0.15, residual + 0.1, residual + 0.05]

        for scheduler_class in self.scheduler_classes:
            scheduler_class = self.scheduler_classes[0]
            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)
            # copy over dummy past residuals
            scheduler.ets = dummy_past_residuals[:]
            scheduler.set_plms_mode()

            with tempfile.TemporaryDirectory() as tmpdirname:
                scheduler.save_config(tmpdirname)
                new_scheduler = scheduler_class.from_config(tmpdirname)
                # copy over dummy past residuals
                new_scheduler.ets = dummy_past_residuals[:]
                new_scheduler.set_plms_mode()

395
396
            output = scheduler.step(residual, sample, time_step, **kwargs)
            new_output = new_scheduler.step(residual, sample, time_step, **kwargs)
Patrick von Platen's avatar
Patrick von Platen committed
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

            assert np.sum(np.abs(output - new_output)) < 1e-5, "Scheduler outputs are not identical"

    def test_timesteps(self):
        for timesteps in [100, 1000]:
            self.check_over_configs(timesteps=timesteps)

    def test_timesteps_pmls(self):
        for timesteps in [100, 1000]:
            self.check_over_configs_pmls(timesteps=timesteps)

    def test_betas(self):
        for beta_start, beta_end in zip([0.0001, 0.001, 0.01], [0.002, 0.02, 0.2]):
            self.check_over_configs(beta_start=beta_start, beta_end=beta_end)

    def test_betas_pmls(self):
        for beta_start, beta_end in zip([0.0001, 0.001, 0.01], [0.002, 0.02, 0.2]):
            self.check_over_configs_pmls(beta_start=beta_start, beta_end=beta_end)

    def test_schedules(self):
        for schedule in ["linear", "squaredcos_cap_v2"]:
            self.check_over_configs(beta_schedule=schedule)

    def test_schedules_pmls(self):
        for schedule in ["linear", "squaredcos_cap_v2"]:
            self.check_over_configs(beta_schedule=schedule)

    def test_time_indices(self):
        for t in [1, 5, 10]:
            self.check_over_forward(time_step=t)

    def test_time_indices_pmls(self):
        for t in [1, 5, 10]:
            self.check_over_forward_pmls(time_step=t)

    def test_inference_steps(self):
        for t, num_inference_steps in zip([1, 5, 10], [10, 50, 100]):
            self.check_over_forward(time_step=t, num_inference_steps=num_inference_steps)

    def test_inference_steps_pmls(self):
        for t, num_inference_steps in zip([1, 5, 10], [10, 50, 100]):
            self.check_over_forward_pmls(time_step=t, num_inference_steps=num_inference_steps)

    def test_inference_pmls_no_past_residuals(self):
        with self.assertRaises(ValueError):
            scheduler_class = self.scheduler_classes[0]
            scheduler_config = self.get_scheduler_config()
            scheduler = scheduler_class(**scheduler_config)

            scheduler.set_plms_mode()

448
            scheduler.step(self.dummy_sample, self.dummy_sample, 1, 50)
Patrick von Platen's avatar
Patrick von Platen committed
449
450
451
452
453
454
455
456

    def test_full_loop_no_noise(self):
        scheduler_class = self.scheduler_classes[0]
        scheduler_config = self.get_scheduler_config()
        scheduler = scheduler_class(**scheduler_config)

        num_inference_steps = 10
        model = self.dummy_model()
457
        sample = self.dummy_sample_deter
Patrick von Platen's avatar
Patrick von Platen committed
458
459
460
461

        prk_time_steps = scheduler.get_prk_time_steps(num_inference_steps)
        for t in range(len(prk_time_steps)):
            t_orig = prk_time_steps[t]
462
            residual = model(sample, t_orig)
Patrick von Platen's avatar
Patrick von Platen committed
463

464
            sample = scheduler.step_prk(residual, sample, t, num_inference_steps)
Patrick von Platen's avatar
Patrick von Platen committed
465
466
467
468

        timesteps = scheduler.get_time_steps(num_inference_steps)
        for t in range(len(timesteps)):
            t_orig = timesteps[t]
469
            residual = model(sample, t_orig)
Patrick von Platen's avatar
Patrick von Platen committed
470

471
            sample = scheduler.step_plms(residual, sample, t, num_inference_steps)
Patrick von Platen's avatar
Patrick von Platen committed
472

473
474
        result_sum = np.sum(np.abs(sample))
        result_mean = np.mean(np.abs(sample))
Patrick von Platen's avatar
Patrick von Platen committed
475
476
477

        assert abs(result_sum.item() - 199.1169) < 1e-2
        assert abs(result_mean.item() - 0.2593) < 1e-3