1. 初始化代码;
This commit is contained in:
17
tools/devices.py
Normal file
17
tools/devices.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from functools import cached_property
|
||||
|
||||
|
||||
class DeviceManager(object):
|
||||
|
||||
def __init__(self):
|
||||
self.device = self.__get_device()
|
||||
|
||||
@staticmethod
|
||||
def __get_device():
|
||||
if torch.cuda.is_available():
|
||||
return torch.device('cuda:0')
|
||||
if torch.backends.mps.is_available():
|
||||
return torch.device('mps')
|
||||
return torch.device('cpu')
|
||||
Reference in New Issue
Block a user