Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_devices():
device_str = "cuda" if CONFIG.USE_CUDA else "cpu"
if CONFIG.USE_DEVICE is not None:
device_str = CONFIG.USE_DEVICE
device = torch.device(device_str)
available_devices = 1
if device_str == 'cuda':
available_devices = torch.cuda.device_count()
return device, available_devices
def __init__(self, ds, dynamic_parameters, shape=None, selfaware=False, size_parameters={}, pretrained_net=None):
self.input_size = None
self.output_size = None
self.selfaware = selfaware
# How many devices we can train this network on
self.available_devices = 1
self.max_variance = None
if ds is not None:
self.out_indexes = ds.out_indexes
device_str = "cuda" if CONFIG.USE_CUDA else "cpu"
if CONFIG.USE_DEVICE is not None:
device_str = CONFIG.USE_DEVICE
self.device = torch.device(device_str)
if CONFIG.DETERMINISTIC:
'''
Seed that always has the same value on the same dataset plus setting the bellow CUDA options
In order to make sure pytorch randomly generate number will be the same every time
when training on the same dataset
'''
if ds is not None:
torch.manual_seed(len(ds))
else:
torch.manual_seed(2)
if device_str == 'cuda':
torch.backends.cudnn.deterministic = True
def __init__(self, ds, dynamic_parameters, shape=None, selfaware=False, size_parameters={}, pretrained_net=None):
self.input_size = None
self.output_size = None
self.selfaware = selfaware
# How many devices we can train this network on
self.available_devices = 1
self.max_variance = None
if ds is not None:
self.out_indexes = ds.out_indexes
device_str = "cuda" if CONFIG.USE_CUDA else "cpu"
if CONFIG.USE_DEVICE is not None:
device_str = CONFIG.USE_DEVICE
self.device = torch.device(device_str)
if CONFIG.DETERMINISTIC:
'''
Seed that always has the same value on the same dataset plus setting the bellow CUDA options
In order to make sure pytorch randomly generate number will be the same every time
when training on the same dataset
'''
if ds is not None:
torch.manual_seed(len(ds))
else:
torch.manual_seed(2)
if device_str == 'cuda':
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def get_devices():
device_str = "cuda" if CONFIG.USE_CUDA else "cpu"
if CONFIG.USE_DEVICE is not None:
device_str = CONFIG.USE_DEVICE
device = torch.device(device_str)
available_devices = 1
if device_str == 'cuda':
available_devices = torch.cuda.device_count()
return device, available_devices