Skip to content

Change fp16 error to warning #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/diffusers/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ def to(self, torch_device: Optional[Union[str, torch.device]] = None):
module = getattr(self, name)
if isinstance(module, torch.nn.Module):
if module.dtype == torch.float16 and str(torch_device) in ["cpu", "mps"]:
raise ValueError(
"Pipelines loaded with `torch_dtype=torch.float16` cannot be moved to `cpu` or `mps` "
"due to the lack of support for `float16` operations on those devices in PyTorch. "
"Please remove the `torch_dtype=torch.float16` argument, or use a `cuda` device."
logger.warning(
"Pipelines loaded with `torch_dtype=torch.float16` cannot run with `cpu` or `mps` device. It"
" is not recommended to move them to `cpu` or `mps` as running them will fail. Please make"
" sure to use a `cuda` device to run the pipeline in inference. due to the lack of support for"
" `float16` operations on those devices in PyTorch. Please remove the"
" `torch_dtype=torch.float16` argument, or use a `cuda` device to run inference."
)
module.to(torch_device)
return self
Expand Down
11 changes: 0 additions & 11 deletions tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,6 @@ def to(self, device):

return extract

def test_pipeline_fp16_cpu_error(self):
model = self.dummy_uncond_unet
scheduler = DDPMScheduler(num_train_timesteps=10)
pipe = DDIMPipeline(model.half(), scheduler)

if str(torch_device) in ["cpu", "mps"]:
self.assertRaises(ValueError, pipe.to, torch_device)
else:
# moving the pipeline to GPU should work
pipe.to(torch_device)

def test_ddim(self):
unet = self.dummy_uncond_unet
scheduler = DDIMScheduler()
Expand Down