Issues/Questions with 02_production.ipynb

This is my first post, so I hope I haven’t missed something.

I’m trying to work through Website Lesson 2 / Book Chapter 2 using the 02_production.ipynb notebook from fastbook/02_production.ipynb at master · fastai/fastbook · GitHub.


I thought that when doing any training, fastai/pytorch would use a GPU if available to speed up processing, but when trying to run this code in either Kaggle or Google Collab, it doesn’t seem to use the GPU:

learn = vision_learner(dls, resnet18, metrics=error_rate)

In Kaggle I can see the CPU is pegged, but the GPU shows nothing (Image attached)

In Google Colab, they only show the GPU RAM, but I didn’t see an increase in GPU RAM usage either. Also these runs typically seem to take ~ 30 seconds to run, which isn’t a big deal, but watching the vidoe course, they seem to take significantly less time to run, which also makes me think the GPU isn’t being used. Just curious why.


When running this code:

interp.plot_top_losses(5, nrows=1)

both Kaggle and Google Collab have issues displaying the column headers correctly:

Is there a way to fix this?

Hey @bosatsu,

Welcome to the forums and thanks for posting your question :smiley:, you might want to change the topic from “Site Feedback” to “Part 1 2022” since this relates to the course notebooks

You have to manually enable the GPU in both contexts before they can be used, which is my guess as to why you’re not seeing accelerated performance.

In Colab you can enable it from the “Runtime” menu & “Change Runtime Type” selection, where you can then enable a GPU/TPU.

In kaggle you can follow this discussion guide:

  1. Sign in to kaggle
  2. Open any notebook. On the right-hand side click on the drop down beside “Accelerator”
  3. Select “GPU”
  4. Wait for the kernel to start up

To verify if pytorch is using the GPU, you can checkout this stackoverflow

Here’s the example output and code from the accepted answer:

>>> import torch

>>> torch.cuda.is_available()

>>> torch.cuda.device_count()

>>> torch.cuda.current_device()

>>> torch.cuda.device(0)
<torch.cuda.device at 0x7efce0b03be0>

>>> torch.cuda.get_device_name(0)
'GeForce GTX 950M'

Apologies if you’ve already followed those instructions, let me know what output you get from running the above torch.cuda code and we can see what devices are available and being used.

1 Like

Hey @nglillywhite !

Thanks so much for the response.

I probably should have demonstrated in my post that I had verified that I added a GPU to the runtime environment, but I did do the instructions you provided.

I also tried the code you provided and it does show that there is a GPU available, but it doesn’t really demonstrate whether the GPU is being used by the code. But at this point, this was just a curiosity. Maybe the Kaggle widget for the GPU display isn’t working correctly.

Any thoughts on fixing the display issue I mentioned above when running interp.plot_top_losses(5, nrows=1)?


Apologies to guide you through the GPU activation since you’d already done that, the other check you can look at is to see which device your dataloaders is on by running dls.device. I’m not sure if that is the actual deciding factor as to where your model gets trained but it rules out one other possibility that your dataloaders are on your cpu device instead of an accelerated device.

On the display of the losses with plot_top_losses, you could try play with the figsize, nrows parameters, however I’ve noticed those parameters are only shown/explained in the old docs and I can see **kwargs is in the new api, so it might accept these parameters or not, I haven’t tried it out. If I get time this afternoon I’ll come back and make a snippet to play with.