LLM 서빙을 위한 탄력적 KV 캐시: 작동 가능한 회수 메커니즘과 청크 기반 프리필이 이미 그 격차를 좁히는 이유
Elastic KV Cache for LLM Serving:A Working Reclamation Mechanism, and Why Chunked Prefill Already Closes the Gap
한국어 초록
대규모 언어 모델(LLM) 서빙 엔진은 시작 시 키-값(KV) 캐시 크기를 한 번 결정하며, 최악의 프리필(prefill) 활성화를 대비해 예비 메모리를 영구적으로 확보해 둡니다. 디코드(decode) 위주의 단계에서는 이 예비 메모리가 유휴 상태로 유지되지만, 대규모 프리필에 필요한 바로 그 메모리이기 때문에 KV 풀에 넘겨줄 수는 없습니다. 본 논문에서는 이 예비 메모리를 회수할 수 있는지 질문을 던지고, 이를 검증하기 위한 메커니즘을 구축합니다. 제안하는 탄력적 KV 캐시는 다음 배치(batch)에 대한 스케줄러의 한 단계 앞선 뷰를 바탕으로, 디코드 중에는 예비 메모리를 KV 풀에 대여하고 프리필 전에 반환합니다. 이는 CUDA 가상 메모리 경로 상의 순수 유저스페이스에서 동작합니다. 즉, 층(layer)당 두 개의 물리 핸들이 하나의 연속 가상 범위로 매핑되므로 어텐션(attention) 커널(kernel)을 수정할 필요가 없으며 드라이버 패치도 요구되지 않습니다. 수 밀리초 만에 메모리 할당을 해제(decommit)하고 수십 밀리초 만에 재할당(recommit)하며, CUDA 그래프 및 접두 문맥(prefix) 캐싱과도 연동되고 메모리 부족(OOM) 오류를 전혀 유발하지 않습니다. 동일한 메모리를 정적으로 커밋하는 것은 프리필 급증 시 충돌을 일으켜 안전하지 않으므로 동적 전환이 필수적입니다. 메커니즘을 구축한 후, 본 논문은 이 메커니즘이 기반하는 전제를 검증하고 솔직한 부정적 결과를 보고합니다. 이 방식은 작은 프리필 청크 크기가 프리필 지연 시간을 크게 악화시킬 때만 이점이 있습니다. 실제 디코드 부하에 긴 프롬프트를 주입하는 통제된 실험에서 프리필은 연산 바운드(compute bound)이고 디코드는 스텝당 시퀀스별로 약 1개의 토큰(token)만 소비하기 때문에 해당 불이익은 미미했습니다(8,192토큰과 32,768토큰 청크 크기 간 중앙값 최초 토큰 생성 시간(TTFT) 차이는 약 1%). 단순히 max_num_batched_tokens를 낮추는 것이 거의 동일한 지연 시간으로 컨트롤러보다 더 많은 KV를 회수합니다. 또한 예비 메모리는 텐서 병렬화(tensor parallelism) 환경에서 희석되어 TP1의 KV 16%에서 TP4의 2.7%로 감소합니다. 본 논문에서는 예비 메모리 회수가 여전히 도움이 될 수 있는 조건을 정확히 명시하며, 이 메커니즘을 재사용 가능한 유저스페이스 탄력적 VMM 할당기로 공개합니다.
원문 초록
An LLM serving engine sizes its key-value (KV) cache once, at startup, permanently setting aside a reserve for the worst-case prefill activation. During decode-dominant phases that reserve sits idle, yet it cannot be handed to the KV pool because it is exactly the memory a large prefill needs. We ask whether this reserve is reclaimable, and build a mechanism to test it. Our elastic KV cache lends the reserve to the KV pool during decode and returns it before prefill, driven by the scheduler's one-step-ahead view of the next batch. It is pure userspace on the CUDA virtual-memory path: two physical handles mapped into one contiguous virtual range per layer, so the attention kernel is unchanged and no driver patch is required. It decommits in a few milliseconds and recommits in tens of milliseconds, works with CUDA graphs and prefix caching, and never triggers an out-of-memory event. A static commit of the same memory is unsafe, crashing on prefill bursts, which makes the dynamic toggle necessary. Having built the mechanism, we test the premise it rests on and report an honest negative result. It only pays off if a small prefill chunk size badly hurts prefill latency. In a controlled experiment injecting long prompts into a live decode load, that penalty is small (median time-to-first-token differs by about 1% between chunk sizes of 8192 and 32768 tokens), because prefill is compute bound and decode consumes only about one token per sequence per step. Simply lowering max_num_batched_tokens recovers more KV than the controller does, at nearly equal latency. The reserve also dilutes under tensor parallelism, from 16% of KV at TP1 to 2.7% at TP4. We state precisely when reclaiming the reserve could still help, and release the mechanism as a reusable userspace elastic-VMM allocator.
제출 이력
확인된 버전만 표시합니다. 전체 제출 이력은 arXiv 원문에서 확인하세요.
- arXiv:2608.23658v1제출 시각 미확인
함께 살펴볼 논문
공통 태그를 근거로 연결했습니다. 실제 인용 관계나 논문의 우수성을 뜻하지 않습니다.
공통 태그로 연결된 공개 논문이 아직 없습니다.
토론
이 논문과 연결된 포럼 글이 아직 없습니다.