背景:我们的 SGLang fork(在 /user4813494d/openbmb/demo-sala/sglang/python/sglang/)跑 EAGLE-3…
Private research annotation
Sign in to add a private research label or note.
- User
背景:我们的 SGLang fork(在 /user_4813494d/openbmb/demo-sala/sglang/python/sglang/)跑 EAGLE-3 chain verify 推测解码(spec_steps=2, topk=2, draft_token_num=5)。线上观察到偶发性"accept rate 坍缩到 0 且无法恢复"——日志中每个 decode step 严格 accept_len=1.00、accept_rate=0.00 持续几十步直到请求结束,gen throughput 从正常 150+ tok/s 掉到 99 tok/s。该现象在多个 draft model 权重(v2、v3、不同 ckpt epoch)下都复现,所以不是单一 ckpt 的问题,而是 spec decode runtime 路径上的稳态 bug。
请彻底调研以下问题(thoroughness=very thorough),不要写代码,只需返回精准的调研报告:
-
EAGLE-3 chain verify 的执行路径
- 在 SGLang fork 中找 spec verify 的入口函数(很可能在 srt/speculative/ 或 srt/managers/scheduler 下),列出 draft step + verify + accept 的完整调用链。
- chain verify 的接受/拒绝逻辑在哪里(greedy 比较 token id?sampling 比较概率?)。
- accept_len、accept_rate 这两个指标具体是怎么算的、在哪里写入 log。
-
Draft model 的状态依赖
- llama_eagle3.py 里 forward 接收哪些输入(aux_hidden_states 来自 target 哪几层?hidden 还是 logits?)
- draft model 的 KV cache 与 target KV cache 是怎么同步的(reject 时如何 rewind?)
- lm_head + d2t 映射的应用点(draft 输出的 32000 vocab token 怎么映射回 target 73448 vocab)
- hot_token_id / draft_vocab_size 相关代码
-
CUDA graph 的捕获范围
- EAGLE3 path 是否在 cuda graph 里捕获 draft forward / verify?
- 如果 graph 捕获了带状态的 buffer(mamba/GLA conv state、scratch),是否存在 capture 时的状态在 replay 时不一致的风险?
- bench/kill_sglang.sh、demo-sala/sglang patches 里有没有相关 graph 修复(特别是 minicpm_backend.py 里 CUDA graph fix)
-
混合架构(standard attn + GLA)下的 spec decode
- GLA layer 的 chunk/recurrent 状态在 spec verify reject 时如何回滚?
- 8 个 standard attn layers 走 InfLLM-v2 sparse 时(虽然这个 case 还没到 dense_len 8192)spec decode 的 path 兼容性
-
现有可观测性
- 当前有哪些 spec decode 相关的统计指标(除了 accept_len/accept_rate)
- 是否有 logits dump、token-level mismatch dump、divergence position 之类的钩子?
- 失败状态有没有 fallback / self-heal(譬如 N 步 accept_rate=0 后回退到 no-spec)
-
可能的稳态坍缩根因猜想验证
- 在代码里寻找以下风险点是否真实存在: a) draft KV 和 target KV 长度不同步(一个 reject path 漏掉 rewind) b) aux_hidden_states 的索引在长上下文下越界 / 取错位置 c) d2t 表加载或 set_embed 后没有同步更新到 graph buffer d) FP4 数值进入饱和区,draft 输出永远是某个常量 token e) chain verify 树构造里某个 path 的 attention mask / position id 错位 f) "set_embed" 把 target embedding 拷给 draft 之后是否需要重新 capture cuda graph g) sampling 路径:target 用 multinomial 采样 / draft 用 greedy → 永远 mismatch
请按以上 6 个分区返回结构化报告,每个发现都给出 file:line 引用。重点找代码事实,不是猜测。报告控制在 ~600 词。
-
Assistant
我来彻底调研这个 EAGLE-3 spec decode 的稳态坍缺问题。让我从多个角度并行搜索关键代码路径。
Assistant
现在并行搜索关键代码路径、chain verify 逻辑和指标计算:
Assistant
现在让我找到计数器递增的位置:
Assistant
现在找 spec_num_accepted_tokens 被设置的地方:
Assistant
现在找 update_spec_metrics 的调用者:
Assistant
现在查找 result.num_accepted_tokens 的来源:
Assistant
现在查找 num_accepted_tokens 设置的位置:
Assistant
现在找 accept_lens 的设置位置:
Assistant
让我查找 eagle_worker_v2 中的 verify 和 accept 逻辑:
Assistant
现在查找 sample 函数和验证逻辑,这是关键:
Assistant
让我查找 verify_tree_greedy_func:
Assistant
现在查找 llama_eagle3.py 中的 draft forward:
Assistant
现在查找 draft KV cache 同步和 rewind 逻辑:
Assistant
现在让我查找 GLA 相关的坍缺 bug 证据和 minicpm_backend:
Assistant
让我现在检查梯度流中是否存在一个决定性的常量 token 问题:
Assistant
现在让我寻找关键的一个线索:aux_hidden_states 的索引和层输入:
Assistant
现在让我看看 draft 的 forward 中是否存在索引不匹配的问题:
Assistant
现在让我找 hidden_states 在哪里被初始化和设置:
Assistant
现在让我搜索一个关键的问题:forward_batch.spec_info 的 hidden_states 是否被正确初始化和更新:
Assistant
现在让我找到最关键的一个问题:当 accept_len 和 predict 不匹配时会发生什么:
Assistant
现在让我找到关键问题 - 当模型总是拒绝 spec token 时会发生什么:
Assistant
现在让我查找一个关键的问题: 当采样时 target 和 draft 是否使用不同的方法(target greedy vs draft multinomial 或者反过来):
Assistant
现在我有了足够的信息。让我最后检查一下 draft forward 时候是否有可能永远输出相同的 token:
Assistant
完美!现在让我生成最终的调研报告。我已经发现了多个关键线索,现在做最后的验证:
Assistant
- User
Assistant
我来深度调研这个 SGLang fork,逐一回答这 10 个问题。
Assistant
Let me find the key files systematically:
Assistant
Now let me read the key files in parallel:
Assistant
Now let me check the Req class and scheduler:
Assistant
Now let me check the scheduler's main loop and HTTP server:
Assistant
Now let me check HTTP server and Eagle/spec info:
Assistant
Now let me check for Eagle/spec_info structures:
Assistant
Now let me check for CUDA graph and RNG information:
Assistant
Let me check sampling and decode batch processing:
Assistant
Now let me check for MambaPool state structure:
Assistant
Now let me check for pause/quiesce mechanisms:
Assistant
Let me now search for specific MiniCPM model and attn backend configuration:
Assistant
Now let me check for sampling behavior in MiniCPM or existing update mechanisms:
Assistant
- User
Assistant
我来系统审计热路径上的 profiling/仪表残留。先读取关键文件。
Assistant
关键环境变量确认:
EAGLE_TRACE_FILE="${EAGLE_TRACE_FILE:-}"传空字符串(不是 unset)。现在读所有热路径文件。Assistant
现在读 minicpm_backend.py 和 hybrid_linear_attn_backend.py:
Assistant
现在检查 minicpm_backend.py 第2175行那个无条件
torch.cuda.synchronize()是否真的在热路径,以及_item()调用:Assistant
现在检查热路径的 EAGLE_TRACE_FILE 问题和 os.environ.get 调用:
Assistant
现在确认
EAGLE_TRACE_FILE的真实值:Assistant
_EAGLE_TRACE_PATH = ""→bool("")= False,所以 trace 分支不会进入。现在检查 hybrid_linear_attn_backend.py 的 nvtx 调用上下文:Assistant
MiniCPM-SALA 使用
MiniCPMHybridConfig,所以mammaish_config不为 None,即update_mamba_state_after_mtp_verify中的 nvtx 代码每步都会触发。现在检查 modelopt_quant.py 里的 b12x profile:Assistant
关键发现:
_b12x_profile_call在_B12X_PROFILE=False时直接调用func()并返回(第222-223行),但每次 apply 都要调用这个函数,而_b12x_profile_call本身也是一次函数调用开销(closure + bool check)。现在检查 scheduler.py 里的 spec v1 路径:Assistant
time.perf_counter()调用只在ForwardMode.EXTEND下(prefill 路径),decode 路径不触发。现在检查 minicpm_attention_kernels.py 和 minicpm_sparse_kernels.py 里的 profile 代码:Assistant
关键发现:
_profile_begin()在第461、474、526、640、654行每步每层都在调用。来看它是否是热路径问题:Assistant
_profile_begin()调用了_profile_can_sync()再调用time.perf_counter(),但关键在于_profile_can_sync()里面有if not _MINICPM_PROFILE: return False,默认 False,所以_profile_begin()不会 synchronize,但仍然会调用time.perf_counter()。这是真实开销。现在确认:Assistant
_profile_can_sync()默认返回 False(_MINICPM_PROFILE=0),但_profile_begin()仍然调用time.perf_counter()并返回。然后_profile_end()在第67行立即 return(if not _MINICPM_PROFILE: return)。所以热路径上
_profile_begin()每次仍然执行:- 函数调用
_profile_can_sync()→ False time.perf_counter()调用(不可省略)
每 step 被调用多少次?我来数:
- minicpm_attention_kernels.py 在 decode mode 下:每个 std-attention 层(8层)每步 forward 被调用 ≥2次(_conv_start + _begin_start + _dec_start)
- minicpm_backend.py 中也有
_profile_begin()
现在查调用次数和 minicpm_backend.py 的
synchronize是否真的在热路径:- 函数调用
Assistant
现在确认 minicpm_backend.py 的 decode 热路径中
_profile_begin调用:Assistant
关键:在 decode 时,标准 attention 层每层有 3 个
_profile_begin()调用(行1441, 1453, 1521),加上来自 minicpm_attention_kernels.py 的调用。_profile_end虽然在_MINICPM_PROFILE=False时立即返回,但_profile_begin()每次仍会调用time.perf_counter()。现在确认 minicpm_backend.py line 2175 的
torch.cuda.synchronize()触发条件:这是在
else分支(即_MINICPM_PROFILE=False时),位于if self.attention_kernel_type == "flashinfer":块内,即每步 decode CUDA graph replay 都触发。这是最严重的问题。现在检查 EAGLE_FORCE_NO_ACCEPT 和其他 os.environ.get 调用:
Assistant
现在统计热路径上
os.environ.get()每步的调用次数:Assistant
minicpm.py 的两个
synchronize()在set_embed_and_head/set_embed中,只在初始化时调用,不在热路径。现在检查_mm_profile_begin()是否也有类似问题:Assistant
这是每层 forward 都调用 6 次
_profile_begin()/_profile_end()的地方。在 32 层模型中,每步触发 32×6 = 192 次(每次都调用time.perf_counter())。现在检查 llama_eagle3.py:Assistant
现在数出每步热路径的
nvtx.range_push/pop总调用数:Assistant
现在确认 minicpm_backend.py 中
synchronize()的具体上下文(line 2175 是 decode replay 热路径中的 else 分支):Assistant
这是最严重问题:当
_MINICPM_PROFILE=False时,begin_forward之后会 无条件torch.cuda.synchronize(),每步一次。这注释上写non_blocking=True,但之后立刻同步,把异步优势全消掉了。现在确认这个函数是否每步 decode 都调用到,是哪个方法:
Assistant