Open
Description
🐛 Describe the bug
import time
import torch
from torchvision import models
device = torch.device("mps")
model = models.resnet18()
model.to(device)
model.eval()
for i in range(10):
x = torch.randn(1, 3, 224, 224, device=device)
start = time.perf_counter()
with torch.no_grad():
model(x)
torch.mps.synchronize()
end = time.perf_counter()
print(end - start)
# time.sleep(1) # <--- Cooldown time
Sample output:
- Comment
sleep
0.013851750001776963
0.011806082969997078
0.009203707973938435
0.006015666993334889
0.0059204999706707895
0.00472587498370558
0.004517166991718113
0.0045674999710172415
0.004554332990664989
0.004492584033869207
- Uncomment
sleep
:
0.013814875041134655
0.0132357919937931
0.013537375023588538
0.016312292020302266
0.014802166959270835
0.01544141594786197
0.01633595797466114
0.015492709004320204
0.01755624997895211
0.015840500011108816
Is it expected? And now can I keep the model runs as fast as before sleep
? I remember facing the same problem with CUDA
on Nvidia Jetson, the solution is to use sudo jetson_clocks
. So is there any similar solution to Jetson on macOS.
Versions
OS: macOS 14.4.1 (arm64)
CPU: Apple M2
Python version: 3.10.14 (main, Mar 21 2024, 11:21:31) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-14.4.1-arm64-arm-64bit
[pip3] torch==2.4.0.dev20240331
[pip3] torchaudio==2.2.0.dev20240331
[pip3] torchvision==0.19.0.dev20240331