메뉴
HN
Hacker News • 54일 전

AirLLM: 단일 4GB GPU로 70B 모델 추론하기

IMP
8/10
핵심 요약

오픈소스 라이브러리인 AirLLM은 양자화(Quantization)나 가지치기(Pruning) 없이도 단일 4GB VRAM GPU에서 70B 규모의 대형 언어 모델을 실행할 수 있게 해줍니다. 레이어 단위 스트리밍 및 희소 모델(MoE) 최적화를 통해 메모리 사용량을 획기적으로 줄여, 초대형 모델조차 일반적인 로컬 환경에서 구동할 수 있다는 점에서 AI 실무자들에게 매우 중요한 기술입니다.

번역된 본문

빠른 시작 | 설정 | MacOS | 예제 노트북 | FAQ

AirLLM은 추론 시 메모리 사용량을 획기적으로 줄여주어, 양자화(quantization), 지식 증류(distillation), 또는 가지치기(pruning) 없이도 단일 4GB GPU 카드로 70B 크기의 대형 언어 모델을 실행할 수 있게 해줍니다. 심지어 8GB VRAM으로 405B 크기의 Llama 3.1을, 약 12GB로 DeepSeek-V3(671B)를 구동할 수 있으며, 현재 공개된 최대 규모의 오픈소스 모델인 Kimi K3(2.8T)조차 4GB 미만의 VRAM으로 실행할 수 있습니다. 이는 희소 MoE(Sparse MoE) 모델들이 전체 레이어가 아닌 한 번에 하나의 전문가(Expert) 모듈만 스트리밍하기 때문입니다.

AI 에이전트 추천:

  • 최고의 AI 게임 스프라이트 생성기
  • 최고의 AI 표정 편집기
  • Bloome — 클라우드에서 AI 에이전트 팀을 구축하고 실행하세요. 설정 불필요.

업데이트 내역 [2026/07] Kimi K3(2.8T) 지원: 현재까지 공개된 최대 규모의 오픈소스 모델이 단일 RTX 6000 Ada 그래픽 카드에서 엔드투엔드로 측정했을 때 단 3.72GB의 VRAM만으로 구동됩니다. 전문가별 스트리밍(per-expert streaming) 방식은 토큰이 실제로 참조하는 전문가 모듈만 로드합니다. K3 모델 구동을 위한 3가지 필수 요구사항이 있습니다: pip를 통한 compressed-tensors와 flash-attn 설치 (해당 모델 코드는 사용자 요청과 무관하게 flash attention을 필수로 요구함), 미리 빌드된 CUDA 13용 flash-attn 휠(wheel)이 아직 없으므로 CUDA 12 버전으로 빌드된 torch 설치, 그리고 remote code가 5.x 버전에서는 로드되지 않으므로 transformers 4.56.x 버전 사용.

[2026/06] v3.0: FP8 모델 지원 및 최신 모델 반영. 단일 AutoModel 클래스를 통해 DeepSeek-V3(671B)는 약 12GB에서, Qwen3-235B는 약 3GB에서 실행할 수 있게 되었습니다. 추가로 Qwen3, Llama 3.x/4, DeepSeek V2/V3, Phi-4, Gemma 등 다양한 최신 모델을 지원합니다. [2024/08/20] v2.11.0: Qwen2.5 지원 [2024/08/18] v2.10.1: CPU 추론 지원. 샤딩(sharding)되지 않은 모델 지원. 훌륭한 기여를 해주신 @NavodPeiris님께 감사드립니다! [2024/07/30] Llama3.1 405B 지원 (예제 노트북). 8bit/4bit 양자화 지원. [2024/04/20] AirLLM이 Llama3를 네이티브로 지원합니다. 4GB 단일 GPU로 Llama3 70B를 실행하세요. [2023/12/25] v2.8.2: MacOS에서 70B 대형 언어 모델 실행 지원. [2023/12/20] v2.7: AirLLMMixtral 지원. [2023/12/20] v2.6: AutoModel 추가. 모델 유형을 자동으로 감지하여 초기화 시 모델 클래스를 제공할 필요가 없습니다. [2023/12/18] v2.5: 모델 로딩과 연산을 겹치기 위한 프리페칭(prefetching) 추가. 10%의 속도 향상. [2023/12/03] ChatGLM, QWen, Baichuan, Mistral, InternLM 지원 추가! [2023/12/02] safetensors 지원 추가. 현재 Open LLM 리더보드 상위 10위권 내의 모든 모델을 지원합니다. [2023/12/01] airllm 2.0. 압축(compressions) 지원: 런타임 속도 3배 향상! [2023/11/20] airllm 초기 버전 출시!

목차 빠른 시작, 모델 압축, 설정, MacOS에서 실행, 예제 노트북, 지원되는 모델, 감사의 말, FAQ

빠른 시작 (Quickstart)

  1. 패키지 설치 먼저 airllm pip 패키지를 설치합니다. pip install airllm

  2. 추론 (Inference) 그 다음, AirLLMLlama2를 초기화하고 사용 중인 모델의 허깅페이스(HuggingFace) 리포지토리 ID나 로컬 경로를 전달합니다. 이후 일반적인 트랜스포머(transformer) 모델과 유사한 방식으로 추론을 수행할 수 있습니다. (AirLLMLlama2 초기화 시 layer_shards_saving_path를 통해 분할된 레이어 모델을 저장할 경로를 지정할 수도 있습니다.)

from airllm import AutoModel

MAX_LENGTH = 128

# 허깅페이스 리포지토리 ID만 전달하면 됩니다 — 대부분의 인기 모델과 작동합니다:
model = AutoModel.from_pretrained("Qwen/Qwen3-32B")

# 동일한 코드 한 줄로 더 큰 모델을 실행해 보세요:
#model = AutoModel.from_pretrained("Qwen/Qwen3-235B-A22B") # 235B 모델이 약 3GB 메모리로 실행됩니다
#model = AutoModel.from_pretrained("deepseek-ai/DeepSeek-V3") # 671B 모델이 약 12GB 메모리로 실행됩니다

# 또는 모델의 로컬 경로를 사용할 수도 있습니다...
#model = AutoModel.from_pretrained("/home/ubuntu/.cache/huggingface/hub/models--Qwen--Qwen3-32B/snapshots/...")

input_text = [
  'What is the capital of United States?',
  #'I like',
]

input_tokens = model.tokenizer(input_text, return_tensors="pt", return_attention_mask=False, truncation=True, max_length=MAX_LENGTH, padding=False)

generation_output = model.generate(
  input_tokens['input_ids'].cuda(),
  max_new_tokens=20,
  use_cache=True,
  return_dict_in_generate=True
)

output = model.tokenizer.decode(generation_output.sequences[0])
print(output)

참고: 추론 중에 원본 모델이 먼저 분해되어 레이어별로 저장됩니다. 디스크 공간이 충분한지 확인하시기 바랍니다.

원문 보기
원문 보기 (영어)
Quickstart | Configurations | MacOS | Example notebooks | FAQ AirLLM dramatically reduces inference memory usage, letting 70B large language models run on a single 4GB GPU card — without quantization, distillation, or pruning. You can even run 405B Llama 3.1 on 8GB , DeepSeek-V3 (671B) on ~12GB , and Kimi K3 (2.8T) — the largest open-source model released to date — on under 4GB , because sparse MoE models stream one expert at a time rather than a whole layer. AI Agents Recommendation: Best AI Game Sprite Generator Best AI Facial Expression Editor Bloome — build & run AI agent teams in the cloud, zero setup Updates [2026/07] Kimi K3 (2.8T) support: the largest open-source model runs on a single card in 3.72GB of VRAM, measured end to end on one RTX 6000 Ada. Per-expert streaming loads only the experts a token actually routes to. K3 brings three requirements of its own: pip install compressed-tensors flash-attn (its model code mandates flash attention regardless of what you request), a CUDA 12 build of torch, since no prebuilt flash-attn wheel exists for CUDA 13 yet, and transformers 4.56.x, as its remote code does not load on 5.x. [2026/06] v3.0 : FP8 model support + the latest models. Run DeepSeek-V3 (671B) on ~12GB and Qwen3-235B on ~3GB , plus Qwen3, Llama 3.x/4, DeepSeek V2/V3, Phi-4, Gemma and more — all through a single AutoModel . [2024/08/20] v2.11.0: Support Qwen2.5 [2024/08/18] v2.10.1 Support CPU inference. Support non sharded models. Thanks @NavodPeiris for the great work! [2024/07/30] Support Llama3.1 405B ( example notebook ). Support 8bit/4bit quantization . [2024/04/20] AirLLM supports Llama3 natively already. Run Llama3 70B on 4GB single GPU. [2023/12/25] v2.8.2: Support MacOS running 70B large language models. [2023/12/20] v2.7: Support AirLLMMixtral. [2023/12/20] v2.6: Added AutoModel, automatically detect model type, no need to provide model class to initialize model. [2023/12/18] v2.5: added prefetching to overlap the model loading and compute. 10% speed improvement. [2023/12/03] added support of ChatGLM , QWen , Baichuan , Mistral , InternLM ! [2023/12/02] added support for safetensors. Now support all top 10 models in open llm leaderboard. [2023/12/01] airllm 2.0. Support compressions: 3x run time speed up! [2023/11/20] airllm Initial version! Star History Table of Contents Quick start Model Compression Configurations Run on MacOS Example notebooks Supported Models Acknowledgement FAQ Quickstart 1. Install package First, install the airllm pip package. pip install airllm 2. Inference Then, initialize AirLLMLlama2, pass in the huggingface repo ID of the model being used, or the local path, and inference can be performed similar to a regular transformer model. ( You can also specify the path to save the splitted layered model through layer_shards_saving_path when init AirLLMLlama2. from airllm import AutoModel MAX_LENGTH = 128 # just pass a hugging face repo id — works with almost any popular model: model = AutoModel . from_pretrained ( "Qwen/Qwen3-32B" ) # go bigger with the exact same one line: #model = AutoModel.from_pretrained("Qwen/Qwen3-235B-A22B") # 235B, runs in ~3GB #model = AutoModel.from_pretrained("deepseek-ai/DeepSeek-V3") # 671B, runs in ~12GB # or use a model's local path... #model = AutoModel.from_pretrained("/home/ubuntu/.cache/huggingface/hub/models--Qwen--Qwen3-32B/snapshots/...") input_text = [ 'What is the capital of United States?' , #'I like', ] input_tokens = model . tokenizer ( input_text , return_tensors = "pt" , return_attention_mask = False , truncation = True , max_length = MAX_LENGTH , padding = False ) generation_output = model . generate ( input_tokens [ 'input_ids' ]. cuda (), max_new_tokens = 20 , use_cache = True , return_dict_in_generate = True ) output = model . tokenizer . decode ( generation_output . sequences [ 0 ]) print ( output ) Note: During inference, the original model will first be decomposed and saved layer-wise. Please ensure there is sufficient disk space in the huggingface cache directory. Model Compression - 3x Inference Speed Up! We just added model compression based on block-wise quantization-based model compression. Which can further speed up the inference speed for up to 3x , with almost ignorable accuracy loss! (see more performance evaluation and why we use block-wise quantization in this paper ) How to enable model compression speed up: Step 1. make sure you have bitsandbytes installed by pip install -U bitsandbytes Step 2. make sure airllm verion later than 2.0.0: pip install -U airllm Step 3. when initialize the model, passing the argument compression ('4bit' or '8bit'): model = AutoModel . from_pretrained ( "garage-bAInd/Platypus2-70B-instruct" , compression = '4bit' # specify '8bit' for 8-bit block-wise quantization ) What are the differences between model compression and quantization? Quantization normally needs to quantize both weights and activations to really speed things up. Which makes it harder to maintain accuracy and avoid the impact of outliers in all kinds of inputs. While in our case the bottleneck is mainly at the disk loading, we only need to make the model loading size smaller. So, we get to only quantize the weights' part, which is easier to ensure the accuracy. Configurations When initialize the model, we support the following configurations: compression : supported options: 4bit, 8bit for 4-bit or 8-bit block-wise quantization, or by default None for no compression profiling_mode : supported options: True to output time consumptions or by default False layer_shards_saving_path : optionally another path to save the splitted model hf_token : huggingface token can be provided here if downloading gated models like: meta-llama/Llama-2-7b-hf prefetching : prefetching to overlap the model loading and compute. By default, turned on. For now, only AirLLMLlama2 supports this. delete_original : if you don't have too much disk space, you can set delete_original to true to delete the original downloaded hugging face model, only keep the transformed one to save half of the disk space. MacOS Just install airllm and run the code the same as on linux. See more in Quick Start . make sure you installed mlx and torch you probably need to install python native see more here only Apple silicon is supported Example [python notebook] ( https://github.com/lyogavin/airllm/blob/main/air_llm/examples/run_on_macos.ipynb ) Example Python Notebook Example colabs here: example of other models (ChatGLM, QWen, Baichuan, Mistral, etc): Details ChatGLM: from airllm import AutoModel MAX_LENGTH = 128 model = AutoModel . from_pretrained ( "THUDM/chatglm3-6b-base" ) input_text = [ 'What is the capital of China?' ,] input_tokens = model . tokenizer ( input_text , return_tensors = "pt" , return_attention_mask = False , truncation = True , max_length = MAX_LENGTH , padding = True ) generation_output = model . generate ( input_tokens [ 'input_ids' ]. cuda (), max_new_tokens = 5 , use_cache = True , return_dict_in_generate = True ) model . tokenizer . decode ( generation_output . sequences [ 0 ]) QWen: from airllm import AutoModel MAX_LENGTH = 128 model = AutoModel . from_pretrained ( "Qwen/Qwen-7B" ) input_text = [ 'What is the capital of China?' ,] input_tokens = model . tokenizer ( input_text , return_tensors = "pt" , return_attention_mask = False , truncation = True , max_length = MAX_LENGTH ) generation_output = model . generate ( input_tokens [ 'input_ids' ]. cuda (), max_new_tokens = 5 , use_cache = True , return_dict_in_generate = True ) model . tokenizer . decode ( generation_output . sequences [ 0 ]) Baichuan, InternLM, Mistral, etc: from airllm import AutoModel MAX_LENGTH = 128 model = AutoModel . from_pretrained ( "baichuan-inc/Baichuan2-7B-Base" ) #model = AutoModel.from_pretrained("internlm/internlm-20b") #model = AutoModel.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1") input_text = [ 'What is the capital of China?' ,] input_tokens = model . tokenizer ( input_text , return