attck metrics

This commit is contained in:
2026-07-08 00:25:07 +02:00
parent 026ca47800
commit eb8060fc05
37 changed files with 1649 additions and 66 deletions

View File

@@ -43,17 +43,12 @@ class CertifiedUnlearning(Strategy):
InceptionV3 auxiliary layers and tracking gradients.
"""
inner_model = getattr(model, "model", model)
# Check if the current architecture is an Inception variant
is_inception = inner_model.__class__.__name__.lower() == "inception3"
params_list = []
for name, p in inner_model.named_parameters():
if p.requires_grad:
# Discard the disconnected auxiliary training branch weights
if is_inception and "AuxLogits" in name:
continue
# CRITICAL: Append as a tuple so it can be unpacked as (name, param)
# Append as a tuple so it can be unpacked as (name, param)
params_list.append((name, p))
return params_list if named else [e[1] for e in params_list]
@@ -92,7 +87,7 @@ class CertifiedUnlearning(Strategy):
first_grads = grad(loss, params, retain_graph=True, create_graph=True)
elemwise_products = sum(torch.sum(g_elem * v_elem) for g_elem, v_elem in zip(first_grads, v))
return grad(elemwise_products, params, create_graph=False)
def _stochastic_newton_update(self, g, dataset, model, device):
model.eval()
criterion = nn.CrossEntropyLoss()
@@ -133,7 +128,6 @@ class CertifiedUnlearning(Strategy):
h_s = self._hvp(loss, params, h_estimate)
# OPTIMIZATION 4: Avoid deprecated .data, use detach() and in-place ops
with torch.no_grad():
for k in range(len(params)):
h_estimate[k].copy_(h_estimate[k] + g[k] - (h_s[k] / self.scale))
@@ -143,7 +137,7 @@ class CertifiedUnlearning(Strategy):
if global_step % step_interval == 0 and current_pct < 100:
current_pct += 1
print(f"\rProgress: {current_pct}% done", end="", flush=True)
with torch.no_grad():
for k in range(len(params)):
h_res[k] += h_estimate[k] / self.scale