![[Bug]: DiffusionGemma structured JSON outputs fail with xgrammar FSM rejection](https://www.chat-gpts.plus/wp-content/uploads/2026/06/45436-40f4f255.jpg)
[Bug]: DiffusionGemma structured JSON outputs fail with xgrammar FSM rejection
快速结论:当对 DiffusionGemma 模型使用 structured JSON output(如 OpenAI 兼容的 response_format: {"type": "json_schema", ...} 或 vLLM 顶层 structured_outputs)时,服务器返回 HTTP 500。优先排查:当前结构化输出栈假设自回归逐 token 推进 xgrammar FSM,而 DiffusionGemma 的扩散解码路径采用并行画布去噪,不兼容左到右逐 token 序列,导致 FSM 拒绝 token。
问题场景
用户在 Docker 镜像 vllm/vllm-openai:pr45163-a275a28e-dgemma-fullpy 中运行 vLLM v0.22.1rc1.dev332+g2c9c07c85,使用 vllm serve 命令加载 nvidia/diffusiongemma-26B-A4B-it-NVFP4 模型,配置了 structured_outputs_config(backend=’auto’)、quantization=modelopt_fp4、kv_cache_dtype=fp8_e4m3、tensor_parallel_size=1、pipeline_parallel_size=1。通过 curl 请求 /v1/chat/completions 并设置 structured JSON 约束(如 JSON schema 或 top-level structured_outputs)时触发故障。
该问题在 RTX PRO 6000 Blackwell Max-Q Workstation Edition (SM 12.0, CUDA 13.0, driver 595.71.05) 单卡环境下复现。普通文本生成不受影响,同样的 prompt 在不加结构化约束时能返回合法的 JSON-like 内容,但 schema 约束解码导致中断。
报错原文
[backend_xgrammar.py:158] Failed to advance FSM for request ... for tokens ...
[scheduler.py:1500] Unexpected: grammar rejected tokens [...] for request .... Terminating request.
[serving.py:195] Request ... failed with an internal error during generation
POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
curl 返回:
{"error":{"message":"Internal server error","type":"InternalServerError","param":null,"code":500}}
原因分析
根本原因:DiffusionGemma 的扩散语言模型解码路径采用并行画布去噪(block/diffusion decoding),不会像标准自回归(AR)模型那样从左到右逐个 token 发射。而结构化输出栈(xgrammar FSM)假设每个采样 token 都是严格的逐 token 接受并推进 FSM。当调度器(Scheduler)一次将整个 committed canvas block(例如包含完整 JSON 及额外 token <turn|>)传递给 grammar.accept_tokens() 时,xgrammar 的匹配器在闭合 } 后遇到非 xgrammar 停止 token(如 <turn|> → token 106)而拒绝;或者在另一种场景下,画布去噪步骤并未被 grammar 位掩码真正约束,导致如 json 等 token 在左花括号之后即被拒绝。
具体来说,pr45468 中的 token 分析揭示了两种失败模式:
- Repro 1:committed canvas block 解码为
{\n "invoice_id": "RE-2026-0142",\n "customer": "Aigner Transport"\n}<turn|>— 虽然 JSON 本身符合 schema,但调度器将整个 block 一次性交给 grammar,xgrammar 在}后拒绝<turn|>(token 106)。在自回归解码中,位掩码会在下一步强制生成有效停止 token,但全块传递使其不可能。 - Repro 2:block 解码为
json\n{ ... }\n```<turn|>— 去噪步骤实际上未被 grammar 位掩码约束。
因此,结构化输出栈严格依赖自回归逐步 FSM 推进,而扩散模型并行画布去噪既无左到右顺序也无单 token 停止边界。当前没有扩散模型校验路由存在于结构化输出路径。
近期的修复 pr45468 在请求时添加明确的校验错误,返回 HTTP 400 并告知 “Structured outputs are not yet supported for diffusion language models.”,而不是内部 500 错误。
环境排查
- vLLM 版本:v0.22.1rc1.dev332+g2c9c07c85(Docker 镜像 vllm/vllm-openai:pr45163-a275a28e-dgemma-fullpy)
- GPU 硬件:NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition(Compute capability 12.0)
- CUDA 版本:13.0;驱动 595.71.05
- PyTorch 版本:2.11.0+cu130
- 模型:nvidia/diffusiongemma-26B-A4B-it-NVFP4(量化 modelopt_fp4,kv_cache_dtype fp8_e4m3)
- 并行配置:tensor_parallel_size=1,pipeline_parallel_size=1
- 结构化输出配置:StructuredOutputsConfig(backend=’auto’, disable_any_whitespace=False, disable_additional_properties=False, reasoning_parser=’gemma4′, …)
- 启动参数:
--max-model-len 81920 --gpu-memory-utilization 0.88 --max-num-seqs 48 --max-num-batched-tokens 2048 --attention-backend TRITON_ATTN --generation-config vllm等
解决步骤
- 升级到包含 pr45468 或更高版本的 vLLM。该修复在请求验证时针对 diffusion 模型拒绝结构化输出请求,返回 HTTP 400 而非 500。示例命令:
vllm serve nvidia/diffusiongemma-26B-A4B-it-NVFP4 [其他参数],当传入response_format或structured_outputs时,会返回类似 “Structured outputs are not yet supported for diffusion language models.” 的 400 错误。 - 禁用 structured outputs。在等待真正的扩散模型约束解码支持之前,避免为 DiffusionGemma 使用
response_format或structured_outputs。普通生成(plain generation)不受影响。 - 如已在可复现环境,可尝试基于 pr45468 分支(如
fix-45436-diffusion-structured-guard)重新测试两个 curl 用例,预期返回400 BadRequestError而不是 500。
验证方法
重新运行之前触发 500 的 curl 命令:
- 响应格式 JSON schema: 使用
response_format: {"type": "json_schema", ...}发送请求,期望返回 HTTP 400 以及类似 “Structured outputs are not yet supported for diffusion language models.” 的错误信息。 - 顶层 structured_outputs: 使用
structured_outputs: {"json": ...}发送请求,同样期望 HTTP 400。 - 普通生成验证: 发送不包含结构化约束的普通
messages请求,应返回正常响应(HTTP 200),不受影响。
此外,可确认服务器日志不再出现 backend_xgrammar.py 或 grammar rejected tokens 错误。

![[WIP Integration] LocateAnything-3B (MoonViT-SO-400M + Eagle MLP + Qwen2.5-3B): spatial localization failure and token count mismatch in cli](https://www.chat-gpts.plus/wp-content/uploads/2026/06/24020-8aeab169-768x403.jpg)

![[程序员] AI 编程的下一个阶段将会是什么形态呢?程序员的我又将何去何从?](https://www.chat-gpts.plus/wp-content/uploads/2026/06/ai_cover_5-544-768x403.jpg)