yinxiangshi
(Haojie Jia(AllonsĪ³))
1
I am trying using mps on the newest version of torch:1.12.0.dev20220518
however, mps does not work.
Here is my code:
a = torch.rand((10000, 1000))
b = torch.rand((1000, 10000))
tic = time.time()
torch.matmul(a, b)
toc = time.time()
print(toc - tic)
print(a.device)
a.to("mps")
b.to("mps")
tic = time.time()
torch.matmul(a, b)
toc = time.time()
print(toc - tic)
print(a.device)
and output:
0.2177259922027588
cpu
0.22797489166259766
cpu
yinxiangshi
(Haojie Jia(AllonsĪ³))
2
Btw my device is M1 with macOS 12.3.
nick_elsey
(Nicholas Elsey)
3
You should assign the device tensor to a variable:
a = a.to(āmpsā)
b = b.to(āmpsā)
yinxiangshi
(Haojie Jia(AllonsĪ³))
5
I upded my code, so here is the res:
This actually works:
a = torch.rand((10000, 500))
b = torch.rand((500, 10000))
tic = time.time()
torch.matmul(a, b)
toc = time.time()
print(toc - tic)
print(a.device)
c = torch.rand((10000, 500)).to("mps")
d = torch.rand((500, 10000)).to("mps")
tic = time.time()
torch.matmul(c, d)
toc = time.time()
print(toc - tic)
print(c.device)
0.13344311714172363
cpu
0.0002028942108154297
mps:0
2 Likes