Skip to content

Commit 4553c29

Browse files
authored
[Tests] fix: slow serialization test (#2678)
fix: slow serialization tests
1 parent c9477bf commit 4553c29

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/test_ema.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ class EMAModelTests(unittest.TestCase):
3333
generator = torch.manual_seed(0)
3434

3535
def get_models(self, decay=0.9999):
36-
unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet", device=torch_device)
37-
ema_unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet")
38-
ema_unet = EMAModel(
39-
ema_unet.parameters(), decay=decay, model_cls=UNet2DConditionModel, model_config=ema_unet.config
40-
)
36+
unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet")
37+
unet = unet.to(torch_device)
38+
ema_unet = EMAModel(unet.parameters(), decay=decay, model_cls=UNet2DConditionModel, model_config=unet.config)
4139
return unet, ema_unet
4240

4341
def get_dummy_inputs(self):
@@ -149,6 +147,7 @@ def test_serialization(self):
149147
with tempfile.TemporaryDirectory() as tmpdir:
150148
ema_unet.save_pretrained(tmpdir)
151149
loaded_unet = UNet2DConditionModel.from_pretrained(tmpdir, model_cls=UNet2DConditionModel)
150+
loaded_unet = loaded_unet.to(unet.device)
152151

153152
# Since no EMA step has been performed the outputs should match.
154153
output = unet(noisy_latents, timesteps, encoder_hidden_states).sample

0 commit comments

Comments
 (0)