Repository navigation
perf(irodori_tts): read the RF context K/V cache in place - #1168
Merged
Merged
Conversation
The context graph computes every DiT layer's text / speaker / caption K/V once per request. Each step graph then copied all of it into its own IO buffer (the single-branch graph through a host round trip), so the K/V was held twice on the device while sampling, once at the guided batch. Step graphs now read the context graph's outputs directly, through leaf tensors placed at the same addresses (a single-branch graph over a guided cache uses the leading slice). A plain use or view of those outputs would pull the context graph's nodes into the step graph. Step graphs are dropped whenever the context graph is rebuilt, so they never outlive it. The computation is unchanged and the output is byte-identical. The IO copy, its device memory and the host round trip are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
@KKTTSPJ Great improvement. Added some RTF datapoints:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The RF sampler computes every DiT layer's context K/V (text, speaker and caption tokens) once per request in the context graph. Each step graph then copied all of it into its own IO buffer with
ggml_backend_tensor_copy; the single-branch graph over a guided cache even read the whole cache back to the host to upload its first branch. While sampling, the K/V was therefore held twice on the device, once at the guided batch size.With this PR, step graphs read the context graph's outputs where they are. They use leaf tensors placed at the same addresses with
ggml_backend_tensor_alloc; a plain use or a view of those outputs would pull the context graph's own nodes into the step graph. A single-branch graph over a guided cache reads the leading slice (the conditional branch). Step graphs are dropped whenever the context graph is rebuilt, so they never point at freed memory.The computation is unchanged; only the IO copy, its device memory and the host round trip are removed.
src/models/irodori_tts/rf_dit.cpponly.How large the copy was
Per-graph buffers for one request (CUDA, Q8_0, 40 steps). The context has
max_text_len(256) + speaker +max_caption_len(512) tokens, and reference audio adds speaker tokens (218 for a 34.7 s reference) and a speaker CFG branch:Validation
RTX 5060 Ti (CUDA 12.8) and CPU, Windows.
Byte-identical output to
main(baseline binary:mainatdcec826b; the commits up to this branch's base611131c8only add WebGPU paths):guidance_min_t=0), the default,guidance_mode=joint,guidance_mode=alternating.--request-sequencesession per binary with 10 requests that change the cache shape and the guidance mode between requests (no reference, reference, reference + caption, alternating, joint, caption only,guidance_min_t=0,guidance_scale=0, repeated requests), for v4.1 Small and v4.1 Small MeanFlow: 10 of 10 identical for each, on CUDA and on CPU.Peak GPU memory (increase over idle, sampled every 50 ms; CUDA, 40 steps; "chunked" =
codec_decode_chunk_steps=100,codec_encode_chunk_steps=100). v4 Large rows are #1163 (now merged) with and without this change:The saving shows wherever sampling sets the peak. Without codec chunking, a long output or a reference encode sets it instead, so those cells do not move. v4 Small's K/V is small enough that the codec sets its peak in every case here, but the copy (195–362 MiB above) is gone there as well. Run times did not change.
🤖 Generated with Claude Code