These patches are fragile and non-obvious. Removing or simplifying any of them without validation will likely crash generation or produce garbage audio. Treat them as critical.
qwen-tts==0.1.1 was designed for transformers 4.x. We're using transformers 5.12.1 for CVE-2026-1839. The Dockerfile and runtime code monkeypatch several internal behaviors to keep both backends (OpenVINO and PyTorch) working.
Both TTS_BACKEND=openvino and TTS_BACKEND=pytorch are working under transformers 5.12.1
with these patches in place.
qwen-tts==0.1.1hard-pinstransformers==4.57.3.- Dockerfile installs it
--no-deps, then separately installstransformers==5.12.1. - All code in qwen_tts is NOT fully validated under T5; these patches compensate.
- speech_vq.py:
- Overrides
intra_op_num_threadsfrom 1 to 6 for ONNX Runtime. - Fragile: depends on exact string; future qwen-tts releases may break this.
- Overrides
- modeling_persona_forge_tokenizer_v2.py:
- Strips
@check_model_inputsdecorator that breaks under T5.
- Strips
- modeling_mimi.py:
- Renames
create_sliding_window_causal_mask→create_causal_maskdue to T5 symbol changes.
- Renames
- modeling_rope_utils.py:
- Injects custom
_compute_default_rope_parametersand sets"default"as init function because T5 changed how RoPE is wired.
- Injects custom
- Replaces direct use of initialization helpers with explicit imports (
from transformers import initialization as init). - Replaces
module.weight.data.normal_/zero_/fill_calls withinit.normal_,init.zeros_,init.ones_. - Adds guard for
padding_idxto avoid errors on meta-device init. - Replaces
input_embeds/"input_embeds"withinputs_embeds/"inputs_embeds". - Removes incompatible
cache_positionpasses in new signatures.
- Removes
layer_type_validationimport from T4; substitutesself.validate_layer_type().
- qwen-tts registers
inv_freqas non-persistent; T5 can materialize it uninitialized on meta-device. repair_rotary_buffers:- Recomputes
inv_freqfrom therope_init_fnand validates it (finite, positive, decreasing, starts at 1.0 for default type). - Required after every model load under T5.
- Recomputes
- Dockerfile injects custom
_compute_default_rope_parametersintomodeling_rope_utilsand sets"default"as init function.
Applied at model-load time (for both backends) via patch_talker_prepare_inputs().
Three issues fixed in one patch:
-
Stale inputs_embeds bug (primary crash cause for PyTorch backend): T5's centralized
prepare_inputs_for_generationforwards all model_kwargs, including the original long-sequenceinputs_embedsfrom step 1, into every decode step. The talker'sforwardusesinputs_embeds.shape[1] > 1to detect prefill; with stale embeds on a 1-token decode step, it re-enters the prefill path → wrong masks vs. K/V cache → attention corruption → matmul crash. Fix: dropinputs_embedsfrom model_inputs on non-first iterations. -
Full input_ids on decode steps: T5 passes the accumulated (B, N)
input_idsinstead of just the last token. The talker usesinput_ids.shape[1]for RoPE + codec embedding; N>1 produces garbage RoPE/logits, EOS ≈ 0, runs to capacity. Fix: clipinput_idsto[:, -1:]in decode steps. -
Stale attention_mask leak: A prefill attention_mask (e.g. (1, 171)) leaks into decode steps and corrupts causal mask creation and Q/K/V lengths. Fix: pop
attention_maskfrom model_inputs on non-first iterations.
CRITICAL: reverting any of these fixes under T5 will crash (pytorch) or produce non-terminating/garbage generation (both backends).
Applied at model-load time via patch_eager_attention_mask_broadcast().
-
sdpa_attention_forward stale-mask slicing: If a 4D attention_mask's Q/K dimensions don't match the current query and key lengths, it is sliced to match. Without this, stale masks from prefill cause shape mismatches in SDPA attention.
-
create_causal_mask / create_sliding_window_causal_mask decode-mode bypass: In decode mode (single-token input with existing cache), return
Noneinstead of building a mask. This avoids stale prefill-length masks being used to create incorrect causal masks. Patchestransformers.masking_utils,modeling_persona_forge, and the tokenizer module which has its own imports.
- If bumping transformers, qwen-tts, or related deps, assume these patches need review and retesting.
- Do not "clean up" these patches unless you've proven they're no longer needed with a full run on both backends.