You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when gpu is not specified, armory defaults to running the attack on GPU0 and loading some other data onto all other GPUs. It would be useful to be able to launch armory without having to check gpustat.
When gpu is not set to a specific integer value and use_gpu is set to True, utilize the following function to automatically detect the best gpu to use as done elsewhere:
defget_device(device=None) ->torch.device:
""" If None is passed, the GPU with the most free memory will be used. If False is passed, the CPU will be used. Otherwise, the device will be set to the specified GPU. """ifdeviceisFalse:
log.info("Using CPU")
returntorch.device("cpu")
elifdeviceisNone:
# Get the current memory usage of all GPUs using nvidia-smimemory= {
i: int(
os.popen(
f"nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits --id={i}"
).read()
)
foriinrange(torch.cuda.device_count())
}
# Get the GPU with the most free memorydevice=torch.device(f"cuda:{max(memory, key=memory.get)}")
log.info(
f"Autoselected {device} with {memory[device.index]} MB bytes free"
)
returndeviceelse:
try:
returntorch.device(f"cuda:{device}")
exceptExceptionase:
log.error(f"Error setting device to {device}: {e}")
returntorch.device("cpu")
The text was updated successfully, but these errors were encountered:
Currently when gpu is not specified, armory defaults to running the attack on GPU0 and loading some other data onto all other GPUs. It would be useful to be able to launch armory without having to check gpustat.
When gpu is not set to a specific integer value and
use_gpu
is set to True, utilize the following function to automatically detect the best gpu to use as done elsewhere:The text was updated successfully, but these errors were encountered: