[Refactor] Declare model-local KV held outside the paged manager (#6171)

Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
Yueqian Lin authored and GitHub committed 2026-09-11 08:44:32 +08:00
1 parent 5a386d789f
commit 5c69fc2a8a
12 files changed
+1283 -3

No files matched your search

@@ -158,6 +158,17 @@ class MingFlashOmniTalkerForConditionalGeneration(nn.Module, CustomProcessMixin)
patch_size=self.patch_size,
)
def model_local_kv_specs(self):
"""Forward to the generator, which owns the talker's StaticCache.
``MingAudioGenerator`` is a plain object rather than a submodule, so
the module-tree walk cannot reach it on its own.
"""
generator = getattr(self, "audio_generator", None)
if generator is None:
return []
return generator.model_local_kv_specs()
@property
def device(self) -> torch.device:
return next(self.model.parameters()).device
@@ -41,6 +41,12 @@ from vllm_omni.model_executor.models.common.ming.cfm_solver import (
integrate_cfm_steps,
)
from vllm_omni.model_executor.models.common.ming.dit_blocks import CondEmbedder, DiTBlock, FinalLayer
from vllm_omni.model_executor.models.model_local_kv import (
ModelLocalKVScope,
ModelLocalKVSpec,
RowDriver,
spec_from_hf_config,
)
logger = init_logger(__name__)
@@ -575,6 +581,13 @@ class MingAudioGenerator:
for a single TTS request. The generator is stateless across requests.
"""
_STATIC_CACHE_LEN = 2048
"""Positions the talker's StaticCache is preallocated for.
Read by both ``_init_kv_cache`` and ``model_local_kv_specs`` so the
declaration cannot drift from the allocation.
"""
def __init__(
self,
config,
@@ -609,6 +622,49 @@ class MingAudioGenerator:
# trailing latent frames prepended on each decode call
self._vae_decode_pad_frames = 32
def model_local_kv_specs(self) -> list[ModelLocalKVSpec]:
"""Declare the talker's preallocated decode cache.
This is the case that a static table cannot hold. ``self._llm_config``
is a ``Qwen2Config`` resolved from the checkpoint at load time, so
layers, kv-heads and head-dim do not exist anywhere in this repo, and
the dtype is whatever the weights loaded as. Reading them off the same
objects ``_init_kv_cache`` builds from is the only way to get a real
number.
Unlike the other three this is not a ceiling that a short utterance
stays under. transformers v5 initializes ``StaticLayer`` lazily, but
the first write to a layer allocates all ``max_cache_len`` positions at
once rather than growing, so a prefill brings the full extent into
existence on step 0 of every generation.
Width is fixed at one row, not ``max_num_seqs``. ``forward`` takes only
``runtime_additional_information[0]`` and runs the whole AR loop inline
before returning, so one worker holds one cache no matter how many
sequences the scheduler admits. Declaring this per-sequence -- which an
earlier revision did, by deriving the multiplier from scope -- reported
``max_num_seqs`` times the real figure.
The caveat is that nothing enforces the serialization. ``StaticCache``
is built outside ``_sampler_pool``'s lock, so overlapping calls to
``generate_latents`` would coexist. If this model ever gains a
concurrent entry point, this row count is the line to revisit.
"""
return [
spec_from_hf_config(
self._llm_config,
name="talker_llm_static_cache",
dtype=next(self._model.parameters()).dtype,
physical_capacity_positions=self._STATIC_CACHE_LEN,
capacity_source=f"hardcoded max_cache_len={self._STATIC_CACHE_LEN} in _init_kv_cache",
scope=ModelLocalKVScope.INVOCATION,
rows=RowDriver.FIXED,
rows_fixed=1,
rows_reason="forward() handles one request and runs the AR loop inline",
allocation_note="full extent on first write per layer, not grown; rebuilt per text segment",
)
]
@cached_property
def _sampler_pool(self) -> CFMGraphExecutorPool | None:
device = next(self._model.parameters()).device
@@ -790,7 +846,7 @@ class MingAudioGenerator:
def _init_kv_cache(
self, use_static_cache: bool, device: torch.device, dtype: torch.dtype
) -> tuple[StaticCache | None, int]:
max_cache_len = 2048
max_cache_len = self._STATIC_CACHE_LEN
if not use_static_cache:
return None, max_cache_len
cache = StaticCache(