Lesson 7 official topic

I’m not familiar with F1ScoreMulti but just noticing differences two your function and the code in cells 15,16,17

  • “all_metrics” is a tuple, so try: metrics=(f1Score_Multi)
  • Cell 15 passes a subset of the input input[:,:10] to error_rate()

The first few hits in the following search also look promising…
F1ScoreMulti classification metrics can’t handle a mix of multi-label-indicator and continuous-multioutput targets

Note that that’s not a tuple either! You need a comma: metrics=(f1Score_Multi,)

2 Likes

The links for “Label Smoothing Explained using Microsoft Excel” from the forum post and course website are outdated, here’s the updated link:

1 Like

thanks. I’ve updated the link at the top of this post now.

anyone tried Multi-Target classification with Titanic dataset. I am not able to correctly pass in the customized loss function trying to predict Survived and Pclass at the same time. Any notebooks where this has been tried and worked?

I got the same error. Issue was that newer timm library was getting installed that didn’t seem to be compatible with the notebook. Setting the timm library to the exact version fixed the issue for me (though session has to be restarted for it to work, just rerunning this code won’t overwrite the library with the older version)

Change:
path = setup_comp(comp, install=‘fastai “timm>=0.6.2.dev0”’)

path = setup_comp(comp, install=‘fastai “timm==0.6.2.dev0”’)

2 Likes

Great job fixing this, I was struggling with it this morning and wondering why Kaggle wasn’t playing nice!

@jeremy is it worth updating the Kaggle noetbooks for the course?

Hi there,

Im running the notebook in Kaggle for Road to the Top, Part 3 and running into an issue when running the ‘swinv2_large_window12_192_22k’ model.

train(‘swinv2_large_window12_192_22k’, 192, epochs=1, accum=2, finetune=False)
report_gpu()

Getting the below error after running this cell:

:RuntimeError: running_mean should contain 12 elements not 3072

Any help would be much appreciated?

Many thanks,
Ross

I am having the same error right now. I installed wwf following some advice from Github but it didn’t function. What should I do?

Hi guys,
I’m in lesson 7, and finally i’m encountering an error. I’m in Scaling up Part 3 notebook. and can’t get the memory usage with code Jeremy provided.
I’m running WSL2 in mamba venv

My error is with print(torch.cuda.list_gpu_processes())

TypeError Traceback (most recent call last)
Cell In[43], line 1
----> 1 print(torch.cuda.list_gpu_processes())

File ~/mambaforge/envs/fastaienv/lib/python3.10/site-packages/torch/cuda/memory.py:598, in list_gpu_processes(device)
596 lines.append(“no processes are running”)
597 for p in procs:
→ 598 mem = p.usedGpuMemory / (1024 * 1024)
599 lines.append(f"process {p.pid:>10d} uses {mem:>12.3f} MB GPU memory")
600 return “\n”.join(lines)

TypeError: unsupported operand type(s) for /: ‘NoneType’ and ‘int’

When i check torch.cuda.is_available() True
and torch.cuda.current_device() 0
Any ideas?

When i modify code it runs fine, except i see no efficiency gains with gradient accumulation.
So i’m wondering if something is off with my setup or something is not calculating correctly?

Here’s the modified code that runs.
def report_gpu_updated():
print(f’Total GPU Memory: {torch.cuda.get_device_properties(0).total_memory / (10242):.2f} MB’)
print(f’Used GPU Memory: {torch.cuda.memory_allocated(0) / (1024
2):.2f} MB’)
print(f’Cached GPU Memory: {torch.cuda.memory_reserved(0) / (1024**2):.2f} MB’)
gc.collect()
torch.cuda.empty_cache()
report_gpu_updated()

convnext_small_in22k
accum = 1 Used GPU Memory: 16.25 MB
accum = 2 Used GPU Memory: 814.71 MB
accum =4: Used GPU Memory: 800.23 MB

for vit_large_patch16_224 example with accum =2
Used GPU Memory: 4654.58 MB
Does this look right?

Thanks in advance

I also got an error for last 2 models:

swinv2_large_window12_192_22k
RuntimeError: running_mean should contain 12 elements not 3072

and
swin_large_patch4_window7_224
RuntimeError: running_mean should contain 14 elements not 3072

Did you figure out what was wrong?

@jeremy Why did you choose 5e-3 as the learning rate in fit_one_cycle() in the “Collaborative filtering deep dive” notebook? This number seems magical to me. Can you help me understand how you arrived at it?

Another question I have about the “Collaborative filtering deep dive” notebook is:
Why does the collaborative filtering model built with fastai’s collab_learner outperform the deep learning model built with the CollabNN class? It seems to perform even worse when I add the extra hidden layers as such

learn = collab_learner(dls, use_nn=True, y_range=(0, 5.5), layers=[100,50])
learn.fit_one_cycle(5, 5e-3, wd=0.1)

Hey lesson 7 crew.
I published a quick recap of this lesson along with a quiz (questions I created myself).
Also included is my per-lesson tenacious animal for your viewing pleasure :smile_cat:

I was trying to implement multi-target classification with the titanic dataset, I seem to be getting two different predictions, but something doesn’t seem quite right about how I’ve tried to implement it, but cant quite figure out what.

Hi,

The first thing we can do to make this model a little bit better is to force those predictions to be between 0 and 5. For this, we just need to use sigmoid_range , like in <>. One thing we discovered empirically is that it’s better to have the range go a little bit over 5, so we use (0, 5.5):

This is snippet from 08_collab, from where do we arrive at 5 ? What does that range mean ?

The code related to the snippet.

class DotProduct(Module):
def init(self, n_users, n_movies, n_factors, y_range=(0,5.5)):
self.user_factors = Embedding(n_users, n_factors)
self.movie_factors = Embedding(n_movies, n_factors)
self.y_range = y_range

def forward(self, x):
    users = self.user_factors(x[:,0])
    movies = self.movie_factors(x[:,1])
    return sigmoid_range((users * movies).sum(dim=1), *self.y_range)

Thanks

That 5 corresponds to the maximum rating of 5 that someone can give a movie. I found a snippet in the lesson 7 video where he talks about it. Since sigmoid never outputs 1 (except at positive infinity), the maximum value of the range is 5.5 so that a sigmoid output of 5 is possible.

1 Like

I loved lesson 7! A bit bummed I discovered this course 1-2 years late, but better now than never :). Anyways I wanted to extend this method to produce personalized recommendations for me, based on the movie ratings I noted in letterboxd for the movies that are part of the data set. If anyone is curious: Kaggle notebook, writeup. Thanks a lot for the amazing course !

2 Likes

Hi, great lesson!
I am doing collaborative filtering with anime dataset.
First, I created a model and exported it as pkl.
Next I created app.py file with dls, learn (from my .pkl) and defined function:
def find_similar_animes(anime_name, learn, dls, top_n=5) …
where anime_name should be selected from the list (name of the anime from anime dataframe).
the output of find_similar_anime function is

similar_animes = [dls.classes[‘name’][i] for i in top_indices].

When I provide anime name to anime_name and run it in notebook -I am getting the result - 5 similar animes:

anime_name = “Durarara!!”
similar_animes = find_similar_animes(anime_name, learn, dls)
print(f"Top 5 similar animes to ‘{anime_name}’:“)
for i, movie in enumerate(similar_animes, 1):
print(f”{i}. {movie}").

The output is:
Top 5 similar animes to ‘Durarara!!’:

  1. Gintama Movie: Shinyaku Benizakura-hen
  2. Haikyuu!! Second Season
  3. Major S1
  4. Gin no Saji
  5. Steins;Gate: Kyoukaimenjou no Missing Link - Divide By Zero.

Which is great! I stumble into an issue when trying to create Gradio interface.

interface = gr.Interface(
fn=find_similar_animes,
inputs=gr.Dropdown(choices=list(anime[‘name’]), label=“Select Anime”),
#learn = load_learner(model),
#dls = CollabDataLoaders.from_df(ratings, item_name=‘name’, bs=64),
outputs = gr.Textbox(),
title=“Find Similar Animes”,
description=“Select an anime from the dropdown list to find similar animes.”
)
interface.launch()

The gradio creates interface, where I can pick anime name from the drop down, but the output shows an error:

How can I define the output, so it is displayed as a list of recommended animes?

It’s been just 11 min out of allocated 30 Hours. That I got an error stating:
“OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB. GPU 0 has a total capacty of 14.75 GiB of which 1.06 MiB is free. Process 2355 has 14.74 GiB memory in use. Of the allocated memory 14.50 GiB is allocated by PyTorch, and 62.92 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF”.

I have just trained 2 models with Images size of 1000 and epoch = 1 . GPU was T4*2.