From ff3d5aff7509cd36d49e7a320c910552f652a9c9 Mon Sep 17 00:00:00 2001 From: Jinzhe Pan <48981407+Eigensystem@users.noreply.github.com> Date: Mon, 16 Feb 2026 04:26:35 +0800 Subject: [PATCH] [Fix] hunyuan postprecessing issue (#1104) --- fastvideo/configs/pipelines/hunyuangamecraft.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fastvideo/configs/pipelines/hunyuangamecraft.py b/fastvideo/configs/pipelines/hunyuangamecraft.py index 24fc2f7cd..9feab31d1 100644 --- a/fastvideo/configs/pipelines/hunyuangamecraft.py +++ b/fastvideo/configs/pipelines/hunyuangamecraft.py @@ -57,10 +57,18 @@ def llama_preprocess_text(prompt: str) -> str: def llama_postprocess_text(outputs: BaseEncoderOutput) -> torch.Tensor: """Extract hidden states from LLaMA output, skipping instruction tokens.""" hidden_state_skip_layer = 2 - assert outputs.hidden_states is not None - hidden_states: tuple[torch.Tensor, ...] = outputs.hidden_states - last_hidden_state: torch.Tensor = hidden_states[-(hidden_state_skip_layer + - 1)] + hidden_states = outputs.hidden_states + if hidden_states is not None and len( + hidden_states) > hidden_state_skip_layer: + last_hidden_state: torch.Tensor = hidden_states[-( + hidden_state_skip_layer + 1)] + elif outputs.last_hidden_state is not None: + # Fallback for encoder outputs without hidden_states. + last_hidden_state = outputs.last_hidden_state + else: + raise ValueError( + "LLaMA encoder output must contain hidden_states or last_hidden_state." + ) crop_start = prompt_template_video.get("crop_start", -1) last_hidden_state = last_hidden_state[:, crop_start:] return last_hidden_state