diff options
author | Aarni Koskela <akx@iki.fi> | 2023-12-30 22:20:30 +0000 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2023-12-31 11:22:43 +0000 |
commit | 5768afc776a66bb94e77a9c1daebeea58fa731d5 (patch) | |
tree | 06c015a95076b2de579a72750aa7862a9615ed09 /test | |
parent | a84e842189f5599fd354147f72d1a9b9ed0716c8 (diff) | |
download | stable-diffusion-webui-gfx803-5768afc776a66bb94e77a9c1daebeea58fa731d5.tar.gz stable-diffusion-webui-gfx803-5768afc776a66bb94e77a9c1daebeea58fa731d5.tar.bz2 stable-diffusion-webui-gfx803-5768afc776a66bb94e77a9c1daebeea58fa731d5.zip |
Add utility to inspect a model's parameters (to get dtype/device)
Diffstat (limited to 'test')
-rw-r--r-- | test/test_torch_utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/test_torch_utils.py b/test/test_torch_utils.py new file mode 100644 index 00000000..f1aec832 --- /dev/null +++ b/test/test_torch_utils.py @@ -0,0 +1,19 @@ +import types + +import pytest +import torch + +from modules.torch_utils import get_param + + +@pytest.mark.parametrize("wrapped", [True, False]) +def test_get_param(wrapped): + mod = torch.nn.Linear(1, 1) + cpu = torch.device("cpu") + mod.to(dtype=torch.float16, device=cpu) + if wrapped: + # more or less how spandrel wraps a thing + mod = types.SimpleNamespace(model=mod) + p = get_param(mod) + assert p.dtype == torch.float16 + assert p.device == cpu |