[Diffusion] Add native KV cache initialization and Scheduler-managed block allocation (#6094)

Signed-off-by: zwhzzz0821 <zwhzzz0821@users.noreply.github.com>
Co-authored-by: zwhzzz0821 <zwhzzz0821@users.noreply.github.com>
This commit is contained in:
Yukim1andzwhzzz0821 authored and GitHub committed 2026-08-18 07:00:24 +00:00
1 parent b283215c28
commit 0a1846aa45
33 files changed
+2609 -265

No files matched your search

@@ -473,6 +473,38 @@ async def test_cancelled_future_does_not_kill_busy_loop():
_stop_engine(engine)
@pytest.mark.asyncio
async def test_native_kv_reservation_error_wakes_stream_without_killing_busy_loop():
loop = asyncio.get_running_loop()
engine = _make_engine_with_loop(loop)
def fail_reservation(*args, **kwargs):
raise RuntimeError("native allocation bug")
engine.scheduler._diffusion_kv_manager = SimpleNamespace(
has_request=lambda request_id: False,
reserve_request=fail_reservation,
free_request=lambda request_id: None,
)
request = _make_request("kv-error")
request.diffusion_kv_requests = (object(),)
try:
response_stream = engine.async_add_req_and_stream_response(request)
output_queue = engine._out_streams[request.request_id]
for _ in range(300):
if not output_queue.empty():
break
await asyncio.sleep(0.01)
assert not output_queue.empty(), "terminal KV allocation error was not delivered to the request stream"
output = await anext(response_stream)
assert output.error == "native allocation bug"
assert output.finished
assert engine.worker_thread.is_alive()
finally:
_stop_engine(engine)
# ─────────────────────────── _RpcTask basics ───────────────────────────────