Introduction
The demand for on-device AI is surging, driven by the need for enhanced privacy, offline accessibility, and reduced operational costs. However, the transition from server-side to edge computing faces significant hurdles. Modern Large Language Models (LLMs) and Diffusion models are often orders of magnitude larger than previous mobile-optimized architectures, frequently exceeding the physical memory limits of consumer devices. Furthermore, the extreme heterogeneity of mobile GPUs—ranging from Qualcomm and Arm to Apple and Intel—makes it difficult to develop high-performance kernels that are universally efficient.
To address these challenges, researchers from Google and Meta have introduced ML Drift, a high-performance inference framework designed to scale large generative models on mobile and laptop GPUs.
The ML Drift Framework
The core philosophy of ML Drift is a shift away from rigid, hardware-specific data structures toward a more flexible, virtualized approach.
Tensor Virtualization
A primary innovation is Tensor Virtualization, which decouples a tensor's logical dimensions from its physical storage layout on the GPU. Instead of forcing a 5D array into a specific memory format, the engine dynamically selects the most efficient physical representation—such as a 2D texture or a 1D buffer—based on the target hardware's characteristics.
Coordinate Translation
To maintain high performance despite this abstraction, ML Drift employs Coordinate Translation. Rather than calculating memory addresses at runtime, the framework bakes the mathematical mapping directly into the shader code during the compilation phase. This "zero-overhead" approach ensures that logical-to-physical mapping does not become a computational bottleneck.
Optimization Strategies
ML Drift implements several advanced techniques to minimize memory usage and maximize throughput.
- Stage-Aware LLM Kernels: LLM inference is split into two distinct phases: the compute-bound Prefill stage and the memory-bandwidth-bound Decode stage. ML Drift utilizes specialized kernels for each, including int8 quantization for prefill, to optimize for the specific bottleneck of each phase.
- Aggressive Memory Reuse: By performing a lifespan analysis of tensors, the framework reuses memory buffers for intermediate activations. This technique reduced the activation memory footprint for Stable Diffusion 1.4 by 93%, from 4.31 GB to just 387 MB.
- Hardware-Specific Tuning: The framework leverages vendor-specific extensions, such as Arm’s specialized matrix-multiplication instructions, to achieve peak performance on diverse chipsets.
Experimental Results
The framework was evaluated across a variety of generative tasks, including image synthesis with Stable Diffusion 1.4 and text generation with models like Llama 3.1 8B and Gemma 2B.
ML Drift demonstrated substantial improvements over existing solutions like llama.cpp and MLC LLM:
- Stable Diffusion 1.4: Achieved a full 512x512 image generation (20 iterations) in 8.97 seconds on an Adreno 750 GPU.
- LLM Throughput: On the Qualcomm Adreno 830, the framework delivered a 5× to 11× speedup in token prefill.
- Large-Scale Viability: Llama 3.1 8B was successfully run on mobile hardware with a decode speed of 12.7 tokens/s, making 8B-parameter models practical for real-time mobile applications.
Conclusion and Future Work
ML Drift represents a significant step forward in making massive generative models accessible on consumer hardware. While it currently faces limitations on desktop GPUs due to the lack of Tensor Core access in OpenCL/WebGPU, its performance on mobile platforms is transformative. Future research will focus on sub-channel quantization, sparsity, and zero-copy buffer optimizations to further push the boundaries of on-device inference.
Summary updated