Name 'torch' is not defined

I did some modifications in TrainingArguments. I commented the max_steps and set training epochs as 2. But when we load this args in Trainer and train the model, it generates this weird error “name torch is not defined” after few steps.

I even tried to reinstall the torch and also tried to restart the runtime. But it won’t work.

Hi @devang_pagare

Welcome to the community.

Are you try to run locally?

No, I haven’t. I tried to run it on the Colab free version with GPU.

This error is very easily reproducible. Please try at your end, I think you’ll also get the same error.

Also, this error can be seen even if you comment on the epochs and set max_steps = 200/400.

Hi @devang_pagare,

Did you execute/run all previous cells sequentially before you try to execute/run this cell.


Yes, I did execute everything before this cell.

And are you sure it is installed in the colab ?

Try to run import torch and see what happens

Did that too, Even when it’s already present in a cell.

I guess I found the answer. The file needs to import torch.

Added one line - import torch in

It’s working now.

1 Like