Unverified Commit 4553c29d authored by Sayak Paul's avatar Sayak Paul Committed by GitHub
Browse files

[Tests] fix: slow serialization test (#2678)

fix: slow serialization tests
parent c9477bf8
...@@ -33,11 +33,9 @@ class EMAModelTests(unittest.TestCase): ...@@ -33,11 +33,9 @@ class EMAModelTests(unittest.TestCase):
generator = torch.manual_seed(0) generator = torch.manual_seed(0)
def get_models(self, decay=0.9999): def get_models(self, decay=0.9999):
unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet", device=torch_device) unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet")
ema_unet = UNet2DConditionModel.from_pretrained(self.model_id, subfolder="unet") unet = unet.to(torch_device)
ema_unet = EMAModel( ema_unet = EMAModel(unet.parameters(), decay=decay, model_cls=UNet2DConditionModel, model_config=unet.config)
ema_unet.parameters(), decay=decay, model_cls=UNet2DConditionModel, model_config=ema_unet.config
)
return unet, ema_unet return unet, ema_unet
def get_dummy_inputs(self): def get_dummy_inputs(self):
...@@ -149,6 +147,7 @@ class EMAModelTests(unittest.TestCase): ...@@ -149,6 +147,7 @@ class EMAModelTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
ema_unet.save_pretrained(tmpdir) ema_unet.save_pretrained(tmpdir)
loaded_unet = UNet2DConditionModel.from_pretrained(tmpdir, model_cls=UNet2DConditionModel) loaded_unet = UNet2DConditionModel.from_pretrained(tmpdir, model_cls=UNet2DConditionModel)
loaded_unet = loaded_unet.to(unet.device)
# Since no EMA step has been performed the outputs should match. # Since no EMA step has been performed the outputs should match.
output = unet(noisy_latents, timesteps, encoder_hidden_states).sample output = unet(noisy_latents, timesteps, encoder_hidden_states).sample
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment