Ditto: Quantization-aware Secure Inference of Transformers upon MPC

Haoqi Wu, Wenjing Fang, Yancheng Zheng, Junming Ma, Jin Tan, Lei Wang

TL;DR

Ditto is a new framework that significantly accelerates secure Transformer inference by co-designing quantization-aware distillation with efficient Multi-Party Computation (MPC) primitives. By utilizing MPC-friendly static quantization and novel type-conversion protocols, Ditto achieves up to a 4.40× speedup over previous state-of-the-art methods like MPCFormer while maintaining near-baseline model accuracy.

What Problem Does This Paper Address?

As Transformer models (like BERT and GPT) become ubiquitous, privacy concerns regarding sensitive user prompts and proprietary model weights have skyrocketed. Secure Multi-Party Computation (MPC) offers a solution by allowing multiple parties to compute a function (like model inference) without revealing their private inputs.

However, MPC is notoriously slow. In the "plaintext" world, we use quantization (e.g., converting 32-bit floats to 8-bit integers) to speed up models. But in MPC, standard quantization doesn't work "out of the box." Operations like scaling and clipping—which are nearly free on a CPU—require expensive communication rounds and complex bit-level manipulations in an MPC environment. In fact, these "extra" steps can actually create more communication overhead than the quantization saves.

Methods

The authors propose a two-pronged approach to bridge the gap between quantization and MPC:

High-level workflow of Ditto, showing the distillation and MPC execution phases.
  1. MPC-Friendly Quantization & Distillation: Instead of expensive dynamic quantization, Ditto uses static dyadic quantization. By ensuring scaling factors are powers of two ($1/2^f$), divisions are replaced by simple bit-shifts. To recover the accuracy lost during this aggressive quantization, they employ Quantization-Aware Distillation (QAD), where a full-precision "teacher" model helps a quantized "student" model learn to produce similar hidden states and logits.
  2. Novel MPC Primitives: The framework introduces efficient UpCast and DownCast protocols. These allow the system to switch between low-bitwidth rings (for fast linear algebra) and high-bitwidth rings (for precision-sensitive non-linear functions like Softmax or GeLU) with minimal communication.
  3. End-to-End Framework: Ditto is implemented atop the SecretFlow-SPU framework. It features a compiler that automatically rewrites the model's computation graph to insert these type conversions where needed, seamlessly managing upcasting and downcasting between different bitwidths.

Datasets

The authors evaluated Ditto on standard benchmarks for both encoder and decoder architectures:

  • BERT (Base & Large): Evaluated on the GLUE benchmark, specifically the RTE, CoLA, QQP, and QNLI tasks.
  • GPT2 (Base & Medium): Evaluated on the Wikitext-103 dataset for language modeling performance (Perplexity).

Key Insights and Ideas

  • The "Aha" Moment for Type Conversion: The authors realized that the biggest bottleneck wasn't the math itself, but moving data between different "rings" (bit-widths) in MPC. Their UpCast optimization uses a "positive heuristic trick"—adding a large bias to signed integers—to avoid expensive non-linear comparisons when extending bit-widths.
  • Mixed Precision is Mandatory: Linear layers (the bulk of the work) can survive on 8-bit precision, but non-linear layers like Softmax fail without higher precision. Ditto's ability to seamlessly "upcast" to 64-bit for these sensitive operations is what preserves the model's utility.
  • Static over Dynamic: While dynamic quantization is popular in plaintext for its accuracy, its requirement to find min/max values at runtime is an MPC nightmare. Static quantization, combined with distillation, provides a much better efficiency-accuracy trade-off for secure settings.

Key Results

Ditto demonstrates a superior Pareto frontier for the trade-off between runtime and communication size.

Inference efficiency on Bert-base and GPT2-base with varying input sequence lengths.
  • Speedups: Ditto is 3.14× to 4.40× faster than MPCFormer and 1.44× to 2.35× faster than PUMA.
  • Communication Efficiency: As detailed in the efficiency benchmarks, Ditto consistently requires less data transfer across various input lengths compared to baselines. For BERT-base with an input length of 128, Ditto's communication is ~3.5× lower than the vanilla baseline.
  • Negligible Accuracy Loss: On the QNLI task, BERT-base achieved an accuracy of 91.78% with Ditto, actually slightly outperforming the 91.62% baseline, likely due to the regularization effects of distillation.

Limitations and Future Work

While Ditto is a major step forward, the authors note a few areas for growth:

  • Aggressive Quantization: The current work focuses on 8-bit quantization. Exploring 4-bit or even binary/ternary weights could further reduce overhead but would require even more sophisticated distillation techniques.
  • Distillation Overhead: The model owner must perform a distillation step before deployment. While this is a one-time offline cost, it may be significant for massive models.
  • Output Privacy: The paper focuses on protecting inputs and model weights during inference but does not address "differential privacy" for the final output (e.g., preventing an attacker from inferring training data from the model's answers).

Summary updated

BibTeX
@inproceedings{wu2024ditto,
  author = {Haoqi Wu and Wenjing Fang and Yancheng Zheng and Junming Ma and Jin Tan and Lei Wang},
  title = {{Ditto: Quantization-aware Secure Inference of Transformers upon MPC}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=ZzXNCQGzqT},
}
Figure