Black box

This commit is contained in:
2026-07-08 13:55:02 +02:00
parent 945d0298d0
commit 90e33f074d
2 changed files with 20 additions and 74 deletions

View File

@@ -165,65 +165,6 @@ def log_metrics(evaluation_domains, reloaded, strategy_in_use):
strategy=strategy_in_use
)
# performs MIA and ZRF attack on models and logs the results
def run_unlearning_and_attack_eval(forget_train_loader, retain_test_loader, reloaded, strategy_in_use, suite_runner, device, forget_class):
"""
Performs adversarial vulnerability stress tests (MIA and ZRF) in-memory
on the freshly unlearned model instance without saving it to disk first.
"""
if suite_runner is None:
raise ValueError("An active initialized UnlearningAttackSuite instance must be supplied.")
print(f"\n>>> Initializing Threat Model Stress Testing Suite for: {strategy_in_use}")
# 1. Dynamically map the white-box feature extraction hook to the active inner model
suite_runner.register_model_hook(reloaded.model)
# 2. Fire the complete evaluation suite using the isolated data split subsets
results = suite_runner.run_complete_evaluation(
target_class=forget_class,
framework_name=strategy_in_use,
forget_loader=forget_train_loader, # Members split from the train data partition
retain_test_loader=retain_test_loader, # Clean non-members split from validation data
device=device
)
print(f" [Attack Complete] Logit MIA AUC: {results['logit_mia_auc']:.4f} | "
f"Internal MIA AUC: {results['internal_mia_auc']:.4f} | "
f"ZRF Score: {results['zrf_score']:.4f}")
# performs MIA and ZRF attack on models and logs the results
def run_shaddow_attack_eval(forget_train_loader, retain_test_loader, reloaded, strategy_in_use, suite_runner, device, forget_class):
"""
Performs adversarial vulnerability stress tests matching the localized
shadow architecture specifications laid out in thesis Section 5.5.
"""
if suite_runner is None:
raise ValueError("An active initialized UnlearningAttackSuite instance must be supplied.")
print(f"\n>>> Initializing Threat Model Stress Testing Suite for: {strategy_in_use}")
# Instantiate a clean copy of the baseline trained model to serve as the Shadow reference proxy
# (Since finetuning is done once, we read its parameters cleanly from disk)
base_shadow = Model.create(arch=ARCH, device=device, size=CLASS_SIZE)
base_shadow.load(arch=ARCH)
# Execute the updated conditional attack framework
results = suite_runner.run_complete_evaluation(
framework_name=strategy_in_use,
target_class=forget_class,
forget_loader=forget_train_loader,
retain_test_loader=retain_test_loader,
unlearned_instance=reloaded, # The unlearned candidate model
base_shadow_instance=base_shadow, # The shadow proxy architecture
device=device
)
print(f" [Attack Complete] Adversary Binary Classification Accuracy: {results['mia_accuracy']:.4f}")
# Unlearning and strategy eval
def run_unlearning_and_strategy_eval(env_dict, forget_class_idx, strategy, evaluate = False, suite_runner=None):
"""
@@ -393,8 +334,8 @@ if __name__ == "__main__":
#dist_attacker.run_adversarial_evaluation()
#dist_attacker.run_incremental_evaluation(current_class_step=i)
if suite_runner is not None:
suite_runner.shutdown_hook()
#if suite_runner is not None:
#suite_runner.shutdown_hook()
except KeyboardInterrupt:
print("\nprogram interrupted. Exit!")