Introduction
The rapid advancement of Large Language Models (LLMs) and diffusion models has primarily been confined to cloud environments. However, the "holy grail" of AI deployment is on-device execution, which offers superior privacy, lower latency, and offline capability. The primary obstacle is the "scale gap": modern generative models are often 100x larger than the workloads mobile and laptop GPUs were designed to handle. Furthermore, the fragmentation of GPU APIs—including OpenCL, Metal, Vulkan, and WebGPU—prevents the deployment of highly optimized, cross-platform code.
To address these challenges, we introduce ML Drift, a high-performance inference framework that achieves an order-of-magnitude performance boost over existing engines. By leveraging tensor virtualization and hardware-specific optimizations, ML Drift enables models like Llama 3.1 and Stable Diffusion to run efficiently on consumer-grade mobile and laptop hardware.
Architectural Innovations: Tensor Virtualization
The cornerstone of ML Drift is Tensor Virtualization. This technique decouples the logical representation of a tensor (its mathematical dimensions) from its physical storage on the GPU (e.g., buffers, textures, or arrays).
This abstraction allows the engine to automatically select the most efficient memory layout for a specific chip. For instance, many mobile GPUs feature 4-element SIMD units that perform best with data organized in 4-channel slices. ML Drift can exploit these hardware characteristics across different APIs without requiring manual algorithm rewrites.
Supporting this virtualization is a Coordinate Translation stage in the shader generation process. By mapping logical indices to physical addresses during pre-processing, the framework eliminates runtime overhead while maintaining hardware-optimized layouts. Additionally, ML Drift employs Device Specialization, generating backend-specific shaders (OpenCL, Metal, etc.) that utilize vendor-specific extensions, such as specialized matrix multiplication instructions.
Optimized Inference Strategies
ML Drift implements stage-aware optimizations specifically for LLMs, distinguishing between the "prefill" phase (processing the initial prompt) and the "decode" phase (generating tokens sequentially).
- Prefill: Utilizes compute-heavy convolution kernels and int8 quantization to process large batches of input tokens rapidly.
- Decode: Focuses on memory-bound fully connected kernels. Since the bottleneck here is memory bandwidth, quantization is integrated directly into the operational kernels to maximize throughput.
Furthermore, the framework employs a "Greedy by Size" memory management strategy. For Stable Diffusion 1.4, this approach reduced the runtime memory footprint from 4.31 GB to just 387 MB—a 93% reduction—enabling execution on mid-range mobile devices.
Performance Evaluation
The framework was evaluated using state-of-the-art models including Stable Diffusion 1.4, Gemma 2B, and Llama 3.1 (8B), across a wide array of hardware from Qualcomm, Arm, Intel, NVIDIA, and Apple.
Key results include:
- Stable Diffusion 1.4: Generated a 512x512 image in 8.97 seconds on a Qualcomm Adreno 750 mobile GPU.
- LLM Throughput: On the Snapdragon 8 Elite (Adreno 830), Gemma2 2B achieved a prefill speed of 1220 tokens/s and a decode speed of 20.8 tokens/s.
- Comparative Advantage: ML Drift demonstrated a 5x to 11x speedup in token prefill compared to other open-source solutions on Qualcomm GPUs. On Apple M4 Pro, it outperformed
llama.cppandMLX LLMby 14% and 20%, respectively.
Conclusion and Future Work
ML Drift successfully bridges the scale gap for on-device generative AI. While currently limited by API constraints on desktop GPUs (e.g., OpenCL's lack of full Tensor Core access compared to CUDA), the framework provides a robust path for cross-platform deployment. Future work will focus on sub-channel quantization, model sparsity, and improving "zero-copy" buffer sharing between heterogeneous processors (CPU/GPU/NPU) to further push the boundaries of on-device intelligence.
Summary updated