使用 fastsafetensors 加速模型加载
Speeding up Model Loading with fastsafetensors
AI总结:
针对大模型加载慢的问题,提出 Python 库 fastsafetensors,通过直接在设备内存实例化张量并优化 I/O,使 Llama、Falcon 和 Bloom 等模型加载速度提升 4.8 至 7.5 倍。
摘要:
模型参数规模的快速增长给预训练模型加载带来了新挑战。目前,机器学习代码通常在主机内存中将每个参数反序列化为张量对象,然后再将其复制到设备内存。我们发现,这种方法未充分利用存储吞吐量,并显著减慢了使用广泛使用的模型文件格式 safetensors 加载大型模型的速度。在这项工作中,我们提出了 fastsafetensors,这是一个旨在优化 safetensors 文件中张量反序列化的 Python 库。我们的方法首先将磁盘上的参数组复制到设备内存,并在那里直接将它们实例化为张量对象。这种设计实现了低级 I/O 和高级张量预处理的进一步优化,包括并行复制、点对点 DMA 和 GPU 卸载。实验结果表明,在加载 Llama(70亿、130亿和700亿参数)、Falcon(400亿参数)和 Bloom(1760亿参数)等模型时,性能提升了 4.8 倍至 7.5 倍。
英文摘要:
The rapid increases in model parameter sizes introduces new challenges in pre-trained model loading. Currently, machine learning code often deserializes each parameter as a tensor object in host memory before copying it to device memory. We found that this approach underutilized storage throughput and significantly slowed down loading large models with a widely-used model file formats, safetensors. In this work, we present fastsafetensors, a Python library designed to optimize the deserialization of tensors in safetensors files. Our approach first copies groups of on-disk parameters to device memory, where they are directly instantiated as tensor objects. This design enables further optimization in low-level I/O and high-level tensor preprocessing, including parallelized copying, peer-to-peer DMA, and GPU offloading. Experimental results show performance improvements of 4.8x to 7.5x in loading models such as Llama (7, 13, and 70 billion parameters), Falcon (40 billion parameters), and the Bloom (176 billion parameters).
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。