Fix first-token metadata and reused attention-layer indexing (#39328)

Co-authored-by: Jinghui Zhang <jinghui@meta.com>
Co-authored-by: Lucia Fang <116399278+luccafong@users.noreply.github.com>
This commit is contained in:
Lianmin Zheng
2026-09-15 15:22:26 -07:00
committed by GitHub
co-authored by Jinghui Zhang Lucia Fang
parent 08b1922405
commit 4da5599e93
4 changed files with 59 additions and 2 deletions
@@ -48,6 +48,25 @@ def test_pipeline_attention_metadata_is_indexed_by_global_layer_id():
assert companions[24] is companion24
def test_reuse_tables_pass_through_but_distinct_duplicates_raise():
looped = SimpleNamespace(layer_id=1)
companion = object()
attention_in = [SimpleNamespace(layer_id=0), looped, looped]
companions_in = [None, companion, companion]
attention, companions = index_attention_layers_by_global_id(
attention_in, companions_in
)
assert attention is attention_in
assert companions is companions_in
with pytest.raises(ValueError, match="duplicate attention layer_id: 2"):
index_attention_layers_by_global_id(
[SimpleNamespace(layer_id=2), SimpleNamespace(layer_id=2)], [None, None]
)
def test_model_runner_can_override_decode_graph_runner(monkeypatch):
from sglang.srt.runtime_context import get_context
@@ -46,6 +46,26 @@ class TestSetstatePreservesUnsetTimeSentinels(CustomTestCase):
self.assertAlmostEqual(hop2.wait_queue_entry_time, 123.456 - 9.0)
class TestOutputMetaInfo(CustomTestCase):
def test_first_token_latency_requires_valid_timestamps(self):
for created, first, expected in (
(1.0, 1.5, 0.5),
(0.0, 1.5, None),
(1.0, 0.0, None),
(1.0, 1.0, None),
(1.0, 0.5, None),
):
with self.subTest(created=created, first=first):
stats = rts.APIServerReqTimeStats()
stats.created_time = created
stats.first_token_time = first
meta_info = stats.convert_to_output_meta_info()
if expected is None:
self.assertNotIn("first_token_latency", meta_info)
else:
self.assertAlmostEqual(meta_info["first_token_latency"], expected)
class TestConvertToGenAiSpanAttrs(CustomTestCase):
def _stats_after_first_token(self) -> rts.APIServerReqTimeStats:
stats = rts.APIServerReqTimeStats()