Refactor eagle bigram key matching (#13714)

This commit is contained in:
Liangsheng Yin
2025-11-22 20:40:42 +08:00
committed by GitHub
parent a92afb00c6
commit ac43822634
7 changed files with 89 additions and 181 deletions

View File

@@ -13,7 +13,7 @@
# ==============================================================================
"""Common utilities."""
from typing import Any, Optional, Tuple
from typing import Any, List, Optional, Tuple
import torch
import triton
@@ -241,3 +241,13 @@ def maybe_init_custom_mem_pool(
return init_mooncake_custom_mem_pool(device)
else:
return False, None, None
def convert_to_bigram_key(tokens: List[int]) -> List[Tuple[int, int]]:
# EAGLE uses bigram keys in the radix tree since draft sequence is the one-token-shifted version of target
# [1, 2, 3, 4] -> [(1,2), (2,3), (3,4)]
if len(tokens) and isinstance(tokens[0], tuple):
return tokens
if len(tokens) < 2:
return []
return [(tokens[i], tokens[i + 1]) for i in range(len(tokens) - 1)]