[BugFix] Fix prefer_model_sampler token history in async scheduling (#3681)

Signed-off-by: zengchuang <zengchuang3@huawei.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Zeng ChuangandClaude Opus 4.7 authored and GitHub committed 2026-05-22 14:29:46 +08:00
1 parent 0ed3186db1
commit f0af3ab200
3 files changed
+90 -72

No files matched your search

@@ -406,6 +406,9 @@ def test_gpu_ar_model_runner_prefers_model_sampler_when_opted_in():
self.updated = False
def update_async_output_token_ids(self):
# After PR 3681 fix, update_async_output_token_ids is called
# BEFORE model sampler path to ensure async placeholder repair
# runs for all sampling paths
self.updated = True
_, GPUARModelRunner = _cosyvoice3_model_and_runner()
@@ -420,7 +423,7 @@ def test_gpu_ar_model_runner_prefers_model_sampler_when_opted_in():
out = runner._sample(torch.tensor([[0.1, 0.2]], dtype=torch.float32), spec_decode_metadata=None)
assert out is expected
assert runner.input_batch.updated is False
assert runner.input_batch.updated is True
assert len(calls) == 1
@@ -436,9 +439,13 @@ def test_gpu_ar_model_runner_supplies_req_output_history_to_model_sampler():
self.sampled_token_ids_cpu = None
self.async_copy_ready_event = None
self.prev_req_id_to_index = None
self.update_async_called = False
def update_async_output_token_ids(self):
raise AssertionError("fallback async repair should not run for model sampler path")
# After PR 3681 fix, update_async_output_token_ids is called
# BEFORE model sampler path to ensure async placeholder repair
# runs for all sampling paths
self.update_async_called = True
_, GPUARModelRunner = _cosyvoice3_model_and_runner()
runner = object.__new__(GPUARModelRunner)
@@ -454,6 +461,7 @@ def test_gpu_ar_model_runner_supplies_req_output_history_to_model_sampler():
runner._sample(torch.tensor([[0.1, 0.2]], dtype=torch.float32), spec_decode_metadata=None)
assert runner.input_batch.update_async_called is True
assert seen_histories == [[[1, 2, 3]]]
@@ -476,9 +484,13 @@ def test_gpu_ar_model_runner_repairs_async_placeholders_for_model_sampler():
self.sampled_token_ids_cpu = torch.tensor([[29]], dtype=torch.int32)
self.async_copy_ready_event = _ReadyEvent()
self.prev_req_id_to_index = {"rid-1": 0}
self.update_async_called = False
def update_async_output_token_ids(self):
raise AssertionError("fallback async repair should not run for model sampler path")
# After PR 3681 fix, update_async_output_token_ids is called
# BEFORE model sampler path to ensure async placeholder repair
# runs for all sampling paths (model sampler + fallback sampler)
self.update_async_called = True
_, GPUARModelRunner = _cosyvoice3_model_and_runner()
runner = object.__new__(GPUARModelRunner)
@@ -495,4 +507,5 @@ def test_gpu_ar_model_runner_repairs_async_placeholders_for_model_sampler():
runner._sample(torch.tensor([[0.1, 0.2]], dtype=torch.float32), spec_decode_metadata=None)
assert runner.input_batch.async_copy_ready_event.synced is True
assert runner.input_batch.update_async_called is True
assert seen_histories == [[[11, 29]]]