Skip to content

Conversation

litianjian
Copy link
Contributor

Add multi-video support for LLaVA-Onevision models.

Example

import av
import time
import numpy as np
from huggingface_hub import hf_hub_download
import vllm
from vllm import LLM, SamplingParams

MODEL="llava-hf/llava-onevision-qwen2-7b-ov-hf"

text_prompt = "<|im_start|>user <video> <video>\nWhat’s the difference between these two videos?.<|im_end|><|im_start|>assistant\n"

def read_video_pyav(container, indices):
    '''
    Decode the video with PyAV decoder.
    Args:
        container (`av.container.input.InputContainer`): PyAV container.
        indices (`List[int]`): List of frame indices to decode.
    Returns:
        result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
    '''
    frames = []
    container.seek(0)
    start_index = indices[0]
    end_index = indices[-1]
    for i, frame in enumerate(container.decode(video=0)):
        if i > end_index:
            break
        if i >= start_index and i in indices:
            frames.append(frame)
    return np.stack([x.to_ndarray(format="rgb24") for x in frames])


video_path = hf_hub_download(repo_id="raushan-testing-hf/videos-test", filename="sample_demo_1.mp4", repo_type="dataset")
container = av.open(video_path)
total_frames = container.streams.video[0].frames
indices = np.arange(0, total_frames, total_frames / 32).astype(int)
video = read_video_pyav(container, indices)

llm = LLM(model=MODEL, tensor_parallel_size=1)
sampling_params = SamplingParams(temperature=0.8,
                            top_p=0.95,
                            max_tokens=100)
outputs = llm.generate(
    {
        "prompt": text_prompt,
        "multi_modal_data": {
            "video": [video,video]
        }
    },
    sampling_params=sampling_params)

generated_text = ""
for o in outputs:
    generated_text += o.outputs[0].text
print(f"LLM output:{generated_text}")

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@DarkLight1337
Copy link
Member

FYI I found some problems with the chat template earlier (see #8874). Please double check that you're using the correct chat templates for examples/tests in this PR.

@DarkLight1337 DarkLight1337 changed the title [Bugfix][VLM]Add multi-video support for LLaVA-Onevision model [Model][VLM] Add multi-video support for LLaVA-Onevision model Sep 30, 2024
@DarkLight1337 DarkLight1337 changed the title [Model][VLM] Add multi-video support for LLaVA-Onevision model [Model][VLM] Add multi-video support for LLaVA-Onevision Sep 30, 2024
@DarkLight1337
Copy link
Member

Sorry for the long wait! Can you add a test with multi-video input so it is easy to verify that this works?

@litianjian
Copy link
Contributor Author

Sorry for the long wait! Can you add a test with multi-video input so it is easy to verify that this works?

Sorry for late response. I added a test with multi-video input.

@litianjian
Copy link
Contributor Author

I have updated the tests. Could you please review it when you're available? @DarkLight1337

@DarkLight1337
Copy link
Member

Meanwhile let's see if the tests pass CI.

Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the tests locally and they pass. Let's run the CI again.

Thanks for your patience!

@DarkLight1337 DarkLight1337 added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 28, 2024
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) October 28, 2024 13:51
@DarkLight1337 DarkLight1337 merged commit 5f8d807 into vllm-project:main Oct 28, 2024
59 checks passed
FerdinandZhong pushed a commit to FerdinandZhong/vllm that referenced this pull request Oct 29, 2024
rasmith pushed a commit to rasmith/vllm that referenced this pull request Oct 30, 2024
…t#8905)

Co-authored-by: litianjian <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Signed-off-by: Randall Smith <[email protected]>
sumitd2 pushed a commit to sumitd2/vllm that referenced this pull request Nov 14, 2024
…t#8905)

Co-authored-by: litianjian <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Signed-off-by: Sumit Dubey <[email protected]>
sleepwalker2017 pushed a commit to sleepwalker2017/vllm that referenced this pull request Dec 13, 2024
LeiWang1999 pushed a commit to LeiWang1999/vllm-bitblas that referenced this pull request Mar 26, 2025
…t#8905)

Co-authored-by: litianjian <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Signed-off-by: LeiWang1999 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants