import torch
from torch.autograd import Variable
import torchvision.models

model=torchvision.models.squeezenet1_1(pretrained=True)

x=torch.randn(1,3,100,100)
target_y=6

x_fooling=x
x_fooling=x_fooling.requires_grad_()

while(True):
    
    with torch.no_grad():
        if (torch.argmax(model(x_fooling).squeeze())==target_y):
            break
    
    l=model(x_fooling)[0][target_y]
    l.backward()
    print(i)
    dx=1*x_fooling.grad/x_fooling.grad.norm()
    
    with torch.no_grad():
        x_fooling=x_fooling+dx
    

This does not work either, what is the issue, here? torch.no_grad is used and the leaf of X_fooling should have remained the same.
This works if
X_fooling=X_fooling.requires_grad_()

is added before
While (True)
Why is that?