diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-06-27 05:38:14 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-06-27 05:38:14 +0000 |
commit | 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8 (patch) | |
tree | b0e9b9d93f90b5d50084292a48578bd4f9a83ec6 /modules/devices.py | |
parent | baf6946e06249c5af9851c60171692c44ef633e0 (diff) | |
parent | dbc88c96450793b08b520f3b86cd46d6aeaaae52 (diff) | |
download | stable-diffusion-webui-gfx803-394ffa7b0a7fff3ec484bcd084e673a8b301ccc8.tar.gz stable-diffusion-webui-gfx803-394ffa7b0a7fff3ec484bcd084e673a8b301ccc8.tar.bz2 stable-diffusion-webui-gfx803-394ffa7b0a7fff3ec484bcd084e673a8b301ccc8.zip |
Merge branch 'release_candidate'
Diffstat (limited to 'modules/devices.py')
-rw-r--r-- | modules/devices.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/devices.py b/modules/devices.py index d8a34a0f..1ed6ffdc 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -1,5 +1,7 @@ import sys import contextlib +from functools import lru_cache + import torch from modules import errors @@ -154,3 +156,19 @@ def test_for_nans(x, where): message += " Use --disable-nan-check commandline argument to disable this check." raise NansException(message) + + +@lru_cache +def first_time_calculation(): + """ + just do any calculation with pytorch layers - the first time this is done it allocaltes about 700MB of memory and + spends about 2.7 seconds doing that, at least wih NVidia. + """ + + x = torch.zeros((1, 1)).to(device, dtype) + linear = torch.nn.Linear(1, 1).to(device, dtype) + linear(x) + + x = torch.zeros((1, 1, 3, 3)).to(device, dtype) + conv2d = torch.nn.Conv2d(1, 1, (3, 3)).to(device, dtype) + conv2d(x) |