thank you, @smth - but I meant solving the problem, not hiding it. apologies if I weren’t clear.
The idea is that we want to edit a module in the notebook and have pytorch find its source - which normally is not possible since nb is a json file.
Here is a hack I came up with for notebooks:
#cell0
# some code
[...]

#celln:
from torch import nn
class FeatureLoss(nn.Module): [... your code here ...]

#celln+1:
x=_i # this copies the contents of the prev cell verbatim
file = "./feature_loss.py"
with open(file, 'w') as f: f.write(x)
from feature_loss import FeatureLoss

and voila, you can have the cake (edit in the notebook) and eat it too (having the source pytorch can find).
Except you can’t rely on any of the local variables of the notebook unless you pass those as arguments to that auto-saved class.