aboutsummaryrefslogtreecommitdiff
path: root/modules/torch_utils.py
diff options
context:
space:
mode:
authorwangshuai09 <391746016@qq.com>2024-01-30 19:15:41 +0800
committerGitHub <noreply@github.com>2024-01-30 19:15:41 +0800
commit74ff85a1a1ee4cce432b1c7d33c1eda831f68d48 (patch)
tree99b70e0fef8422c8f603bf7faa1a393091cb2a8b /modules/torch_utils.py
parentec124607f47371a6cfd61a795f86a7f1cbd44651 (diff)
parentce168ab5dbc8b54b7245f352a2eaa55a37019b91 (diff)
Merge branch 'dev' into npu_support
Diffstat (limited to 'modules/torch_utils.py')
-rw-r--r--modules/torch_utils.py17
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}")