mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-11-21 03:11:40 +08:00
9e60cdbc3f
Sole usage of Python 3.10's match-case in the project hinders quick-start for beginners; consider replacing with if-else for improved accessibility.
26 lines
684 B
Python
26 lines
684 B
Python
from __future__ import annotations
|
|
|
|
import torch.nn
|
|
import torch
|
|
|
|
|
|
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}")
|
|
|
|
|
|
def float64(t: torch.Tensor):
|
|
"""return torch.float64 if device is not mps or xpu, else return torch.float32"""
|
|
if t.device.type in ['mps', 'xpu']:
|
|
return torch.float32
|
|
return torch.float64
|