mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-08-03 19:02:27 +00:00
Add utility to inspect a model's parameters (to get dtype/device)
This commit is contained in:
17
modules/torch_utils.py
Normal file
17
modules/torch_utils.py
Normal file
@@ -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}")
|
Reference in New Issue
Block a user