diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-01 17:01:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-01 17:01:06 +0300 |
commit | 7ba02e0b7cfc85d5d237eba71ab4d66564857d55 (patch) | |
tree | b317227a0e63c42aa8c4b06147761dfd37ae24fc /modules/torch_utils.py | |
parent | be31e7e71a08dc27543d31aa6e6532463ccbf20f (diff) | |
parent | 15156cde18844f459ba101b1356d162aa7f39c47 (diff) |
Merge branch 'dev' into finer-settings-freezing-control
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}") |