vLLM社区

vLLM 2026社区进展:高性能推理引擎的进化

引言 vLLM是2026年最流行的高性能LLM推理引擎。从PagedAttention到连续批处理,vLLM不断创新推理优化技术。本文将全面介绍2026年vLLM社区的最新进展。 vLLM 2026核心特性 PagedAttention 2.0 vLLM的招牌技术,2026年升级到2.0: 虚拟内存管理:更高效的KV Cache管理 碎片消除:几乎零内存碎片 吞吐量提升:比v1提升30% 连续批处理 from vllm import LLM, SamplingParams llm = LLM(model="glm-5-32b") # 连续批处理 prompts = ["问题1", "问题2", "问题3", ...] sampling_params = SamplingParams(temperature=0.7, max_tokens=500) outputs = llm.generate(prompts, sampling_params) 多模态支持 # 支持视觉模型 llm = LLM(model="qwen3-vl-72b") # 图像输入 from vllm.multimodal import ImageFeature outputs = llm.generate( prompts=[{"text": "描述这张图", "image": image_feature}] ) 分布式推理 # 张量并行 llm = LLM( model="deepseek-v4-671b", tensor_parallel_size=4, pipeline_parallel_size=2 ) # 流水线并行 llm = LLM( model="deepseek-v4-671b", pipeline_parallel_size=8 ) 2026年新特性 1. Speculative Decoding(投机解码) # 用小模型加速大模型 llm = LLM( model="glm-5-32b", speculative_model="glm-5-air-6b", # 投机模型 num_speculative_tokens=5 ) # 吞吐量提升2-3倍 2. 量化推理 # INT4量化推理 llm = LLM( model="glm-5-32b", quantization="awq", dtype="float16" ) # GPTQ量化 llm = LLM( model="qwen3-72b", quantization="gptq" ) 3. LoRA动态加载 # 同时服务多个LoRA适配器 llm = LLM( model="glm-5-32b", enable_lora=True, max_loras=16, max_lora_rank=64 ) # 每个请求使用不同的LoRA outputs = llm.generate( prompts=[ {"prompt": "问题1", "lora_request": LoRARequest("lora_1", 1, "path/to/lora1")}, {"prompt": "问题2", "lora_request": LoRARequest("lora_2", 2, "path/to/lora2")}, ] ) 4. 语法引导生成 # 约束输出为JSON from vllm.sampling_params import SamplingParams, GuidedDecodingParams sampling_params = SamplingParams( guided_decoding=GuidedDecodingParams( json={"type": "object", "properties": {"name": {"type": "string"}}} ) ) 5. 模型组成 # 工具调用+推理+生成 llm = LLM( model="glm-5-32b", enable_auto_tool_choice=True, tool_call_parser="glm" ) 性能基准 吞吐量对比(tokens/s) 模型 vLLM TGI llama.cpp Triton GLM-5 32B (A100×4) 2850 2100 850 1800 Qwen3 72B (A100×8) 1920 1450 520 1300 Llama4 8B (A100×1) 4500 3800 2100 3200 延迟对比 模型 vLLM P50 vLLM P95 TGI P95 GLM-5 32B 0.8s 2.1s 3.5s Qwen3 7B 0.2s 0.5s 0.8s 部署指南 Docker部署 # 简单部署 docker run --gpus all -p 8000:8000 \ vllm/vllm-openai:latest \ --model glm-5-32b \ --tensor-parallel-size 4 # 带OpenAI兼容API docker run --gpus all -p 8000:8000 \ vllm/vllm-openai:latest \ --model glm-5-32b \ --openai-api-key sk-vllm Kubernetes部署 apiVersion: apps/v1 kind: Deployment metadata: name: vllm-glm5 spec: replicas: 2 template: spec: containers: - name: vllm image: vllm/vllm-openai:latest args: - --model=glm-5-32b - --tensor-parallel-size=4 resources: limits: nvidia.com/gpu: 4 ports: - containerPort: 8000 API服务 # OpenAI兼容API from openai import OpenAI client = OpenAI( base_url="http://localhost:8000/v1", api_key="sk-vllm" ) response = client.chat.completions.create( model="glm-5-32b", messages=[{"role": "user", "content": "你好"}] ) 社区生态 贡献者 2026年vLLM社区有: ...

2026-07-02 · 2 min · 363 words · 硅基 AGI 探索者
sglang 2026 inference engine

SGLang 2026:结构化生成的高性能推理引擎

SGLang:被低估的推理黑马 SGLang(Structured Generation Language)在 2026 年从"学术项目"蜕变为"生产级推理引擎"。由 LMSYS 团队(ChatBot Arena 的创建者)开发,SGLang 的核心创新是 RadixAttention——一种基于基数树的 KV Cache 复用技术,在多轮对话和复杂 Agent 场景中实现了惊人的性能提升。 核心技术创新 1. RadixAttention RadixAttention 是 SGLang 的标志性技术。它将 KV Cache 组织为基数树结构,实现前缀复用: 传统方案:每个请求独立维护 KV Cache ┌──────┐ ┌──────┐ ┌──────┐ │Req 1 │ │Req 2 │ │Req 3 │ │KV │ │KV │ │KV │ │Cache │ │Cache │ │Cache │ └──────┘ └──────┘ └──────┘ 浪费:相同前缀重复计算 RadixAttention:共享前缀的 KV Cache ┌─ "用户: 你好" (共享) │ ├─ "助手: 你好!有什么可以帮您?" (Req 1) │ └─ "助手: 您好!请问需要什么帮助?" (Req 2) └─ "用户: 写代码" (共享) └─ "助手: 好的,请告诉我..." (Req 3) import sglang as sgl # RadixAttention 自动复用前缀 @sgl.function def multi_turn_chat(s, question): s += "以下是一个专业对话:\n" s += "用户: " + question + "\n" s += "助手: " + sgl.gen("answer", max_tokens=256) # 多轮对话中,前缀自动复用 # 第一轮 state1 = multi_turn_chat.run(question="什么是 RAG?") # 第二轮(复用第一轮的前缀) state2 = multi_turn_chat.run(question="RAG 和微调有什么区别?") # 第三轮(复用前两轮的前缀) state3 = multi_turn_chat.run(question="如何结合使用?") # KV Cache 复用率随轮次增加而提高 # 实测:5 轮对话后,KV Cache 复用率达 85%+ 2. 结构化输出 SGLang 原生支持 JSON Schema 约束生成: ...

2026-06-28 · 4 min · 761 words · 硅基 AGI 探索者
tensorrt llm 2026

TensorRT-LLM 2026:NVIDIA 推理加速终极方案

NVIDIA 的推理加速王牌 TensorRT-LLM 是 NVIDIA 在大模型推理领域的旗舰产品。它不是一个独立的推理引擎,而是基于 TensorRT 的 LLM 专用优化层——通过算子融合、精度优化、内存布局优化等技术,在 NVIDIA GPU 上榨取每一分性能。 2026 年,随着 Blackwell 架构 GPU 的普及,TensorRT-LLM 的优势进一步扩大——它对 Blackwell 的 Transformer Engine 和 FP4 精度提供了原生支持。 2026 核心特性 性能优势 特性 TensorRT-LLM 2026 vLLM 0.8 SGLang 0.3 峰值吞吐量 8,500 tok/s 4,200 tok/s 4,800 tok/s 首 Token 延迟 0.15s 0.5s 0.35s FP4 支持 ✅ (Blackwell) ❌ ❌ FP8 支持 ✅ (Hopper) ✅ ✅ 算子融合 深度 基础 基础 模型编译 AOT 编译 JIT JIT 多 GPU TP + PP + EP TP + PP TP + PP Blackwell 架构优化 # Blackwell B200 上的 FP4 推理 import tensorrt_llm as trtllm # 编译模型为 FP4 精度 builder = trtllm.Builder() config = builder.create_builder_config( precision="fp4", # FP4 量化 plugin_config=trtllm.PluginConfig( attention_plugin=True, nccl_plugin=True, gemm_plugin=True, rmsnorm_plugin=True, # Blackwell 专属 transformer_engine=True, moe_plugin=True, ), max_batch_size=256, max_input_len=32768, max_output_len=4096, max_num_tokens=8192, use_paged_context_fmha=True, # Paged Attention use_context_fmha=True, # Flash Attention multiple_profiles=True, # 多优化 Profile tensor_parallel=8, # 8 路张量并行 pipeline_parallel=1, ) # 编译(AOT,提前编译为优化引擎) engine = builder.build( model_dir="Qwen/Qwen3-72B-Instruct", config=config, output_dir="engines/qwen3-72b-fp4" ) # 编译后的引擎不可移植,绑定特定 GPU 架构 # 但性能比 JIT 方案高 30-60% 部署流程 1. 模型编译 # 步骤 1:从 HuggingFace 模型编译 TensorRT 引擎 import tensorrt_llm as trtllm from tensorrt_llm.models import QWenForCausalLM # 加载模型配置 model_config = trtllm.ModelConfig.from_pretrained( "Qwen/Qwen3-72B-Instruct" ) # 编译配置 build_config = trtllm.BuildConfig( max_input_len=32768, max_output_len=4096, max_batch_size=128, max_num_tokens=8192, opt_batch_size=32, opt_input_len=4096, # 精度配置 precision="fp8", # fp4/fp8/fp16 int8_kv_cache=True, # KV Cache 量化 # 插件配置 plugin_config=trtllm.PluginConfig( paged_kv_cache=True, attention_plugin=True, gemm_plugin=True, nccl_plugin=True, rmsnorm_plugin=True, rotary_plugin=True, remove_input_padding=True, # 移除 padding 优化 ), # 并行配置 tensor_parallel=4, pipeline_parallel=1, # 高级优化 use_fused_mlp=True, # MLP 算子融合 use_fused_qkv=True, # QKV 融合 use_dynamic_shape=True, # 动态形状 weight_sparsity=True, # 权重稀疏化 ) # 编译引擎 builder = trtllm.Builder() engine = builder.build_model( model_config=model_config, build_config=build_config, output_dir="engines/qwen3-72b-fp8-tp4" ) 2. 启动服务 # 使用 Triton Inference Server 部署 # 模型仓库结构 models/ └── qwen3-72b/ ├── config.pbtxt ├── 1/ │ └── model.py └── engines/ └── qwen3-72b-fp8-tp4/ ├── rank0.engine ├── rank1.engine ├── rank2.engine └── rank3.engine # config.pbtxt name: "qwen3-72b" backend: "tensorrtllm" max_batch_size: 128 input [ { name: "input_ids" data_type: TYPE_INT32 dims: [ -1 ] }, { name: "input_lengths" data_type: TYPE_INT32 dims: [ 1 ] } ] output [ { name: "output_ids" data_type: TYPE_INT32 dims: [ -1, -1 ] } ] dynamic_batching { preferred_batch_size: [ 4, 8, 16, 32 ] max_queue_delay_microseconds: 100000 } instance_group [ { count: 1 kind: KIND_GPU } ] parameters [ { key: "tensorrt_llm_model_dir" value: { string_value: "/models/qwen3-72b/engines/qwen3-72b-fp8-tp4" } }, { key: "max_output_len" value: { string_value: "4096" } }, { key: "temperature" value: { string_value: "0.7" } }, { key: "top_p" value: { string_value: "0.9" } } ] # 启动 Triton Server docker run --gpus all -p 8000:8000 -p 8001:8001 -p 8002:8002 \ -v /models:/models \ nvcr.io/nvidia/tritonserver:25.06-py3 \ tritonserver --model-repository=/models \ --backend-directory=/opt/tritonserver/backends \ --log-verbose=1 3. 客户端调用 import tritonclient.grpc as grpcclient import numpy as np class TensorRTLLMClient: def __init__(self, url="localhost:8001"): self.client = grpcclient.InferenceServerClient(url) def generate(self, prompt: str, max_tokens: int = 512, temperature: float = 0.7, stream: bool = True): # Tokenize input_ids = self.tokenizer.encode(prompt) inputs = [ grpcclient.InferInput("input_ids", [1, len(input_ids)], "INT32"), grpcclient.InferInput("input_lengths", [1, 1], "INT32"), ] inputs[0].set_data_from_numpy(np.array([input_ids], dtype=np.int32)) inputs[1].set_data_from_numpy(np.array([[len(input_ids)]], dtype=np.int32)) outputs = [grpcclient.InferRequestedOutput("output_ids")] # 推理 result = self.client.infer( model_name="qwen3-72b", inputs=inputs, outputs=outputs ) output_ids = result.as_numpy("output_ids") # Detokenize return self.tokenizer.decode(output_ids[0]) 性能优化 精度对比 精度 显存 (72B) 吞吐量 质量损失 推荐 GPU FP16 145 GB 3,200 tok/s 0% A100 80GB×2 FP8 75 GB 5,800 tok/s <1% H100/H200 INT4 AWQ 42 GB 4,500 tok/s ~3% 任意 FP4 38 GB 8,500 tok/s ~5% B200 算子融合效果 优化 吞吐量提升 延迟降低 基础(无融合) 基准 基准 QKV 融合 +15% -8% + MLP 融合 +25% -15% + RMSNorm 融合 +30% -20% + Rotary 融合 +35% -22% + 全部融合 +42% -28% 多 GPU 扩展 # 张量并行 + 流水线并行配置 config = trtllm.BuildConfig( tensor_parallel=4, # 4 路张量并行 pipeline_parallel=2, # 2 路流水线并行 # 总共 8 GPU # 专家并行(MoE 模型) moe_config=trtllm.MoEConfig( num_experts=256, expert_parallel_size=8, moe_plugin=True, ), ) 并行策略 GPU 数量 吞吐量 扩展效率 TP=1 1 3,200 100% TP=2 2 5,800 91% TP=4 4 9,500 74% TP=8 8 15,200 59% TP=4+PP=2 8 14,800 58% 与 vLLM 对比 维度 TensorRT-LLM vLLM 峰值性能 ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ 部署难度 高 低 模型支持 跟随 NVIDIA 跟随社区 编译时间 10-60 分钟 即时 灵活性 低(AOT) 高(JIT) 跨平台 仅 NVIDIA NVIDIA + AMD 生态 NVIDIA 生态 开源生态 成本 需要 NVIDIA GPU 任意 GPU 适用场景 最适合 极致性能需求:延迟和吞吐量最优 NVIDIA 纯净环境:充分利用 GPU 特性 固定模型部署:AOT 编译换取性能 大规模生产:Triton Server 集群部署 Blackwell 用户:FP4 独家支持 不太适合 快速迭代:每次模型变更需要重新编译 多 GPU 品牌:仅支持 NVIDIA 小团队:部署和调优门槛高 实验性模型:新模型架构支持滞后于 vLLM 成本敏感:需要 NVIDIA GPU 许可 总结 TensorRT-LLM 在 2026 年仍然是"NVIDIA GPU 上最快的推理引擎"。它的 AOT 编译、深度算子融合、FP4/FP8 支持,让它在峰值性能上领先 vLLM 60-100%。这个优势在 Blackwell 架构上更加明显。 ...

2026-06-28 · 4 min · 727 words · 硅基 AGI 探索者
sglang inference engine

SGLang 掐理引擎指南:超越 vLLM 的新选择

SGLang 是什么 SGLang(Structured Generation Language)是由 LMSYS Org 开发的高性能 LLM 推理引擎,核心创新是 RadixAttention——用基数树缓存 KV Cache,在多轮对话和复杂推理场景下显著优于 vLLM。 核心创新:RadixAttention 传统推理引擎的 KV Cache 是按请求隔离的——每个请求独立计算 Attention 的 K 和 V,无法复用。在多轮对话中,前几轮的 KV Cache 每次都要重算。 SGLang 用基数树(Radix Tree)管理 KV Cache: RadixTree: [system prompt] → [user msg 1 + assistant msg 1] → [user msg 2 + ...] ↑ 命中缓存 ↑ 命中缓存 ↑ 新计算 当新请求的前缀与已缓存的前缀匹配时,直接复用 KV Cache,跳过重复计算。 效果: 多轮对话:第 N 轮只计算第 N 轮的 KV,前 N-1 轮全部命中缓存 Few-shot 场景:多个示例的前缀共享缓存 Agent 场景:system prompt 长且固定,缓存命中率接近 100% 与 vLLM 的 PagedAttention 对比 特性 vLLM PagedAttention SGLang RadixAttention 缓存粒度 物理页(块级) 逻辑前缀(语义级) 跨请求复用 需手动启用 prefix caching 自动复用 多轮对话 每轮重新计算 prefix 前缀自动命中 树结构管理 页表 基数树 缓存命中率 中 高 内存效率 高 高 安装 # 安装 SGLang pip install sglang # 或从源码安装 pip install --upgrade pip pip install "sglang[all]" GPU 要求:CUDA 12.0+,推荐 A100/H100/L40S。消费级显卡(3090/4090)也可用。 ...

2026-06-24 · 4 min · 683 words · 硅基 AGI 探索者
鲁ICP备2026018361号