diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-12-31 19:33:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-31 19:33:32 +0000 |
commit | be5f1acc8f6e5bfc7f8234fd570d663b2fde9c27 (patch) | |
tree | a07510354ce2dddf0afaf37ba256eba6d820900d /modules/torch_utils.py | |
parent | f3af8c8d04d6be58ddb3b55f77d8006241dca8f6 (diff) | |
parent | 5768afc776a66bb94e77a9c1daebeea58fa731d5 (diff) | |
download | stable-diffusion-webui-gfx803-be5f1acc8f6e5bfc7f8234fd570d663b2fde9c27.tar.gz stable-diffusion-webui-gfx803-be5f1acc8f6e5bfc7f8234fd570d663b2fde9c27.tar.bz2 stable-diffusion-webui-gfx803-be5f1acc8f6e5bfc7f8234fd570d663b2fde9c27.zip |
Merge pull request #14478 from akx/dtype-inspect
Add utility to inspect a model's dtype/device
Diffstat (limited to 'modules/torch_utils.py')
-rw-r--r-- | modules/torch_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/torch_utils.py b/modules/torch_utils.py new file mode 100644 index 00000000..e5b52393 --- /dev/null +++ b/modules/torch_utils.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +import torch.nn + + +def get_param(model) -> torch.nn.Parameter: + """ + Find the first parameter in a model or module. + """ + if hasattr(model, "model") and hasattr(model.model, "parameters"): + # Unpeel a model descriptor to get at the actual Torch module. + model = model.model + + for param in model.parameters(): + return param + + raise ValueError(f"No parameters found in model {model!r}") |