-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a check and explanation for tensor with all NaNs.
- Loading branch information
1 parent
52f6e94
commit 9991967
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,33 @@ def autocast(disable=False): | |
return torch.autocast("cuda") | ||
|
||
|
||
class NansException(Exception): | ||
pass | ||
|
||
|
||
def test_for_nans(x, where): | ||
from modules import shared | ||
|
||
if not torch.all(torch.isnan(x)).item(): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AUTOMATIC1111
Author
Owner
|
||
return | ||
|
||
if where == "unet": | ||
message = "A tensor with all NaNs was produced in Unet." | ||
|
||
if not shared.cmd_opts.no_half: | ||
message += " This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try using --no-half commandline argument to fix this." | ||
|
||
elif where == "vae": | ||
message = "A tensor with all NaNs was produced in VAE." | ||
|
||
if not shared.cmd_opts.no_half and not shared.cmd_opts.no_half_vae: | ||
message += " This could be because there's not enough precision to represent the picture. Try adding --no-half-vae commandline argument to fix this." | ||
else: | ||
message = "A tensor with all NaNs was produced." | ||
|
||
raise NansException(message) | ||
|
||
|
||
# MPS workaround for https://github.com/pytorch/pytorch/issues/79383 | ||
orig_tensor_to = torch.Tensor.to | ||
def tensor_to_fix(self, *args, **kwargs): | ||
|
@@ -156,3 +183,4 @@ def cumsum_fix(input, cumsum_func, *args, **kwargs): | |
torch.Tensor.cumsum = lambda self, *args, **kwargs: ( cumsum_fix(self, orig_Tensor_cumsum, *args, **kwargs) ) | ||
orig_narrow = torch.narrow | ||
torch.narrow = lambda *args, **kwargs: ( orig_narrow(*args, **kwargs).clone() ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have no idea how to pass this check with test model.
Shouldnt affect performance bcs it would only check that first element is not nan, but can we add a cl arg to disable this?
Alternative way is to download real sd1.5 model with huggingface token in github secrets.