0

When i try to import classes from a python file and use them in collab it throws a name error ,but when i copy and paste the same code and run it in a cell in collab it works just fine . the error is very wierd it will always show the same line as the source of the error .. even if it is blank

i've tried fixing the indentation. it does'nt seem to work

  loss = F.nll_loss(output, target)

  if self.targeted:


      loss = -loss
   self.model.zero_grad()

it throws name error at the blank line saying name device is not defined

ashes
  • 45
  • 6
  • Please share a self-contained notebook that reproduces the problem you observe. (There isn't enough context in the original question to diagnose.) – Bob Smith Feb 16 '19 at 15:47

1 Answers1

0

Showing the same error at the same line even after you edit the code (or blank the line) strongly suggests you're not explicitly reloading the module. Python's import system is idempotent meaning that repeatedly calling "import foo" on the same module will have no effect after the first invocation, even if you edit the module's code. Either restart the kernel (cmd/ctrl-m-period) or use reload explicitly (e.g. https://stackoverflow.com/a/437591/8755609)

Ami F
  • 2,202
  • 11
  • 19