'torch' is not defined - week 2, lab 2. How to fix?

Got stuck while setting up for lab 2 of week 2. Didn’t see any issues with torch when doing the pip install but later on when loading the model, in referencing ‘torch.bfloat16’
original_model = AutoModelForSeq2SeqLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
got this error -

NameError Traceback (most recent call last)
Cell In[11], line 3
1 model_name=‘google/flan-t5-base’
----> 3 original_model = AutoModelForSeq2SeqLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
4 tokenizer = AutoTokenizer.from_pretrained(model_name)

NameError: name ‘torch’ is not defined

How do I fix this?

Did you imported the library?

It appears to be as part of the pip install lines in the notebook.
%pip install --disable-pip-version-check
torch==1.13.1
torchdata==0.5.1 --quiet

did you tried to import torch?

Those lines are just for downloading

import torch

I think I had imported but I did the process all over again (in a new AWS session) and it worked fine this time. Thanks @pastorsoto!

1 Like