Skip to content

Qwen2.5Omni Repeatedly Calculates Audio/Video/Image Features #40476

Description

@CharlesGong12

System Info

  • transformers version: 4.54.1
  • Platform: Linux-5.10.134-16.3.al8.x86_64-x86_64-with-glibc2.39
  • Python version: 3.10.15
  • Huggingface_hub version: 0.34.3
  • Safetensors version: 0.5.3
  • Accelerate version: 1.7.0
  • Accelerate config: not found
  • DeepSpeed version: 0.16.3
  • PyTorch version (accelerator?): 2.6.0+cu126 (CUDA)
  • Tensorflow version (GPU?): 2.16.2 (False)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using distributed or parallel set-up in script?:
  • Using GPU in script?:

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

My code is:

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)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions