readme.md

December 20, 2025 · View on GitHub

Detecting Backdoor Attacks in Federated Learning via Direction Alignment Inspection

This is the official implementation for CVPR'25 ✨Highlight✨ paper "Detecting Backdoor Attacks in Federated Learning via Direction Alignment Inspection".

You can find the full version of our paper here.

If you found AlignIns is interesting, you may also refer to our other related works on robust federated learning systems:

All these methods are based on simple and effective ideas for protecting federated learning systems. They are easy to implement and can be directly integrated into this codebase or into existing federated learning frameworks.

Usage

If you have any issues using this repo, feel free to contact Jiahao @ jiahaox@unr.edu.

The proposed aggregation rule AlignIns is placed in src/aggregation.py, and you can easily take it and integrate AlignIns with your code.

Environment

Our code does not rely on special libraries or tools, so it can be easily integrated with most environment settings.

If you want to use the same settings as us, we provide the conda environment we used in env.yaml for your convenience.

Dataset

CIFAR-10 and CIFAR-100 datasets are available on torchvision and will be downloaded automatically.

Tiny-ImageNet can be easily downloaded from Kaggle.

Example

Generally, to run a case with default settings, you can easily use the following command:

python federated.py \
--poison_frac 0.3 --num_corrupt 4 \
--aggr alignins --data cifar10 --attack badnet

If you want to run a case with non-IID settings, you can easily use the following command:

python federated.py \
--poison_frac 0.3 --num_corrupt 4 \
--non_iid --beta 0.5 \
--aggr alignins --data cifar10 --attack badnet

Here,

ArgumentTypeDescriptionChoice
aggrstrDefense method applied by the serveravg, alignins, rlr, mkrum, mmetric, lockdown, foolsgold, rfa
datastrMain task datacifar10, cifar100, tinyimagenet
num_agentsintNumber of clients in FLN/A
attackstrAttack methodbadnet, DBA, neurotoxin, pgd
poison_fracfloatData poisoning ratio[0.0, 1.0]
num_corruptintNumber of malicious clients in FL[0, num_agents//2-1]
non_iidstore_trueEnable non-IID settings or notN/A
betafloatData heterogeneous degree[0.1, 1.0]

For other arguments, you can check the federated.py file where the detailed explanation is presented.

Citation

We provide the following BibTeX entry for citation for your convenience.

@InProceedings{Xu_2025_CVPR_AlignIns,
    author    = {Xu, Jiahao and Zhang, Zikai and Hu, Rui},
    title     = {Detecting Backdoor Attacks in Federated Learning via Direction Alignment Inspection},
    booktitle = {Proceedings of the Computer Vision and Pattern Recognition Conference (CVPR)},
    month     = {June},
    year      = {2025},
    pages     = {20654-20664}
}

Acknowledgment

Our code is partially constructed on https://github.com/git-disl/Lockdown, big thanks to their contribution!