Abstract
While Transformer models have set new benchmarks in Natural Language Processing (NLP) and Computer Vision, their susceptibility to adversarial attacks remains a critical concern. Formal verification provides a mathematical guarantee of robustness, yet existing tools struggle with the immense computational overhead of "bound-centric" arithmetic. This paper introduces Faith, a specialized framework designed to accelerate Transformer verification on GPUs. By leveraging semantic-aware graph transformations, specialized kernel crafting, and expert-guided autotuning, Faith achieves up to a 3.4x speedup over state-of-the-art verifiers and significantly outperforms general-purpose deep learning compilers.
Introduction
As Transformers are increasingly deployed in safety-critical applications, ensuring their reliability against adversarial perturbations is paramount. For instance, a minor synonym swap in a sentiment analysis task—changing "cold" to "frigid"—should not flip a model's prediction. Formal verification addresses this by proving that no perturbation within a defined bound $\epsilon$ can alter the output.
However, this process is computationally expensive. Current verification frameworks typically rely on general-purpose libraries like PyTorch or compilers like TVM. These tools are optimized for standard matrix multiplications rather than the unique requirements of verification math, which involves tracking dual inequality bounds (upper and lower) for every neuron. This mismatch results in significant memory overhead and underutilization of GPU resources. Faith was developed to bridge this gap by treating verification as a specialized workload requiring custom optimization.
The Challenge: Bound-Centric Computation
Transformer verification relies on linear bound propagation, which requires maintaining pairs of bounds. Standard deep learning operations are "value-centric," but verification is "bound-centric." This leads to two primary inefficiencies in traditional frameworks:
- Redundant Memory Access: Standard verifiers often split weight matrices into positive and negative components to maintain inequality logic, effectively doubling the data loaded from memory.
- Semantic Blindness: General compilers do not recognize the relationship between upper and lower bound tensors, failing to fuse operations that share the same input data.
The Faith Framework
Faith addresses these inefficiencies through a three-tiered optimization strategy:
1. Semantic-aware Computation Graph Transformation
Faith optimizes the computation graph by recognizing the mathematical structure of verification.
- Weight-pairing Fusion: Instead of splitting weights into two matrices, Faith loads the weights once and handles sign-based logic at the GPU register level, reducing memory traffic.
- Double-bound Fusion: By recognizing that upper and lower bounds share input data, Faith fuses their calculation into a single pass, maximizing data reuse.
2. Verification-specialized Kernel Crafter
To maximize hardware utilization, Faith employs custom GPU kernels:
- Workload-adaptive Reduction: Utilizing high-speed GPU warp primitives (
_shfl_down_sync), Faith accelerates "concretization"—the process of collapsing abstract bounds into concrete values. - Sharing-oriented Scheduling: Intermediate bound weights are cached in shared memory to eliminate redundant reads from global memory.
- Broadcast-aware Super Threading: This technique optimizes dot-product operations by broadcasting scalars across threads, significantly increasing parallelism.
3. Expert-guided Autotuning
Rather than relying solely on black-box machine learning for optimization, Faith uses a Rule-based Expert Knowledge Metafile. This metafile incorporates hardware-specific constraints (such as maximum registers per thread) to prune the search space. An XGBoost-based cost model then identifies the most efficient execution schedule within these optimized boundaries.
Experimental Evaluation
Faith was evaluated on NVIDIA A100 and V100 GPUs using standard NLP benchmarks: the Stanford Sentiment Treebank (SST) and Yelp datasets. The models tested included Transformers ranging from 1 to 6 layers.
Key Results
- Superior Speed: Faith achieved a 2.1x to 3.4x speedup (averaging 2.6x) compared to the state-of-the-art CROWN/Auto-LiRPA verifier.
- Compiler Comparison: Faith outperformed general compilers significantly, running 17.2x faster than TVM and 15.9x faster than Ansor on matrix multiplication verification tasks.
- Latency Reduction: For a 6-layer Transformer on the SST dataset, Faith reduced the verification latency from 37 seconds to approximately 15 seconds.
Discussion and Insights
The development of Faith revealed that the primary bottleneck in Transformer verification is memory bandwidth, not raw floating-point operations (FLOPs). By prioritizing data reuse in registers and shared memory over arithmetic simplification, Faith overcomes the "sparsity trap" created by traditional weight-splitting methods.
Furthermore, the results demonstrate that general-purpose compilers are currently insufficient for verification tasks because they lack "verifier-awareness." Specialized frameworks that understand the semantic relationship between bound tensors are necessary for making formal verification practical for real-world deployment.
Conclusion and Future Work
Faith represents a significant step toward making Transformer verification a standard part of the machine learning pipeline. While the current implementation focuses on NLP tasks, the underlying principles are applicable to Computer Vision Transformers (ViTs). Future research will explore extending Faith to a wider variety of neural layers and integrating these optimized kernels into the training process to facilitate the creation of inherently robust models.
Summary updated