Koukyosyumei / AIJack

Security and Privacy Risk Simulator for Machine Learning (arXiv:2312.17667)
Apache License 2.0
352 stars 62 forks source link

Problem occurred when I run Reconstruct Single Data in Gradient-based Model Inversion Attack against Federated Learning #159

Closed OctopusJIA closed 9 months ago

OctopusJIA commented 11 months ago

I followed the tutorial in the document to run the program,but all four methods in Reconstruct Single Data encounter the same error.

reconstruction_single_sample_bug

_RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retaingraph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.

As described above, This error occurs after the local iteration is complete. Then I checked the code and found the following code in GradientInversion_Attack line306

distance.backward(retain_graph=False)

I don't know if retain_gragph=False is the core cause of this bug, but I really don't have a better solution right now.

Koukyosyumei commented 11 months ago

Thank you for your report. I fixed this bug.