MultiTalkWav2VecEmbeds: hidden_states is None with transformers v5 (encoder ignores output_hidden_states)
Summary
MultiTalkWav2VecEmbeds crashes with TypeError: 'NoneType' object is not subscriptable at multitalk/nodes.py:248 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.safetensorsviaWav2VecModelLoader(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 subscriptableEvidence 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:
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.
Happy to open a PR with this if useful. Thanks for the amazing wrapper!
Source: kijai/ComfyUI-WanVideoWrapper