MultiTalkWav2VecEmbeds: 在 transformers v5 中, hidden_states 为 None (编码器忽略 output_hidden_states)

作者: ddrarie-lab创建于 2026年9月22日更新于 2026年9月22日

Summary

multitalk/nodes.py:248 crashes with TypeError: 'NoneType' object is not subscriptable when the environment has transformers v5 (tested 5.17.0). Root cause: in transformers v5, Wav2Vec2Encoder no longer returns hidden_states — both the output_hidden_states=True kwarg (passed at nodes.py:241) and the config flag are silently ignored, so embeddings.hidden_states is None.

Environment

  • ComfyUI 0.37.0 (its requirements install transformers 5.17.0)
  • ComfyUI-WanVideoWrapper 088128b (current main at time of report)
  • torch 2.8.0+cu128, Python 3.11, Linux (RunPod)
  • Model: wav2vec2-chinese-base_fp16.safetensors via Wav2VecModelLoader (same result via the legacy download loader)

Traceback

File ".../ComfyUI-WanVideoWrapper/multitalk/nodes.py", line 248, in process
    audio_emb = torch.stack(embeddings.hidden_states[1:], dim=1).squeeze(0)
                            ~~~~~~~~~~~~~~~~~~~~~~~~^^^^
TypeError: 'NoneType' object is not subscriptable

Evidence it's the encoder, not the wrapper call

Injected a probe right before line 248:

DBGMARK type= <class 'transformers.modeling_outputs.BaseModelOutput'>
        attrs= ['hidden_states', 'last_hidden_state']  hs= <class 'NoneType'>

Also tried forcing wav2vec2_config.output_hidden_states = True before model construction in Wav2VecModelLoader — still None. So in v5 the encoder itself stopped collecting per-layer states through both paths that multitalk/wav2vec2.py relies on (it subclasses transformers.Wav2Vec2Model and forwards the kwarg to self.encoder).

Workaround that works (verified on GPU)

Replace the encoder invocation in multitalk/wav2vec2.py with a version-agnostic manual collection via forward hooks on self.encoder.layers:

python
def _encoder_with_hidden_states(self, hidden_states, attention_mask=None):
    collected = [hidden_states]
    hooks = [l.register_forward_hook(
                lambda m, i, o: collected.append(o[0] if isinstance(o, tuple) else o))
             for l in self.encoder.layers]
    try:
        out = self.encoder(hidden_states, attention_mask=attention_mask, return_dict=True)
    finally:
        for h in hooks: h.remove()
    return out.last_hidden_state, tuple(collected)

and build BaseModelOutput(last_hidden_state=..., hidden_states=tuple(collected)). This restores the exact v4 contract (hidden_states[0] = encoder input, then one entry per layer) without pinning transformers.

内容来源: kijai/ComfyUI-WanVideoWrapper