Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/Build] VLM Test Consolidation #9372

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

alex-jw-brooks
Copy link
Contributor

@alex-jw-brooks alex-jw-brooks commented Oct 15, 2024

*This PR is large because it's touching pretty much all of the VLM tests - the place where they are consolidated into, i.e., where new model tests would be added is here. The place that each of these eventually land to run the vLLM/HF runners (for all of the tests types) is here!

Overview

Most of the multi-modal image/video tests in vLLM do the same thing, but have small tweaks to things like

  • prompt format / model-specific multimodal tokens
  • data types
  • number of logprobs being compared
  • decorators (e.g., @large_gpu_test, which may control spawning the tests in a new process)
    and so on.

However, the structure of the tests themselves is very similar, and pretty much always consists of some boilerplate to configure instances of HfRunner / VllmRunner and compare greedy logprobs in some common _run_test function, which will then be wrapped in a test_ function with different options, e.g., size_factors, being parametrized.

This PR aims to consolidate a lot of the redundancy in vLLM's multimodal tests, starting with the visual tests, but in a way that can also (hopefully) be easily extended to other types, e.g., audio.

The way this is accomplished is by defining five types of test, which can cover most of our visual model tests:

  • single image
  • multiple images
  • visual embeddings (i.e., vLLM gets image embeddings, HF model gets images)
  • video
  • custom inputs, i.e., some other prepepared input for some edge-case for specific models

and defining test wrappers for each of them, each of which leverage common utilities and invoke a common run_test, which is written to be model-agnostic. As such, to add a test for a new type of model, you should be able to (mostly) add a new object configuring a model for the VLM_TEST_SETTINGS & only need to worry about things that are model-specific, e.g., post-processing on the VLLM runner output.

Example 1: GLM-4

Here is an example of an object describing the GLM-4 tests.

    "glm4": VLMTestInfo(
        models="THUDM/glm-4v-9b",
        test_type=VLMTestType.IMAGE,
        prompt_formatter=identity,
        fork_new_process_for_each_test=True,
        img_idx_to_prompt=lambda idx: "",
        max_model_len=2048,
        max_num_seqs=2,
        dtype="bfloat16",
        get_stop_token_ids=lambda tok: [151329, 151336, 151338],
        skip=(get_memory_gb() < 48), # Large GPU test
        patch_hf_runner=vlm_utils.glm_patch_hf_runner,
    ),

Which indicates that we should run a test single image test, using the default single image prompt / image token, without additional prompt formatting. This will actually result in four tests, because it runs the default size factors as separate pytest cases. Additionally, each test case will run in a separate process, similar to if we wrote a test with @large_gpu_test(min_gb=48) to ensure resources are still cleaned up correctly.

Example 2: Phi3v

Phi3v is a model that supports multiple images, so it has single & mutli image tests. This is a pretty good example of what our multi-image tests look like most of the time, but there are a few quirks specific to the model, e.g., needing to use eager attention when running the HF model. The option below configures both the single & multi-image tests for the default size factors.

    "phi3v": VLMTestInfo(
        models="microsoft/Phi-3.5-vision-instruct",
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"<|user|>\n{img_prompt}<|end|>\n<|assistant|>\n", # noqa: E501
        img_idx_to_prompt=lambda idx: f"<|image_{idx}|>\n",
        max_model_len=4096,
        max_num_seqs=2,
        # use eager mode for hf runner, since phi3v didn't work with flash_attn
        model_kwargs={"_attn_implementation": "eager"},
        use_tokenizer_eos=True,
        vllm_output_post_proc=vlm_utils.phi3v_vllm_to_hf_output,
        num_logprobs=10,
    ),

So as a result of the default size factors, when this gets picked up, it will run 4 single image tests (one per size factor) and 4 multi image tests (one per size factor). Settings like max_model_len and max_num_seqs etc which are common are used in all the test types.

Other Implementation details

  • Each VLMTestInfo has the flexibility to set the things we would normally parametrize, e.g., size_factors. This is accomplished by consuming all of the VLM_TEST_SETTINGS, dropping things that are marked as skipped / tests that don't have the corresponding test_type, and then taking an itertools product over specific fields (e.g.,models, num_tokens, size_factors/fixed_sizes, dtype etc) for each test that matched so that each combination will run as its own test.

  • Each test type has two implementations; the normal one, and a heavy version which is identical, but runs each test in a new process. If a test sets fork_new_process_for_each_test=True, it will run in the heavy version, which is wrapped in the @fork_new_process_for_each_test decorator.

    • This can be paired with the skip field to achieve the same effect of some of our existing decorators for cleaning up resources. For example, setting VLMTestInfo(..., fork_new_process_for_each_test=True, skip=(get_memory_gb() < 48)) will behave like @large_gpu_test(min_gb=48).
  • A lot of the current tests use very slight variations of the same prompts. This PR is aligning most of them on a common prompts, so the scores will change slightly. The settings for most models should (hopefully) be the same though; for each model, I ensured that if the prompts matched, the vLLM runner/hf runner produced the same output as I was porting them.

  • In some cases, e.g., paligemma, the prompt is quite different, and using the default one fails the logprobs check. This is why in some cases the prompt is set directly for some models.

  • There are a couple of other tests here that didn't really fit (e.g., the quantized InternVL test and error case for Llava). For now, I left these where they were, since I thought it might be a good idea to figure out if we prefer this to somewhere In between (e.g., keeping in model's tests in its own file, but using common test runner here) first

  • To handle stuff like audio, I think it should be pretty similar to handling images vs. video; if we choose to make this sort of change, hopefully we can just add a new test_type to pass audio through the common wrapper for the vllm/hf runners

  • For stuff like quantized tests - some thoughts for what would feel nice might be a good idea, but I imagine we probably could just pass the model / quantized model, and if its set, create two vLLM runners instead of a HF/vLLM runner

BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE


PR Checklist (Click to Expand)

Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Model] for adding a new model or improving an existing model. Model name should appear in the title.
  • [Frontend] For changes on the vLLM frontend (e.g., OpenAI API server, LLM class, etc.)
  • [Kernel] for changes affecting CUDA kernels or other compute kernels.
  • [Core] for changes in the core vLLM logic (e.g., LLMEngine, AsyncLLMEngine, Scheduler, etc.)
  • [Hardware][Vendor] for hardware-specific changes. Vendor name should appear in the prefix (e.g., [Hardware][AMD]).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to docs/source/ if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.

Adding or changing kernels

Each custom kernel needs a schema and one or more implementations to be registered with PyTorch.

  • Make sure custom ops are registered following PyTorch guidelines: Custom C++ and CUDA Operators and The Custom Operators Manual
  • Custom operations that return Tensors require meta-functions. Meta-functions should be implemented and registered in python so that dynamic dims can be handled automatically. See above documents for a description of meta-functions.
  • Use torch.libary.opcheck() to test the function registration and meta-function for any registered ops. See tests/kernels for examples.
  • When changing the C++ signature of an existing op, the schema must be updated to reflect the changes.
  • If a new custom type is needed, see the following document: Custom Class Support in PT2.

Notes for Large Changes

Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with rfc-required and might not go through the PR.

What to Expect for the Reviews

The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

Thank You

Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!

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.

🚀

@alex-jw-brooks alex-jw-brooks changed the title CI/Build VLM Test Consolidation [CI/Build] VLM Test Consolidation Oct 15, 2024
num_logprobs=num_logprobs,
tensor_parallel_size=1,
)
models = ["llava-hf/llava-1.5-7b-hf"]


@pytest.mark.parametrize("model", models)
Copy link
Member

Choose a reason for hiding this comment

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

We can make this a more general test, perhaps under engine tests (since it's actually testing the error handling inside LLMEngine)

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.

Thanks for spending so much effort on this! Some initial comments.

tests/models/decoder_only/vision_language/utils.py Outdated Show resolved Hide resolved
tests/models/decoder_only/vision_language/utils.py Outdated Show resolved Hide resolved
@@ -0,0 +1,999 @@
"""Common utility functions relating to different models that are useful
Copy link
Member

Choose a reason for hiding this comment

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

This file is pretty long. Can we split out each part into a separate file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! I'll split it up 😄

Copy link
Contributor Author

@alex-jw-brooks alex-jw-brooks Oct 17, 2024

Choose a reason for hiding this comment

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

I broke its contents up into a vlm_utils package. For now, it's still under the VLM tests, but I think we can also pull it up and bring other things into it in follow-ups if we want to (e.g., audio tests which be similar to the same changes I made for video, or the encoder/decoder vision tests for mllama)

####### Entrypoints for running different test types
# Wrappers for all the above, where the only difference
# is that each test runs in a separate process
def run_single_image_test(
Copy link
Member

@DarkLight1337 DarkLight1337 Oct 15, 2024

Choose a reason for hiding this comment

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

Is there an easy way to just run the tests for a single model or a custom subset of models, like the case for PP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - I don't think there is at the moment, but I think it can probably be done by setting IDs in the parametrize call using the model key as a prefix. I'll give try it this evening!

Copy link
Contributor Author

@alex-jw-brooks alex-jw-brooks Oct 17, 2024

Choose a reason for hiding this comment

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

I looked into a bit - I think the best way to do this is actually just using pytest's -k to substring match, since the model's key in the settings dict is already added as the first param to make it more clear which test failed.

Here is an example of how an expanded test case looks after parametrizing:

test_single_image_models[intern_vl-OpenGVLab/InternVL2-1B-128-5-half-None-size_wrapper19]

The key in the settings is always the first parameter in every test, so we can leverage [<key_name> as a matchable substring for running all of the tests for a specific architecture. Some examples:

  • Runs all of the types of tests for only llava - I added some notes to use _ in the model architectures for the keys. This way, the hyphen after llava prevents it from matching against the llava_next's tests
pytest test_models.py -k  "[llava-"
  • Run the tests for one of the two models used in InternVL's tests
pytest test_models.py -k "OpenGVLab/InternVL2-1B"

You can also use and/or inside of -k filters, so we can also do stuff like this to run just the single image llava tests, to run tests for multiple model types, etc. This also matches test_single_image_models_heavy, so we don't need to worry about which tests are using forked processes when testing like this

pytest test_models.py -k "test_single_image and [llava-"

I added a long comment with similar examples, and recommended using --collect-only to quickly check which tests pytests will run with a command before actually executing it here:

# NOTE: The convention of the test settings below is to lead each test key

@alex-jw-brooks alex-jw-brooks force-pushed the vlm_test_consolidation branch 2 times, most recently from 4ced439 to f9f9fc9 Compare October 17, 2024 20:43
@alex-jw-brooks
Copy link
Contributor Author

alex-jw-brooks commented Oct 17, 2024

Hey @DarkLight1337! Thanks for your patience - I addressed the initial feedback and rebased the branch. It's ready for another look when you have a moment! 🙂

@DarkLight1337
Copy link
Member

PTAL at the test failure.

@alex-jw-brooks
Copy link
Contributor Author

alex-jw-brooks commented Oct 22, 2024

Thanks @DarkLight1337 - I actually have been hitting the same error when I run the phi3v model tests in my environment for awhile (on main also - not just in my branch), so I am a bit surprised to see it failing in the CI now when it's been passing until the last few changes, when things are still okay on main.

In my environment, the phi3v tests seem to deterministically pass locally (here and on main) if the runner order in run_test is swapped so that the HF runner goes first, and deterministically fail if the vLLM runner goes first, which is also pretty strange 🤔 I'll keep digging and update once I have some resolution

@alex-jw-brooks
Copy link
Contributor Author

alex-jw-brooks commented Oct 22, 2024

I'm pretty sure the core of the issue is that this is okay:

model_name = "microsoft/Phi-3.5-vision-instruct"
from transformers import AutoImageProcessor
from transformers import AutoProcessor
AutoImageProcessor.from_pretrained(model_name, trust_remote_code=True)
AutoProcessor.from_pretrained(model_name, trust_remote_code=True)

but this throws the attribute error breaking the test.

model_name = "microsoft/Phi-3.5-vision-instruct"

from transformers import AutoImageProcessor
AutoImageProcessor.from_pretrained(model_name, trust_remote_code=True)

from transformers import AutoProcessor
AutoProcessor.from_pretrained(model_name, trust_remote_code=True)

I'm not exactly sure why the current tests are passing on main, but this makes sense why they would fail with the current order, because for phi3v, it uses the default mapper for image inputs, which imports and calls AutoImageProcessor.from_pretrained, and the HF runner imports and calls AutoProcessor.from_pretrained - the AutoProcessor import is also late because it calls torch.cuda.device_count().

I am still trying to find a good workaround here that hopefully won't cause cuda initialization issues, but also went ahead and opened an issue in Transformers as well huggingface/transformers#34307

@DarkLight1337
Copy link
Member

Let's see how HF side responds first.

@DarkLight1337
Copy link
Member

DarkLight1337 commented Oct 26, 2024

Seems that it will take them some time to fix it. Let's skip phi3v tests keep phi3v tests in their own file for now.

@alex-jw-brooks
Copy link
Contributor Author

Sounds good, thanks @DarkLight1337 - I've pulled in the most recent changes from main (mostly new internVL model tests, skips for chameleon, and new preprocessor tests I had separately added for qwen2vl/llava next) and separated the phi3v model tests back into its own file. I'm not sure if they will pass since the tests fail when I try to run test_phi3v.py locally, both on this branch and on main - let's see if they pass on this build! 🤞

For the Qwen2 stuff - I can definitely add model tests for that model, and also help look into why the output results seem garbled, but would it be possible to do it in a separate PR? Pulling all the updates coming in is a bit painful 🙂

Copy link

mergify bot commented Oct 29, 2024

This pull request has merge conflicts that must be resolved before it can be
merged. @alex-jw-brooks please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 29, 2024
@alex-jw-brooks
Copy link
Contributor Author

Just rebased again to update the skips in chameleon tests, but the multimodal decoder tests did pass in the last run!

@mergify mergify bot added the ci/build label Oct 29, 2024
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) October 30, 2024 02:28
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 30, 2024
@DarkLight1337
Copy link
Member

We also need to skip llava-next-video tests, and llava-next embedding tests.

The distributed tests should be updated to use the new test file.

auto-merge was automatically disabled October 30, 2024 05:13

Head branch was pushed to by a user without write access

@alex-jw-brooks
Copy link
Contributor Author

alex-jw-brooks commented Oct 30, 2024

Sounds good - disabled the llava next video tests, and fixed the build kite path for distributed tests.

For the llava next embeddings test, I only skipped test_models_text and left the large GPU test_models_image - I ran test_models_image with transformers 4.46.1 and confirmed it passes

Signed-off-by: Alex-Brooks <[email protected]>

Disable failing llava next tests

Signed-off-by: Alex-Brooks <[email protected]>
@simon-mo simon-mo merged commit cc98f1e into vllm-project:main Oct 30, 2024
77 of 79 checks passed
rasmith pushed a commit to rasmith/vllm that referenced this pull request Oct 30, 2024
Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Randall Smith <[email protected]>
NickLucche pushed a commit to NickLucche/vllm that referenced this pull request Oct 31, 2024
NickLucche pushed a commit to NickLucche/vllm that referenced this pull request Oct 31, 2024
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Nov 4, 2024
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Nov 4, 2024
Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Linkun Chen <[email protected]>
hissu-hyvarinen pushed a commit to ROCm/vllm that referenced this pull request Nov 6, 2024
JC1DA pushed a commit to JC1DA/vllm that referenced this pull request Nov 11, 2024
sumitd2 pushed a commit to sumitd2/vllm that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build 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.

3 participants