[BugFix] Fix prefix-caching issue (#3726)

Signed-off-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
amy-why-3459 authored and GitHub committed 2026-05-29 01:51:54 +00:00
1 parent 834abdaf8b
commit 5dd1d0a772
3 files changed
+18 -4

No files matched your search

@@ -61,7 +61,11 @@ test_params = [
model=model,
stage_config_path=default_path,
use_stage_cli=True,
server_args=["--no-async-chunk"],
server_args=[
"--no-async-chunk",
"--stage-overrides",
'{"0": {"enable_prefix_caching": true}, "1": {"enable_prefix_caching": true}}',
],
),
id="default",
),
@@ -673,8 +673,13 @@ class Qwen3OmniMoeForConditionalGeneration(
span_len = input_ids.shape[0]
update_dict: OmniPayload = {}
if span_len > 1:
# prefill
# Prefix caching can reduce a new request's remaining prefill span to a
# single token. Use the runner-provided phase flag instead of span_len.
is_prefill = bool(payload.get("_omni_is_prefill", span_len > 1))
if is_prefill:
num_computed_tokens = payload.get("_omni_num_computed_tokens")
if num_computed_tokens is not None:
meta["num_processed_tokens"] = int(num_computed_tokens)
input_ids, input_embeds, update_dict = self.talker_preprocess_prefill(input_ids, input_embeds, payload)
code_predictor_codes = torch.zeros(
(input_embeds.shape[0], self.talker.num_code_groups),
+6 -1
View File
@@ -307,11 +307,16 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
)
hs_for_cache = hidden_states if self._model_needs_full_prefix_hidden_states() else None
# FIX: The .cpu attribute of slot_mapping is stale (not updated by the Triton
# _compute_slot_mapping_kernel which only writes to .gpu). We must use .gpu and
# sync back to CPU to get the correctly computed slot mapping.
slot_mapping_gpu = self.input_batch.block_table[0].slot_mapping.gpu
slot_mapping_cpu = slot_mapping_gpu[:num_tokens_padded].cpu()
self.omni_prefix_cache.update_omni_tensor_prefix_cache(
hidden_states=hs_for_cache,
multimodal_outputs=flatten_payload(multimodal_outputs) if multimodal_outputs else multimodal_outputs,
num_tokens_unpadded=num_tokens_unpadded,
slot_mapping=self.input_batch.block_table[0].slot_mapping.cpu,
slot_mapping=slot_mapping_cpu,
num_tokens_padded=num_tokens_padded,
skip_mm_cache_keys=self._deferred_prefix_cache_mm_keys(),
)