[Bugfix] Fix qwen3-omni async thinker to talker decode alignment for #1758 (#2019)

This commit is contained in:
Sy03 authored and GitHub committed 2026-03-26 11:07:11 +08:00
1 parent 16b99c3444
commit d15c91d6d2
2 files changed
+140 -3

No files matched your search

@@ -602,10 +602,17 @@ class Qwen3OmniMoeForConditionalGeneration(
dtype=torch.long,
)
update_dict["code_predictor_codes"] = code_predictor_codes
update_dict["num_processed_tokens_delta"] = span_len
else:
# decode
if not info_dict.get("decode_flag", False):
info_dict["num_processed_tokens"] = 0
# Prefill already consumed the first text token via the
# assistant bootstrap path, so decode starts from the
# remaining-text boundary rather than cumulative index 0.
prefill_consumed_text_tokens = info_dict.get("prefill_consumed_text_tokens")
if prefill_consumed_text_tokens is None:
raise RuntimeError("Missing prefill_consumed_text_tokens for talker decode handoff.")
info_dict["num_processed_tokens"] = prefill_consumed_text_tokens
update_dict["decode_flag"] = True
last_talker_hidden, text_step, update_dict = self.talker_preprocess_decode(
@@ -613,7 +620,8 @@ class Qwen3OmniMoeForConditionalGeneration(
)
update_dict["mtp_inputs"] = last_talker_hidden, text_step
update_dict["num_processed_tokens"] = info_dict.get("num_processed_tokens", 0) + span_len
processed_delta = update_dict.pop("num_processed_tokens_delta")
update_dict["num_processed_tokens"] = info_dict.get("num_processed_tokens", 0) + processed_delta
return input_ids, input_embeds, update_dict
def talker_mtp(
@@ -782,6 +790,7 @@ class Qwen3OmniMoeForConditionalGeneration(
update_dict["tts_pad_embed_projected"] = pad_proj.detach()
except Exception:
pass
update_dict["prefill_consumed_text_tokens"] = 1
self._talker_cache_thinker_decode_embeds(info_dict, update_dict)
return req_input_ids[start_index:end_index], req_embeds[start_index:end_index], update_dict
@@ -909,10 +918,12 @@ class Qwen3OmniMoeForConditionalGeneration(
start_index = info_dict.get("num_processed_tokens", 0)
thinker_output_token_ids = info_dict.get("thinker_output_token_ids", [])
if start_index >= len(thinker_output_token_ids) - 1:
update_dict["num_processed_tokens_delta"] = 0
if info_dict.get("finished_flag"):
return self.tts_pad_embed.to(device)
update_dict["finished_flag"] = True
return self.tts_eos_embed.to(device)
if cached_thinker_decode_embeds is not None and start_index < cached_thinker_decode_embeds.shape[0]:
cached_thinker_decode_embeds = cached_thinker_decode_embeds.to(device)
thinker_embed = cached_thinker_decode_embeds[start_index]
@@ -921,8 +932,12 @@ class Qwen3OmniMoeForConditionalGeneration(
cached_thinker_decode_embeds = torch.cat([cached_thinker_decode_embeds, thinker_decode_embed], dim=0)
update_dict["cached_thinker_decode_embeddings"] = cached_thinker_decode_embeds
else:
thinker_embed = thinker_decode_embed.to(device)
thinker_embed = thinker_decode_embed
if thinker_embed.device != device:
thinker_embed = thinker_embed.to(device)
update_dict["thinker_decode_embeddings"] = None
update_dict["num_processed_tokens_delta"] = 1
return self.talker.text_projection(thinker_embed).to(device)
def talker_preprocess_decode(