Hi Johannes!



 Johannes_L:

if loss.cpu().data.numpy()[0] > 10000:

What is the loss.data doing? Somehow relating the loss to the input data?


I’m not sure specifically what you’re asking, but here are some
comments:
In loss.cpu().data, data is a deprecated property that was used
to unwrap a Tensor from a Variable.  (I believe this was prior to
pytorch version 0.4.0.)
It’s just a coincidence that the character string “data” in
loss.cpu().data happens to match that in self.model(data).
The two are used in different contexts, so the same character string
is allowed to refer to two different completely unrelated things.
In general, the line:
if loss.cpu().data.numpy()[0] > 10000:

seems to be garbled overkill.  There is no need to retrieve the loss
value from the gpu or convert it to numpy to perform the > test.
In current versions of pytorch:
if  loss > 10000:

suffices.
In old (pre-0.4.0?) versions you have to unwrap the Tensor from the
Variable, and extract the python non-Tensor value from the Tensor.
Either:
if  loss.data[0] > 10000:

or:
if  (loss > 10000).data[0]:

works.
Best.
K. Frank