Commit 9c8075ba authored by w-e-w's avatar w-e-w

torch_utils.float64

return torch.float64 if device is not mps or xpu, else return torch.float32
parent ddb28b33
from __future__ import annotations from __future__ import annotations
import torch.nn import torch.nn
import torch
def get_param(model) -> torch.nn.Parameter: def get_param(model) -> torch.nn.Parameter:
...@@ -15,3 +16,11 @@ def get_param(model) -> torch.nn.Parameter: ...@@ -15,3 +16,11 @@ def get_param(model) -> torch.nn.Parameter:
return param return param
raise ValueError(f"No parameters found in model {model!r}") 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"""
match t.device.type:
case 'mps', 'xpu':
return torch.float32
return torch.float64
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment