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

- **GitHub URL**: https://github.com/deepseek-ai/DeepInfer
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A+ (89/100 · Maintenance 35/35 · Adoption 23/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: GPU, Local AI
- **Momentum**: 27,715 ★ total (+93 24h / +1,312 7d) · 3,421 forks
- **When to Use**: Best for: Teams with supported SM100 or Ascend 950 hardware that need to benchmark or integrate DeepSeek-V4.1-Flash offline, with explicit control over parallel execution and reproducibility. Skip if: You need broad model or accelerator support, or an online serving API without building and operating a separate service layer.

## Overview
```text
### Architecture & Core Mechanics
DeepInfer exposes offline execution through `examples/offline_inference.py`. The Python runtime combines model execution and sampling with asynchronous scheduling that overlaps CPU batch preparation and accelerator execution. It supports attention data parallelism and balanced context parallelism, alongside MoE expert parallelism and expert load balancing. These are engine-level execution controls, not an online serving interface.

The source tree separates `deepinfer/` and `csrc/`. The build uses setuptools with Ninja and PyTorch >= 2.7 as build requirements; pinned dependencies include TileLang 0.1.15 and Transformers 4.50.0. Acceleration components include FlashMLA, DeepGEMM, DeepEP, TileKernels, DeepSelect, and custom TileLang operators under `deepinfer/model_executor/layers/tilelang_ops`. Integration uses Python sampling parameters and environment variables; no public plugin protocol is established.

### Key Capabilities & Differentiators
DeepSeek-V4.1-Flash is the only listed model. DSpark uses draft tokens and schedules verification based on confidence; the configured maximum draft length defaults to 5. Sliding-window attention (SWA) bounded replay cuts decoder prefill work by replaying a suffix. The V4.1 compact setting keeps 140 tokens; any retained suffix must cover the attention window plus maximum backtracking.

Batch invariance is opt-in. For deterministic sampling, enable it, disable variable-length MTP, and pass a fixed `seq_seed`. Structured generation accepts regex, JSON Schema, or EBNF. The benchmark sweeps use 4 SM100 GPUs for prefill and 64 for decode, versus 8 Ascend 950 NPUs for prefill and 64 for decode. Each configuration stays within one scale-up domain; these allocations describe benchmark topology, not minimum hardware or performance guarantees.

### Trade-offs & Limitations
DeepInfer is a focused choice when the checkpoint and accelerator fleet match its support envelope and the team wants direct control over prefill and decode. Prefer evaluating a general-purpose engine if a broad model catalog, heterogeneous hardware, or a ready-to-run online API matters more. The open release is an offline engine: budget separately for API integration, request admission, and service observability rather than treating it as a complete serving stack.

Validate two distinct operating profiles if you need both accelerated decoding and strict reproducibility: the deterministic sampling recipe explicitly disables variable-length MTP. Benchmark on the intended topology and size accelerator memory for the checkpoint, context lengths, and concurrency rather than extrapolating from the published device counts. Apache-2.0 covers the engine; check checkpoint and dependency terms separately.

### Hardware & Deployment Guide
Build from source on Linux in a clean Python 3.12 environment with GCC >= 13.0. NVIDIA builds require CUDA >= 13.2 on SM100; Ascend deployments require CANN 9.3 on Ascend 950 with an aarch64 host. For NVIDIA, export `DEEPINFER_ACCELERATOR=nvidia` before running `./build.sh` and keep it set when running the engine. `requirements-nvidia.txt` and `requirements-ascend.txt` are present in the tree.

Run `python examples/offline_inference.py` for an initial check. The default `deepseek-ai/DeepSeek-V4.1-Flash-1017` checkpoint downloads into the Hugging Face cache on first run; set `DEEPINFER_HF_MODEL_DIR` to use a local copy. For isolated environments, stage dependencies as well as weights: the base requirements include a commit-pinned TileKernels Git dependency. Package metadata identifies version 0.1.0 as beta; no GitHub release is listed. Pin a tested revision and record the toolchain for repeatable builds.
```

## Key Capabilities
```text
- Model and hardware scope: DeepSeek-V4.1-Flash on NVIDIA SM100 or Huawei Ascend 950 with aarch64 hosts.
- Parallel execution: Attention DP and balanced CP, with MoE expert parallelism and expert load balancing.
- Draft verification: `DEEPINFER_ENABLE_MTP_VARLEN=1` enables confidence-scheduled verification; `DEEPINFER_USE_NEXTN_DECODE` caps draft length, defaulting to 5.
- Prefill replay: Compact SWA replay retains a bounded suffix; the default V4.1 configuration uses 140 tokens and must cover the window plus maximum backtracking.
- Reproducibility: Enable batch invariance, disable variable-length MTP, and set a fixed `seq_seed` for deterministic sampling.
- Structured generation: `SamplingParams.so_args` accepts regex, JSON Schema, or EBNF constraints.
```

## Quick Start / Clone
```bash
### Offline inference

The default checkpoint, [`deepseek-ai/DeepSeek-V4.1-Flash-1017`](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017), is
downloaded into the Hugging Face cache on the first run; set `DEEPINFER_HF_MODEL_DIR=/path/to/DeepSeek-V4.1-Flash-1017` to
run from a local copy instead.
```
