评测MLX在苹果芯片上运行Transformer模型的推理速度
Benchmarking On-Device Machine Learning on Apple Silicon with MLX
- 用MLX框架实现多种Transformer模型,直接加载Hugging Face模型
- 在苹果芯片上实测显示,同参数量模型推理延迟低于英伟达显卡
- 适合想在Mac上高效部署AI模型的研究者和开发者
大型语言模型和机器学习的普及推动了在笔记本和手机等小型设备上部署模型的研究。为此,MLX框架应运而生,专为苹果芯片优化,便于研究、实验与原型开发。本文评估了MLX在推理延迟方面的表现,对比了其在MLX中实现的Transformer模型与PyTorch版本的性能。我们构建了MLX-transformers框架,支持从Hugging Face下载PyTorch模型检查点并转换为MLX格式,无需手动转换。实验在两台苹果芯片MacBook上进行,并与英伟达CUDA GPU对比,评估了相同参数量的BERT、RoBERTa和XLM-RoBERTa模型。结果表明,MLX在苹果生态中具备实现高效、可访问的本地化机器学习应用的巨大潜力。
原文摘要 · Abstract (English)
The recent widespread adoption of Large Language Models (LLMs) and machine learning in general has sparked research interest in exploring the possibilities of deploying these models on smaller devices such as laptops and mobile phones. This creates a need for frameworks and approaches that are capable of taking advantage of on-device hardware. The MLX framework was created to address this need. It is a framework optimized for machine learning (ML) computations on Apple silicon devices, facilitating easier research, experimentation, and prototyping. This paper presents a performance evaluation of MLX, focusing on inference latency of transformer models. We compare the performance of different transformer architecture implementations in MLX with their Pytorch counterparts. For this research we create a framework called MLX-transformers which includes different transformer implementations in MLX and downloads the model checkpoints in pytorch and converts it to the MLX format. By leveraging the advanced architecture and capabilities of Apple Silicon, MLX-Transformers enables seamless execution of transformer models directly sourced from Hugging Face, eliminating the need for checkpoint conversion often required when porting models between frameworks. Our study benchmarks different transformer models on two Apple Silicon macbook devices against an NVIDIA CUDA GPU. Specifically, we compare the inference latency performance of models with the same parameter sizes and checkpoints. We evaluate the performance of BERT, RoBERTa, and XLM-RoBERTa models, with the intention of extending future work to include models of different modalities, thus providing a more comprehensive assessment of MLX's capabilities. The results highlight MLX's potential in enabling efficient and more accessible on-device ML applications within Apple's ecosystem.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。