MergeGuard: Efficient Thwarting of Trojan Attacks in Machine Learning Models

Soheil Zibakhsh Shabgahi, Yaman Jandali, Farinaz KoushanfararXiv 2025 · DOI · arXiv

Abstract

As machine learning models scale, the reliance on third-party pre-trained models and public datasets introduces significant security risks, most notably Trojan (backdoor) attacks. Existing defenses often struggle with computational overhead or fail to generalize to modern architectures like Vision Transformers (ViTs). We present MergeGuard, a novel post-training defense that adaptively linearizes and merges consecutive layers. This approach effectively "cleanses" malicious weights while simultaneously compressing the model. Experimental results demonstrate that MergeGuard reduces the average Attack Success Rate (ASR) on ViTs from 93.52% to 5.21% with significant computational speedups over state-of-the-art methods.

Introduction

The modern machine learning pipeline frequently involves fine-tuning large-scale models pre-trained on massive, often unverified, datasets. This paradigm is vulnerable to Trojan attacks, where an adversary embeds a "backdoor" into the model. Such models perform normally on clean inputs but misclassify inputs containing a specific trigger—for instance, a stop sign with a small sticker being interpreted as a speed limit sign.

While post-training cleansing methods like Neural Cleanse or Fine-Pruning exist, they are often computationally expensive and lack effectiveness against Transformer-based architectures. MergeGuard addresses these gaps by providing an architecture-agnostic, efficient defense mechanism that leverages model compression as a security tool.

Methodology: Security Through Compression

MergeGuard operates by targeting the terminal layers of a network, which are typically the primary sites for Trojan embedding. The process involves three main stages:

  1. Linearization via Regularization: During fine-tuning on a small, clean dataset, a custom regularizer is applied to activation functions (e.g., PReLU, GeLU, SiLU). This forces the activation toward a linear state.
  2. Layer Merging: Once activations between two layers are linearized, the consecutive linear transformations are mathematically collapsed into a single weight matrix.
  3. Cleansing: This structural transformation disrupts the specific neural pathways established by the attacker, effectively removing the Trojan.
The MergeGuard workflow: (a) Trojaned model, (b) Linearization via regularization, (c) Merged layers, (d) Final compressed and cleansed model.

The methodology is model-agnostic; for Convolutional Neural Networks (CNNs), the authors utilize circulant matrices to facilitate merging.

Experimental Results

The efficacy of MergeGuard was evaluated against five prominent Trojan attacks (TrojanNN, WaNet, BadNet, Blended, and SIG) using the CIFAR-10 dataset on both PreAct-ResNet18 and ViT-base-16 architectures.

Security Efficacy on Vision Transformers

Vision Transformers proved particularly vulnerable to Trojans and resistant to standard defenses. MergeGuard significantly outperformed existing methods in this domain. As shown in the table below, MergeGuard (MG) reduced the average ASR to 5.21% while maintaining a high benign test accuracy of 93.21%.

Performance comparison on Vision Transformer (ViT-base-16) across various Trojan attacks.

Computational Efficiency and Compression

MergeGuard offers substantial improvements in processing time. It achieved speedups of 10.6x over Fine-Pruning, 17.7x over Neural Cleanse, and 3.0x over FTSAM. Furthermore, the defense provides inherent model compression; for the ViT model, merging four layers resulted in a 15% reduction in parameter count and a 14% reduction in MAC operations.

Conclusion

MergeGuard represents a significant advancement in model security, demonstrating that architectural compression can serve as a robust defense against Trojan attacks. By adaptively merging layers, it provides a fast, effective, and architecture-agnostic solution, particularly for large-scale Vision Transformers. Future work will focus on automating layer selection and extending the defense to Large Language Models (LLMs).

Summary updated

BibTeX
@misc{shabgahi2025mergeguard,
  author = {Soheil Zibakhsh Shabgahi and Yaman Jandali and Farinaz Koushanfar},
  title = {{MergeGuard: Efficient Thwarting of Trojan Attacks in Machine Learning Models}},
  year = {2025},
  eprint = {2505.04015},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.04015},
}
Figure