# Repository Briefing: lyogavin/airllm
> Source: https://repoforai.com/repo/lyogavin/airllm (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/lyogavin/airllm
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Jupyter Notebook
- **License**: Apache-2.0
- **Engineering Health**: A+ (98/100 · Maintenance 35/35 · Adoption 23/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v4.0.1 (2026-11-23) — https://github.com/lyogavin/airllm/releases
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: Local AI, GPU, API
- **Momentum**: 43,885 ★ total (+43 24h / +344 7d) · 4,555 forks
- **Topics**: `chinese-llm`, `chinese-nlp`, `finetune`, `generative-ai`, `instruct-gpt`, `instruction-set`, `llama`, `llm`, `lora`, `open-models`, `open-source`, `open-source-models`
- **When to Use**: Best for: Local model evaluation and occasional generation on a single GPU when the required checkpoint exceeds VRAM and sufficient disk capacity and bandwidth are available. Skip if: You need predictable interactive latency, sustained concurrent throughput, or a turnkey HTTP service, or an acceptable model already fits entirely in VRAM.

## Overview
```text
### Architecture & Core Mechanics
AirLLM is a Python inference library built around disk-backed execution. `AutoModel.from_pretrained(...)` takes a Hugging Face model ID or a local path and prepares per-layer shards. During each decode step, the runtime streams those layers through the GPU rather than keeping the full checkpoint resident. Weight residency is therefore driven by layer size rather than total checkpoint size, but runtime state such as the KV cache still needs memory.

The inference code and examples sit under `air_llm/`. Integration uses PyTorch tensors and a Transformers-style tokenizer and `generate` flow. The root manifest points Transformers at Git and lists `bitsandbytes==0.39.0`, which is relevant to optional weight compression. That root pin is not a substitute for checking the installed package and selected model together. `profiling_mode` exposes timings, while the documented prefetch option overlaps loading and compute only for `AirLLMLlama2`.

### Key Capabilities & Differentiators
`AutoModel` provides a common loading entry point for examples spanning Llama, Qwen, ChatGLM, Baichuan, InternLM, and Mistral. Chat models use their tokenizer's chat template, and Transformers `TextStreamer` can surface tokens during generation. Example VRAM figures include ~4 GB for full-precision Llama 3.x 70B and ~12 GB for DeepSeek-V3. These are configuration-specific fit figures, not throughput guarantees or universal memory budgets.

Layer streaming works without quantization. Optional 4-bit or 8-bit blockwise compression reduces the amount of weight data read; in v4.0.1 it applies only to matrices, leaving one-dimensional tensors such as norm weights and biases unquantized. Streamed LoRA is a separate fine-tuning path for the supported Qwen variants: frozen base weights stream from disk, adapters stay on GPU, and the example scripts accept either plain-text training records or instruction pairs with loss applied only to the completion.

### Trade-offs & Limitations
Choose AirLLM when running a specific checkpoint matters more than generation speed. GPU-resident runtimes avoid rereading weights at every decode step, so a smaller model or an acceptable quantized checkpoint that fits in VRAM is a better starting point for interactive or concurrent inference. AirLLM frees up VRAM at the cost of storage reads and weight transfers; compression can reduce bytes read, but it does not remove that per-step work. Streaming text makes progress visible, not faster.

Size the system with separate budgets for peak disk usage during conversion, host memory, GPU runtime state, and sustained read bandwidth. A low VRAM figure alone does not establish that the model fits the whole machine or meets latency targets. Benchmark with the actual checkpoint, prompt lengths, and expected concurrency. AirLLM is Apache-2.0, but checkpoint licenses and gated-access terms must be reviewed separately.

### Hardware & Deployment Guide
Start with `pip install airllm` in a Python environment with PyTorch and a working GPU runtime for the chosen platform. Install a compatible bitsandbytes build if using compression. Local checkpoints avoid fetching model weights at startup; for gated Hugging Face downloads, pass `hf_token`. Initial conversion needs space for the original files and new shards. Use `layer_shards_saving_path` to place shards on an appropriately sized drive. Enable `delete_original` only if you are willing to remove the source copy. On macOS, the MLX and PyTorch path is Apple Silicon only and limited to `LlamaForCausalLM` and `MistralForCausalLM`.

v3.3.0 added Flash-Next streaming with its n-gram table mapped from a file on the host. v4.0.0 introduced streamed LoRA; the Flash-Next path needs a Transformers build that includes `qwen4_exp`. v4.0.1 corrected the NF4 free-space check to multiply by the estimated compressed size ratio (~0.28×), rather than divide by it. For a reproducible rollout, record the working package versions and model revision, then smoke-test both initial shard creation and generation before staging a large checkpoint.
```

## Key Capabilities
```text
- Execution: Splits checkpoints into layer shards and streams weights during generation instead of keeping the full model in VRAM.
- Compression: Optional 4-bit or 8-bit blockwise quantization targets weight matrices; v4.0.1 leaves one-dimensional tensors unquantized.
- Model loading: `AutoModel.from_pretrained` accepts Hugging Face IDs and local paths; `layer_shards_saving_path` selects where converted shards go.
- Profiling: `profiling_mode` reports timing; configurable prefetching is documented only for `AirLLMLlama2`.
- Fine-tuning: Streamed LoRA keeps frozen base weights on disk and adapters on GPU, with example scripts for two Qwen variants.
- Platform scope: The Apple Silicon path uses MLX and PyTorch and is limited to `LlamaForCausalLM` and `MistralForCausalLM`.
```

## Quick Start / Clone
```bash
pip install airllm
```
