AirLLM 讓單張 4GB GPU 即可進行 70B LLM 推論

概覽

AirLLM 透過每次僅在裝置上保留一個模型層,使得在消費級 GPU 上執行非常大的語言模型成為可能。

AirLLM 如何運作

該函式庫將模型拆分為個別的層,並僅在計算需要時才從磁碟串流每一層到 GPU。這意味著 VRAM 的需求量是由最大層的大小決定的,而非總參數數量。

支援的模型與 VRAM 需求

AirLLM 可與廣泛的開源 LLM 協作。下表顯示在使用預設(無壓縮)模式時,各種模型所需的近似 VRAM:

  • Qwen3, Mistral, Phi (≈8 B) – ~1–2 GB
  • Qwen3‑30B, Mixtral (MoE) – ~1–3 GB
  • Qwen3‑235B (MoE) – ~3 GB
  • Llama 3.x 70B (full precision) – ~4 GB
  • Llama 3.1 405B – ~8 GB
  • DeepSeek‑V3 (671 B) – ~12 GB
  • Kimi K3 (2.8 T) – ~3.72 GB VRAM,於 RTX 6000 Ada 上測量(需要額外的依賴項)

性能特性

在預設模式下執行模型會導致高延遲,因為每個 token 都會觸發從磁碟載入一層。該函式庫提供可選的區塊式壓縮(block‑wise compression),可以在精度損失微乎其微的情況下將推論速度提升高達 3 倍。根據使用者回報,在 RTX 6000 Ada 上執行 Kimi K3 的測量結果顯示每 token 約為 292 秒。

設定與使用

  1. 安裝套件:pip install airllm
  2. 使用 AutoModel.from_pretrained(<repo_id>) 初始化模型。
  3. (可選)啟用壓縮:加入 compression='4bit'compression='8bit' 並確保已安裝 bitsandbytes
  4. (可選)透過 hf_token 參數為受限模型提供 Hugging Face token。
  5. (可選)設定 layer_shards_saving_path 以控制拆分後的層儲存位置。
  6. (可選)開啟 profiling_mode=True 以查看時間分配細節。
  7. 按照快速入門範例執行生成。

注意:第一次執行時會分解模型並儲存層分片(layer shards),因此需要在 Hugging Face 快取目錄中有足夠的可用磁碟空間。

平台支援

  • Linux 與 Windows:標準 PyTorch 安裝。
  • macOS:僅支援 Apple Silicon;您必須按照 macOS 章節所述安裝 mlxtorch

限制與權衡

  • 延遲:逐層串流會使互動式對話變得緩慢;此技術更適合批次處理或隔夜任務。
  • 磁碟使用量:儲存所有層分片會消耗大量空間;您可以啟用 delete_original=True 以僅保留轉換後的版本。
  • 預設不進行量化:基礎方法避免量化以保留精度;壓縮是可選的附加功能。
  • 特定模型(例如 Kimi K3)有額外需求,例如 compressed-tensorsflash-attn、CUDA 12 版的 PyTorch 以及 transformers 4.56.x。

社群觀點

Hacker News 的評論者強調了興奮感與實際的疑慮:

  • "Kimi K3 on RTX 6000 Ada (48GB) takes 292 s/token" – @imenani
  • "Seeing a lot of these ‘run 1TB models with 1GB RAM’ projects recently. Most seem vibe coded and probably won’t be maintained." – @roger_
  • "I love it how the rampocalypse is pushing people to squash all the performance they can. I hope that this also leads to rethinking model architecture." – @seu
  • "I’m still slightly confused on what this adds… Does this basically load layers in and out on demand? So I still have to download the full model to disk…" – @cpfohl
  • "You can run any frontier model on your PC if you just wait long enough…" – @xg15
  • "The layer‑by‑layer streaming is clever. Curious how the throughput compares to running a quantized model on the same GPU — seems like quantization might still win on speed?" – @junsu22
  • "At this latency, I can still imagine batch or overnight jobs being interesting; for chat, time to first useful answer matters much more…" – @Alisaqqt

這些評論強調了雖然 AirLLM 實現了令人印象深刻的記憶體效率,但產生的延遲限制了互動式使用,並引發了與 llama.cpp 或 unsloth 等量化推論引擎的比較。

Sources

相關