model = Qwen2_5OmniForConditionalGeneration.from_pretrained(
args.model_name_or_path,
torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
attn_implementation="sdpa",
# attn_implementation="eager",
device_map="auto"
)
conversation = [
{
'role': 'system',
'content': [
{'type': 'text', 'text': 'You are a helpful assistant.'}
]
},
{
"role": "user",
"content": [
{"type": "video", "video": "xxx.mp4", 'max_frames': 80, "max_pixels": 50176},
{"type": "text", "text": "xxx"}
],
}
]
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios, images, videos = process_mm_info(conversation, use_audio_in_video=USE_AUDIO_IN_VIDEO)
inputs = processor(text=text, audio=audios, images=images, videos=videos, return_tensors="pt", padding=True, use_audio_in_video=USE_AUDIO_IN_VIDEO)
inputs = inputs.to(model.device).to(model.dtype)
# Inference: Generation of the output text and audio
text_ids = model.generate(**inputs, use_audio_in_video=USE_AUDIO_IN_VIDEO, return_audio=False, thinker_max_new_tokens=100)
text = processor.batch_decode(text_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
In the qwen2.5-omni code, Qwen2_5OmniThinkerForConditionalGeneration repeatedly calculates the feature of audio/video/image input for each text token generated. Does this cause significant redundancy? As shown here, this code segment does not check whether it's in the prefill phase. Consequently, every time a text token is generated, the forward function computes the same audio/image/video feature as in previous token generation phases.
System Info
transformersversion: 4.54.1Who can help?
No response
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
My code is:
Expected behavior
In the qwen2.5-omni code, Qwen2_5OmniThinkerForConditionalGeneration repeatedly calculates the feature of audio/video/image input for each text token generated. Does this cause significant redundancy? As shown here, this code segment does not check whether it's in the prefill phase. Consequently, every time a text token is generated, the forward function computes the same audio/image/video feature as in previous token generation phases.