Spaces:
Runtime error
Runtime error
Download modules/dml/hijack/utils.py from bilegentile/test: direct link, hf CLI and curl.
- Browser
- Download file 504 Bytes
-
https://huggingface.co/spaces/bilegentile/test/resolve/main/modules/dml/hijack/utils.py
- Command line
-
hf download hf://spaces/bilegentile/test/modules/dml/hijack/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/bilegentile/test/resolve/main/modules/dml/hijack/utils.py
504 Bytes
| import torch | |
| from typing import Callable | |
| from modules.shared import log, opts | |
| def catch_nan(func: Callable[[], torch.Tensor]): | |
| if not opts.directml_catch_nan: | |
| return func() | |
| tries = 0 | |
| tensor = func() | |
| while tensor.isnan().sum() != 0 and tries < 10: | |
| if tries == 0: | |
| log.warning("NaN is produced. Retry with same values...") | |
| tries += 1 | |
| tensor = func() | |
| if tensor.isnan().sum() != 0: | |
| log.error("Failed to cover NaN.") | |
| return tensor | |