port inference program from NVIDIA to M4
I have an inference program that runs on NVIDIA-accelerated hardware. What adjustments would be needed to port it to an M4 Mac? It works, but it's painfully slow (about 5x slower than on NVIDIA). Any tips to speed it up?
import lightly_train
from PIL import Image
import numpy as np
model = lightly_train.load_model("exported_best_20251229.pt")
def dinov3_img_seg(path, output_path):
masks = model.predict(path)
tensor = masks
tensor_cpu = tensor.cpu()
array = tensor_cpu.numpy()
array = array.astype(np.uint8)
img = Image.fromarray(array, mode='L')
img.save(output_path)
Hi yfq512! Thank you for opening the issue! I think this issue would be more suitable in this repo https://github.com/lightly-ai/lightly-train/issues
But anyway. You have to make sure that the device being used by the model is the mps device (take a look here)
mps is the equivalent of CUDA for M-series apple devices. It is expected for the model to be slower than a CUDA, since dedicated NVIDIA GPUs are generally much faster.
Let me know if it works for you, or if you have any other question!
Closing this, since it belongs to LightlyTrain and is most likely solved.