SuperAPI AI Directory

airllm

A Python library that reduces LLM inference memory usage by loading one layer at a time, enabling 70B models on 4GB GPUs, 405B on 8GB, and 671B DeepSeek-V3 on ~12GB. Supports 4-bit/8-bit quantization and a wide range of open models via a single AutoModel interface.

Open website

About this tool

AirLLM is a Python library focused on greatly reducing the GPU memory usage of large language model inference. Its core idea is to "keep only one layer on the GPU at a time," so the required GPU memory depends on the size of a single layer of the model rather than the total size of the model. According to the official description, with this approach, a 70B model can run on a single 4GB GPU without quantization, distillation, or pruning; a 405B model can run with 8GB of GPU memory, and the 671B DeepSeek-V3 requires about 12GB. Later versions also added the ability to train large models under low GPU memory.

Main capabilities and support:

  • Extremely low GPU memory inference: through layer-by-layer loading, very large models can run on GPUs with small GPU memory. The official examples include a 70B model running on a 4GB GPU and Llama3 70B running on a single 4GB GPU.
  • Model compression acceleration: supports model compression based on block quantization, with 4bit or 8bit options. The official description says inference speed can be increased by up to 3 times, with almost negligible accuracy loss. To use it, you need to install bitsandbytes and ensure the airllm version is not lower than 2.0.0, and pass the compression parameter ('4bit' or '8bit') when initializing the model.
  • Broad model compatibility: it can be used by passing a Hugging Face model ID through AutoModel.from_pretrained(...), covering major model families such as Llama (2/3/3.1/3.3/4), Qwen (1/2/2.5/3/3.5/3.8, including MoE, Flash-Next, FP8, and native VL), DeepSeek (V2/V3/R1), Mistral and Mixtral, Phi, Gemma, ChatGLM, Baichuan, InternLM, Yi, Kimi K3, and more, and it is said that most new models can be used on the day they are released.
  • Version evolution: the initial version was released in November 2023; 2.0 supports compression, with a 3x speed increase; 2.5 adds prefetching to overlap model loading and computation, bringing about a 10% speed increase; 2.6 adds AutoModel, automatically detecting the model type; 2.7 supports AirLLMMixtral; 2.8.2 supports running 70B models on macOS; July 2024 supports Llama3.1 405B and 8bit/4bit quantization; August 2024 supports CPU inference and non-sharded models; v2.11.0 supports Qwen2.5.
  • Support for newer large models: v3.0 in June 2026 adds FP8 model support, allowing DeepSeek-V3 (671B) to run with about 12GB of GPU memory and Qwen3-235B with about 3GB. July 2026 supports Kimi K3 (2.8T), which can run on a single card with about 3.72GB of GPU memory (end-to-end measured on RTX 6000 Ada), using on-demand streaming loading for experts, loading only the experts that tokens are actually routed to; using K3 requires pip install compressed-tensors flash-attn, a CUDA 12 version of torch, and transformers 4.56.x. August 2026 supports Qwen3.8-Flash-Next (125B MoE) running with 5.95GB of GPU memory (end-to-end measured on RTX 4090), requiring a transformers build with qwen4_exp and about 360GB of checkpoint disk space; in the same month, supports Qwen3.8-27B running with 3.33GB of GPU memory (end-to-end measured on RTX 3090), requiring transformers 5.8+. September 2026 adds training support: layer-by-layer streaming loading of frozen weights, with adapters kept on the GPU, Qwen3.8-Flash-Next (125B) can be trained under 6GB (RTX 3060 Ti), and Qwen3.8-27B can be trained with about 2GB at a sequence length of 512.

Usage:

  • After installing the pip package airllm, initialize the corresponding model class (such as AirLLMLlama2), pass in the Hugging Face repository ID or local path, and inference can be performed like an ordinary transformer model.
  • During initialization, the save path for the sharded model can be specified through layer_shards_saving_path; during inference, the original model will first be decomposed and saved layer by layer, so it is necessary to ensure that the Hugging Face cache directory has enough disk space.
  • The following configurations are supported during initialization: compression (4bit, 8bit, or the default None), profiling_mode (True outputs elapsed time), layer_shards_saving_path, hf_token (for gated models, such as meta-llama/Llama-2-7b-hf), prefetching (enabled by default, overlaps loading and computation, currently only supported by AirLLMLlama2), delete_original (set to true to delete the original downloaded model to save about half of the disk space).
  • macOS: requires installing mlx and torch, may require installing python native, and only supports Apple Silicon; the code is the same as on Linux.
  • Training: provides the AirLLMLoRA training method; the dataset is a .jsonl file with one JSON object per line, and the commonly used field is text; it also supports instruction pairs (loss is applied only to the answer part) and .txt files (blocks separated by blank lines). Run the training script from the repository root, and use --data to specify the data file; --steps N can stop after N samples, which is convenient for smoke testing; if --data is not provided, it will overfit on a built-in snippet.

Use cases:

  • Running or experimenting with open-source large models with extremely large parameter counts on consumer-grade GPUs with limited VRAM.
  • Scenarios that require lightweight fine-tuning (LoRA) of large models under low-VRAM conditions.
  • Scenarios where you want to quickly switch between different model families for inference or validation through a unified interface (AutoModel).

Limitations and notes:

  • During inference, the original model is first decomposed and saved layer by layer, which consumes a large amount of disk space, so sufficient space needs to be reserved; if you encounter the MetadataIncompleteBuffer error, it is usually due to insufficient disk space, and you need to expand capacity, clean the Hugging Face cache, and retry.
  • Using compression acceleration requires additionally installing bitsandbytes, and the airllm version must be no lower than 2.0.0.
  • Some models are gated models and require providing a Hugging Face API token (hf_token).
  • If you use a Llama2-type loader for QWen or ChatGLM models, a ValueError: max() arg is an empty sequence may occur, and you need to use the corresponding model class.
  • Some models' tokenizers do nothave a padding token, so you can set a padding token or disable the padding configuration.
  • New models (such as the Kimi K3 and Qwen3.8 series) have specific requirements for dependency versions (transformers, torch, flash-attn, etc.), and some capabilities are given as "measured" data; the specific VRAM usage may vary with different environments.
  • Training support is not Hugging Face Trainer / bitsandbytes QLoRA, and Flash-Next requires a transformers build with in-tree qwen4_exp.

Citation information: If you use AirLLM in your research, the official BibTex citation entry is provided. The project welcomes contributions, ideas, and discussions, and accepts sponsorships.