Model loaded on GPU but using GPU and CPU both For prediction

hello everyone,

I have trained a vision model on custom data on GPU(NVIDIA GeForce RTX 3060-12gig) using Fastai - 2.5.3. when I deployed that model in production on GPU(tesla 32 gig/ Cuda-10.2) for continuous predictions I noticed that that model is loaded on GPU but using my CPU as well on the server. so I tested that locally and the result was the same it was using both GPU and CPU on prediction.

so my question is. did I miss something or is there any problem with drivers?


here are the screenshots for both GPU and CPU utilization. it can be seen clearly model is using both GPU and CPU

please correct me if I am wrong somewhere.
Thank you

We use CPU for some of the data preprocessing. Can you show what your prediction code is and how you load the model in?

1 Like

@muellerzr thanks for the reply sir,

here is my example code -

torch.cuda.set_device(0)
model = load_learner(f’ai/fastai_recog.pkl’, cpu=False)

image_path = ‘path/to/image.jpg’
if ‘http’ in image_path:
with model.no_bar(): preds = model.predict(requests.get(image_path, stream=True).content)
else:
with model.no_bar(): preds = model.predict(open(image_path, ‘rb’).read())

print(preds)

Your code looks fine. As I said we use the CPU for initial data preprocessing, so it will never be 100% gpu

1 Like

ok Thank you sir @muellerzr :innocent: