lightly icon indicating copy to clipboard operation
lightly copied to clipboard

port inference program from NVIDIA to M4

Open yfq512 opened this issue 6 months ago • 2 comments

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)

yfq512 avatar May 22 '26 01:05 yfq512

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!

gabrielfruet avatar May 27 '26 16:05 gabrielfruet

Closing this, since it belongs to LightlyTrain and is most likely solved.

liopeer avatar Jun 29 '26 14:06 liopeer