Closed brando90 closed 2 years ago
I don't think there is a side effect (unless it's a PyTorch-side problem), but you can clear it after computing CCA.
I don't think there is a side effect (unless it's a PyTorch-side problem), but you can clear it after computing CCA.
So if I call the above cxa_dist
twice (i.e. calling your jupyter note book code twice in a row) create any problems? In my case I have a loop accross your basic anatome 101 code snippt (which I wrapped in the cxa_dist
)
The snipit I mean is essentially the same as the code above:
from anatome import SimilarityHook
model = resnet18()
hook1 = SimilarityHook(model, "layer3.0.conv1")
hook2 = SimilarityHook(model, "layer3.0.conv2")
model.eval()
with torch.no_grad():
model(data[0])
# downsampling to (size, size) may be helpful
hook1.distance(hook2, size=8)
I think hook1.clear()
is needed, or it keeps collecting tensors. So yes it does have side effects.
@moskomule can we put the hook1.clear()
in the readme tutorial? otherwise OOMs happen since the hooks collect tensors without stop.
I will try really hard to make this my last question, and I won't bother you again. Do we need to do some sort of clearing after we call
hook.distance
in anatome? (or deep copy the models for the code to work properly)?e.g. modification based on your tutorial: