Model parameters created inside torch.inference_mode() are permanently
tainted — even in a new thread, forward() produces inference tensors.
LoadResNet18 now loads the model via _run_in_new_thread so parameters
are normal autograd-compatible tensors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ComfyUI Desktop App wraps node execution in torch.inference_mode(),
which permanently taints tensors — torch.enable_grad() cannot override it.
Solution: run FGSM/PGD gradient computation in a fresh OS thread where
PyTorch's thread-local grad mode starts clean (no inference_mode active).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ComfyUI runs node execution inside torch.no_grad(), which prevents
loss.backward() from building a computation graph. Wrapping the
FGSM and PGD gradient steps with torch.enable_grad() resolves this.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>