TL;DR
Ditto is a new optimization framework that allows large code-generation models (Code LLMs) to run efficiently on standard laptop CPUs without requiring a GPU. By combining block-wise K-Means weight quantization with an LLVM compiler pass that replaces slow loops with hardware-optimized BLAS library calls, Ditto achieves up to a 10.5× speedup and a 6.4× reduction in memory usage with virtually no loss in coding accuracy.
What Problem Does This Paper Address?
Software developers are increasingly eager to run Code LLMs locally on their personal devices rather than relying on cloud-based APIs like GitHub Copilot. Local execution protects proprietary code privacy, eliminates network latency, and enables offline work.
However, state-of-the-art Code LLMs typically contain billions of parameters, demanding 20 to 30 GB of memory and high-end GPUs to run efficiently. Standard consumer laptops are heavily constrained by limited RAM and lack specialized hardware accelerators. Existing compression methods either degrade model accuracy too severely or fail to optimize the underlying execution code, leaving local CPU performance sluggish and bottlenecked by memory bandwidth.
Methods
Ditto tackles this challenge through a hardware-software co-design approach split into two main phases:
- Weight Quantization (Model Compression): Instead of simple bit-truncation, Ditto uses a 1-D K-Means clustering algorithm at a sub-block level (grouping weights into small blocks of 128 or 256 elements). It maps weights to local "codebooks" and stores them as bit-packed 4-bit indices. To prevent extreme outlier weights from ruining the codebook's resolution, Ditto introduces a magnitude-based scale search that clips weights during clustering but assigns outliers to the closest extremal centroid. It also supports a mixed-precision mode, keeping highly sensitive attention tensors in full float32 precision.
- Compilation-Time Optimization (Program Acceleration): The authors observed that General Matrix-Vector Multiplication (GEMV) operations account for over 80% of an LLM's execution time on a CPU. Ditto integrates a custom compilation pass into LLVM that automatically scans the synthesized C inference program, identifies naive, unoptimized GEMV loops, and replaces them with highly optimized Basic Linear Algebra Subprograms (BLAS) library calls (such as Apple's Accelerate framework or OpenBLAS).
Datasets
The authors evaluated Ditto using two widely recognized code generation benchmarks:
- HumanEval+: An enhanced version of OpenAI's HumanEval dataset, featuring 80× more test cases to rigorously check the functional correctness of Python programs.
- MBPP+: An enhanced version of the Mostly Basic Python Problems dataset, augmented with 35× more test cases.
Key Insights and Ideas
- The Synergy of Quantization and Compilation: Quantization and compiler optimization are usually studied in isolation. Ditto demonstrates that they are deeply synergistic. Quantization drastically reduces memory traffic (the primary bottleneck on CPUs), which in turn allows the compiler-optimized BLAS kernels to achieve much higher hardware utilization and acceleration than they could on uncompressed models.
- Quantization as Regularization: Surprisingly, compressing models to 4-bit configurations occasionally improved single-solution accuracy (e.g., a +1.25% pass@1 improvement for Code Llama-7B). This aligns with machine learning theory suggesting that quantization can act as a mild form of regularization, preventing the model from overfitting to suboptimal code completions.
Key Results
Ditto was evaluated on an Apple M4 CPU with 24GB of RAM across three popular 7B-parameter models: Code Llama, Magicoder, and OpenCodeInterpreter.
- Massive Footprint Reduction: Ditto uniformly reduced peak memory usage by 6.4×, compressing 7B-scale models from ~26 GB down to just ~4.1 GB. This allows these massive models to fit comfortably within standard 8 GB or 16 GB laptop memory budgets.
- Substantial Speedups: Inference throughput saw up to a 10.5× speedup compared to full-precision baselines, dropping latency to a highly responsive 213–286 ms per token.
- Energy Savings: Thanks to faster execution times under identical power draws (18W), energy consumption per token was cut by up to 10.5×.
- Near-Lossless Accuracy: Across all models, Ditto maintained an average pass@1 accuracy loss of only 0.27%. It also comfortably outperformed standard
int8quantization baselines, offering up to 6.96% higher accuracy while being 2.2× faster and using 1.6× less memory.
Limitations and Future Work
Currently, Ditto's inference pipeline is specifically tailored to implementations based on the lightweight llama.c architecture.
To broaden its real-world impact, the authors note that future work will focus on extending Ditto's compiler pass to support more complex and widely adopted frameworks like llama.cpp, PyTorch, and TensorFlow. Additionally, they plan to expand the optimization pass to cover other mathematical kernels beyond GEMV, paving the way for efficient batch processing, encoder-decoder models, and multimodal local LLMs.
Summary updated