개요
AirLLM은 추론 메모리 사용량을 최적화하여 70B와 같은 대규모 언어 모델을 양자화, 증류 또는 프루닝 없이 단일 4GB 그래픽 카드에서 실행할 수 있게 합니다. Llama 3.1 405B를 8GB VRAM에 배포하는 것을 지원하며, 청크 양자화 가속을 제공합니다.
README 미리보기
\n\n[**Quickstart**](#quickstart) | \n[**Configurations**](#configurations) | \n[**MacOS**](#macos) | \n[**Example notebooks**](#example-python-notebook) | \n[**FAQ**](#faq)\n\n**AirLLM** optimizes inference memory usage, allowing 70B large language models to run inference on a single 4GB GPU card without quantization, distillation and pruning. And you can run **405B Llama3.1** on **8GB vram** now.\n\n\n[](https://pepy.tech/project/airllm)\n\n[](https://github.com/LianjiaTech/BELLE/blob/main/LICENSE)\n[](https://static.aicompose.cn/static/wecom_barcode.png?t=1671918938)\n[](https://discord.gg/2xffU5sn)\n[\n](https://pypi.org/project/airllm/)\n[](https://medium.com/@lyo.gavin)\n[](https://gavinliblog.com)\n[](https://patreon.com/gavinli)\n[](https://github.com/sponsors/lyogavin)\n\n## AI Agents Recommendation:\n\n* [Best AI Game Sprite Generator](https://godmodeai.co)\n\n* [Best AI Facial Expression Editor](https://crazyfaceai.com)\n\n## Updates\n[2024/08/20] v2.11.0: Support Qwen2.5\n\n[2024/08/18] v2.10.1 Support CPU inference. Support non sharded models. Thanks @NavodPeiris for the great work! \n\n[2024/07/30] Support Llama3.1 **405B** ([example notebook](https://colab.research.google.com/github/lyogavin/airllm/blob/main/air_llm/examples/run_llama3.1_405B.ipynb)). Support **8bit/4bit quantization**.\n\n[2024/04/20] AirLLM supports Llama3 natively already. Run Llama3 70B on 4GB single GPU.\n\n[2023/12/25] v2.8.2: Support MacOS running 70B large language models.\n\n[2023/12/20] v2.7: Support AirLLMMixtral. \n\n[2023/12/20] v2.6: Added AutoModel, automatically detect model type, no need to provide model class to initialize model.\n\n[2023/12/18] v2.5: added prefetching to overlap the model loading and compute. 10% speed improvement.\n\n[2023/12/03] added support of **ChatGLM**, **QWen**, **Baichuan**, **Mistral**, **InternLM**!\n\n[2023/12/02] added support for safetensors. Now support all top 10 models in open llm leaderboard.\n\n[2023/12/01] airllm 2.0. Support com
FAQ (4)
문제 해결Mac에서 airllm으로 llama 모델을 실행할 때 'ValueError: Cannot index mlx array using the given type' 오류를 해결하는 방법은 무엇인가요?
이 오류는 Apple Silicon에서 MLX 백엔드와 함께 airllm을 사용할 때 발생합니다. 모델이 MLX 배열을 기대하지만 입력 토큰 ID가 PyTorch 텐서로 제공되기 때문입니다. 해결하려면 입력 토큰을 변환하세요: import mlx.core as mx; generation_output = model.generate(mx.array(input_tokens['input_ids'])) 대신 input_tokens['input_ids'].cuda(). 이렇게 하면 MLX의 임베딩 레이어와의 호환성이 보장됩니다. 이 문제는 M1 Pro의 macOS 14.5에서 airllm v2.9.1, Python 3.12.4, mlx 버전 14.1–16.1에서 보고되었습니다.
informationalAirLLM은 Llama3 70B를 네이티브로 지원하나요?
AirLLM은 이미 Llama3 70B를 기본적으로 지원합니다. Llama3에는 AirLLM의 기존 Llama 구현을 조정해야 하는 아키텍처 변경 사항이 없기 때문입니다. AirLLM으로 Llama3 70B를 실행하는 데 추가적인 기능 개발은 필요하지 않습니다.
문제 해결macOS에서 transformers/airllm으로 모델을 로드할 때 발생하는 "ModuleNotFoundError: Could not import module 'LlamaForCausalLM'" 오류를 해결하는 방법
이 오류는 오해의 소지가 있습니다 — 이는 Llama 모듈이 누락된 것이 아니라 손상된 torchvision 설치로 인해 가려진 임포트 실패입니다. 트레이스백에서 실제 오류는 RuntimeError: operator torchvision::nms does not exist이며, 이는 torch와 torchvision 버전이 바이너리 호환되지 않을 때 발생합니다(Python 3.13 / Apple Silicon에서 흔함). Transformers의 lazy loader가 image_utils → torchvision을 트리거하고, 크래시가 혼란스러운 ModuleNotFoundError로 나타납니다.
텍스트 전용 LLM(Qwen, Llama 등)의 해결 방법 — torchvision을 완전히 제거하세요:
uv pip uninstall torchvision
# 또는: pip uninstall -y torchvisiontorchvision이 없으면 transformers는 vision 임포트 경로를 건너뛰고
LlamaForCausalLM이 정상적으로 로드됩니다.
vision 지원이 필요한 경우, 대신 서로 일치하는 버전을 다시 설치하세요:
uv pip install -U --force-reinstall torch torchvision두 패키지가 동일한 릴리스 채널에서 설치되었는지 확인하세요(예: torch 2.5.x와 torchvision 0.20.x).
python -c "import torchvision; print(torchvision.__version__)"로 확인할 수 있습니다.
macOS 사용자 참고: Apple Silicon에서는 CUDA를 사용할 수 없으므로 .cuda()를 .to('mps')로 교체하거나 CPU에서 실행하세요.
문제 해결macOS Apple Silicon에서 AirLLM 'Cannot index mlx array using the given type' 오류를 해결하는 방법은?
AirLLM의 MLX 백엔드(AirLLMLlamaMlx.generate())는 mlx.array 인덱스만 받지만, return_tensors="pt"로 설정된 HuggingFace 토크나이저는 torch.LongTensor를 반환하므로 mlx.nn.Embedding에서 크래시가 발생합니다. 이는 AutoModel이 모든 것을 MLX 클래스를 통해 라우팅하기 때문에 macOS의 모든 아키텍처(Llama, Qwen, Mistral, Mixtral, GLM, Baichuan)에 영향을 미칩니다. 우회 방법 — generate()를 호출하기 전에 토큰 ID를 mlx 배열로 변환하세요:
import mlx.core as mx
from airllm import AutoModel
model = AutoModel.from_pretrained("Qwen/Qwen2.5-7B-Instruct", compression=None)
tokens = model.tokenizer(["Hello world"], return_tensors="pt").input_ids
input_ids = mx.array(tokens.detach().cpu().numpy()) # torch -> numpy -> mlx
model.generate(input_ids, max_new_tokens=8)
또는 return_tensors="np"로 토크나이즈한 후 mx.array(...)로 감쌀 수도 있습니다. 영구적인 수정 사항(generate() 경계에서 torch/numpy/mlx 입력을 처리하는 내부 _coerce_to_mlx_array() 헬퍼)이 PR을 통해 제안되었으며, 병합될 때까지는 수동 변환이 필요합니다.