AI 文摘

Mixtraloffloading:10GB显存跑mixtralmoe模型





作者: 人工智能技术与时代人物风云 来源: 人工智能技术与时代人物风云

https://github.com/dvmazur/mixtral-offloading  
https://arxiv.org/abs/2312.17238  
https://colab.research.google.com/github/dvmazur/mixtral-offloading/blob/master/notebooks/demo.ipynb  

随着大型语言模型(LLMs)的广泛采用,许多深度学习从业者正在寻找更高效地运行这些模型的策略。其中一种策略是使用稀疏的专家混合模型(MoE)-这是一种模型架构类型,其中对于任何给定的输入,只有部分模型层是活跃的。这种特性使得基于MoE的语言模型比其密集对应物更快地生成标记,但也由于拥有多个专家而增加了模型大小。不幸的是,这使得最先进的MoE语言模型难以在没有高端GPU的情况下运行。

在这项工作中,我们研究了在具有有限显存上运行大型MoE语言模型的问题。我们基于参数卸载算法,并提出了一种利用MoE LLM固有属性加速卸载的新策略。使用这种策略,我们可以在桌面硬件和免费的Google Colab实例上运行具有混合量化的Mixtral-8x7B。

原理

  • Mixed quantization with HQQ. 我们为注意力层和专家应用单独的量化方案,以将模型适配到结合的GPU和CPU内存中。

  • MoE offloading strategy. 每个层的专家都单独卸载,并且只在需要时重新放回GPU。我们将活跃的专家存储在LRU缓存中,以减少在计算相邻标记的激活时的GPU-RAM通信。

测试步骤

  1. install conda/mamba

  2. conda create –name mixtral python=3.10

  3. conda activate mixtral

  4. conda install jupyterlab

  5. git clone https://github.com/dvmazur/mixtral-offloading

  6. cd mixtral-offloading

  7. mv notebooks/demo.ipynb to demo.ipynb

  8. open jupyter lab

  9. open the demo.ipynb notebook and change the first cell of code to the following:

 # fix numpy in colab  
 !pip install numpy  
 !pip install ipywidgets  
 import numpy  
 from IPython.display import clear_output  
 !pip install -q -r requirements.txt  
  1. in the thrid code cell, you can change the offload value:
 # 16 GB VRAM  
 # offload_per_layer = 4  
 # 12 GB VRAM  
 # offload_per_layer = 5  
 # approx. 10 GB VRAM  
 offload_per_layer = 6  

You can also run it with 4, so the new Nvidia Driver will simply use RAM in place of VRAM instead of OOM-ing, but it will be slow too.

Then execute the rest of the cells…

更多AI工具,参考Github-AiBard123国内AiBard123

可关注我们的公众号:每天AI新工具