Skip to content

Instantly share code, notes, and snippets.

View vadim0x60's full-sized avatar

Vadim Liventsev vadim0x60

View GitHub Profile
const hour_ms = 3600 * 1000
function average(arr) {
sum = null
for (const elem of arr) {
if (elem != null) {
sum += elem
}
}
@vadim0x60
vadim0x60 / torch_device.py
Last active November 20, 2024 12:24
Choose the right Pytorch device always
def torch_device(priority=['xla', 'cuda', 'mps', 'xpu', 'cpu']):
import torch
t = torch.Tensor([0])
for device in map(torch.device, priority):
try:
t.to(device)
return device
except (RuntimeError, AssertionError):
pass