llm inference-engineering distributedsystem ai

deepseek-ai/DeepInfer

1. What is DeepInfer?

DeepInfer is DeepSeek’s open-source LLM inference framework, designed for high-performance execution of large language models.

It provides an optimized inference execution engine, especially for large-scale Mixture-of-Experts (MoE) models.

Its main engineering areas include:

  • GPU kernels: Efficient execution of model operations.
  • Expert Parallelism (EP): Distributing MoE experts across GPUs.
  • Context Parallelism (CP): Distributing context processing across GPUs.
  • Expert Load Balancing (EPLB): Distributing expert workloads efficiently.
  • Asynchronous Scheduling: Overlapping CPU scheduling and GPU execution.
  • Speculative Decoding: Accelerating autoregressive token generation.
  • Distributed Execution: Coordinating inference across multiple accelerators.

Core understanding

DeepInfer is mainly an offline batched inference engine and optimized execution core, not a complete production serving platform.

2. Inference Engine vs Production Inference Service

These are two different engineering problems.

Inference Engine: Executes model computations efficiently.

Production Inference Service: Handles real users, incoming requests, traffic distribution, memory management, scaling, and failures.

A production deployment requires additional components beyond DeepInfer’s public release.

DeepInfer execution coreAdditional serving infrastructure
Model executionAPI and request routing
GPU optimizationReplica load balancing
SchedulingComplete online request lifecycle
Speculative decodingProduction KV-cache management
Expert parallel executionPrefill/Decode disaggregation infrastructure

Engineering lesson

Making model execution fast does not automatically make a production service fast, reliable, or scalable.

3. Asynchronous Scheduling — Overlap CPU and GPU Work

In a simple synchronous inference engine:

  1. CPU prepares a batch.
  2. GPU executes the batch.
  3. CPU waits for the GPU.
  4. The process repeats.

This can introduce idle time.

DeepInfer uses asynchronous scheduling to prepare upcoming work while the GPU processes current work.

CPU: [Schedule A][Schedule B][Schedule C]
GPU:       [Execute A][Execute B][Execute C]

The scheduler is implemented in C++ and can operate while the Python Global Interpreter Lock (GIL) is released.

Important implementation detail

DeepInfer uses optimistic KV-cache positions while scheduling.

The scheduler initially predicts how a sequence will advance. After execution, the state is corrected according to the number of accepted tokens.

This is especially important for Speculative Decoding, where the number of accepted tokens varies.

Engineering lesson

Performance optimization often requires coordination between scheduling, memory state, and decoding — not just faster GPU kernels.

4. Parallelism Strategy — Prefill vs Decode

Prefill: Processes input tokens and initializes the KV Cache.

Decode: Generates output tokens, usually one autoregressive step at a time.

These stages have different computational characteristics.

AspectPrefillDecode
Primary workloadProcess input tokensGenerate new tokens
Typical bottleneckOften compute-intensiveOften memory-bandwidth-intensive
Parallelism goalAvoid unnecessary communicationReduce memory traffic and improve aggregate throughput
DeepInfer strategySmallest practical EP/DP topology that fitsWide EP/DP, including EP64–128

DeepInfer’s documented deployment recommendations use different parallelism strategies for each stage.

The deployment Q&A also states that Tensor Parallelism (TP) and Pipeline Parallelism (PP) are not used in that deployment.

Engineering lesson

More GPUs or more parallelism do not always mean better performance. The parallelism strategy must match the workload and hardware bottleneck.

5. Speculative Decoding and Scheduling

Speculative Decoding accelerates generation by proposing multiple candidate tokens and verifying them.

The number of accepted tokens is not always the same.

For example:

Draft tokens:    A B C D
Verified tokens: A B C
Accepted:        3 tokens

The scheduler must update sequence state according to the actual accepted token count, not simply the proposed token count.

DeepInfer’s speculative decoding and optimistic scheduling are therefore closely connected.

Key insight: An optimization in one part of the runtime can require changes across multiple components.

6. Large-Scale Production Engineering Lessons

  1. Optimize the entire inference pipeline. A faster kernel does not always produce a faster end-to-end system.
  2. Overlap CPU and GPU execution. Scheduling overhead can prevent expensive accelerators from reaching high utilization.
  3. Choose parallelism based on workload. Prefill and Decode have different performance requirements.
  4. Treat distributed communication as a real cost. Moving data between GPUs can reduce the benefits of additional parallelism.
  5. Maintain correct runtime state. Optimistic scheduling improves overlap but requires careful state reconciliation.
  6. Separate compute execution from service infrastructure. A high-performance inference engine is only one component of a production platform.
  7. Evaluate bottlenecks before optimizing. Understand compute, memory bandwidth, communication, and scheduling overhead.

7. Key Terminology

TermMeaning
LLM InferenceRunning a trained model to produce outputs
PrefillProcessing prompt tokens before generation
DecodeGenerating output tokens autoregressively
KV CacheCached attention keys and values used to avoid recomputation
MoEMixture-of-Experts model architecture
EPExpert Parallelism
DPData Parallelism
CPContext Parallelism
EPLBExpert Parallel Load Balancing
GPU KernelProgram that performs computation on a GPU
Speculative DecodingProposing and verifying multiple tokens to accelerate generation
Asynchronous SchedulingPreparing upcoming computation while existing work executes
ThroughputAmount of work completed per unit of time
LatencyTime required to complete a request or operation

8. Questions for Further Learning

  • Why does Decode often become memory-bandwidth-bound?
  • How does Expert Parallelism reduce MoE inference costs?
  • Why does EP/DP topology differ between Prefill and Decode?
  • How does optimistic scheduling maintain correct KV-cache positions?
  • What performance is lost when CPU scheduling cannot overlap GPU execution?
  • What additional components are required to serve millions of requests reliably?
  • How can we measure whether a GPU kernel optimization improves end-to-end latency?

Final Takeaway

DeepInfer demonstrates that high-performance LLM inference is a systems engineering problem, not only a model execution problem.

The most important areas to study are:

GPU computation + memory management + scheduling + distributed parallelism + production architecture.

The central lesson is to optimize how the complete system works together, rather than optimizing each component in isolation.