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

[Frontend] Multi-Modality Support for Loading Local Image Files #9915

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

chaunceyjiang
Copy link
Contributor

@chaunceyjiang chaunceyjiang commented Nov 1, 2024

FIX #8730
FIX #9742

Multi-Modality Support for Loading Local image Files

Copy link

github-actions bot commented Nov 1, 2024

👋 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.

🚀

@chaunceyjiang chaunceyjiang changed the title [Misc] Multi-Modality Support for Loading Local image Files [Misc] Multi-Modality Support for Loading Local Image Files Nov 1, 2024
@DarkLight1337
Copy link
Member

DarkLight1337 commented Nov 1, 2024

For security reasons, let's require a CLI flag to enable loading local image files.

@DarkLight1337 DarkLight1337 self-assigned this Nov 1, 2024
@chaunceyjiang
Copy link
Contributor Author

For security reasons, let's require a CLI flag to enable loading local image files.

@DarkLight1337 What do you reckon would be a good name for a CLI flag?

How about --trust-local-files ?
Should this flag be added to the vllm serve command?

@DarkLight1337
Copy link
Member

For security reasons, let's require a CLI flag to enable loading local image files.

@DarkLight1337 What do you reckon would be a good name for a CLI flag?

How about --trust-local-files ? Should this flag be added to the vllm serve command?

I think it is too easily confused with --trust-remote-code from HF.

Perhaps --trust-remote-access? Allowing API requests to read local image files basically does that.

@cedonley
Copy link
Contributor

cedonley commented Nov 1, 2024

I would suggest that the flag would instead be the allowed path vs. allowing full filesystem access.

For example, --allow-local-media-path=/some/path

Copy link

mergify bot commented Nov 4, 2024

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

@chaunceyjiang chaunceyjiang force-pushed the image_files branch 2 times, most recently from 2414a7e to 8c3572b Compare November 4, 2024 06:30
@mergify mergify bot removed the needs-rebase label Nov 4, 2024
@chaunceyjiang chaunceyjiang changed the title [Misc] Multi-Modality Support for Loading Local Image Files [Frontend] Multi-Modality Support for Loading Local Image Files Nov 4, 2024
@chaunceyjiang chaunceyjiang force-pushed the image_files branch 4 times, most recently from b96fa0c to e8d1ab6 Compare November 4, 2024 07:25
@chaunceyjiang
Copy link
Contributor Author

Test Code:

from openai import OpenAI

# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key=openai_api_key,
    base_url=openai_api_base,
)

models = client.models.list()

model = models.data[0].id




# Single-image input inference
def run_single_image() -> None:

    # Use image url in the payload
    # "https://upload.wikimedia.org/wikipedia/commons/d/da/2015_Kaczka_krzy%C5%BCowka_w_wodzie_%28samiec%29.jpg"
    image_url = "file:///root/jxy/vllm-source/vllm/duck.jpg"
    chat_completion_from_url = client.chat.completions.create(
        messages=[{
            "role":
            "user",
            "content": [
                {
                    "type": "text",
                    "text": "What's in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": image_url
                    },
                },
            ],
        }],
        model=model,
        max_completion_tokens=64,
    )

    result = chat_completion_from_url.choices[0].message.content
    print("Chat completion output from image url:", result)


def main() -> None:
   run_single_image()


if __name__ == "__main__":
    main()

Test 1:

# vllm serve microsoft/Phi-3.5-vision-instruct --task generate \
 --trust-remote-code --max-model-len 4096 --limit-mm-per-prompt image=2 \
 --dtype=float16 --enforce-eager \
 --allowed-local-media-path=/root/jxy/vllm-source/vllm


# python run_single_image.py 
Chat completion output from image url:  The image shows a single mallard duck swimming on a body of water. The duck has a distinctive green head, yellow bill, white neck ring, and brown chest. The water appears calm, creating a clear reflection of the duck.
# vllm serve microsoft/Phi-3.5-vision-instruct --task generate \
    --trust-remote-code --max-model-len 4096 --limit-mm-per-prompt image=2 \
--dtype=float16 --enforce-eager



# python run_single_image.py                                                                   2 ↵
..
openai.BadRequestError: Error code: 400 - {'object': 'error', 'message': "Invalid 'image_url': Cannot load local files without '--allowed-local-media-path'.", 'type': 'BadRequestError', 'param': None, 'code': 400}

@chaunceyjiang
Copy link
Contributor Author

/cc @DarkLight1337 PTAL.

@chaunceyjiang chaunceyjiang force-pushed the image_files branch 2 times, most recently from 5aa7b79 to d71bf75 Compare November 4, 2024 08:08
vllm/multimodal/utils.py Outdated Show resolved Hide resolved
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
vllm/multimodal/utils.py Outdated Show resolved Hide resolved
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.

The implementation looks good, can you add some tests to verify this?

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 implementing this!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) November 4, 2024 14:22
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 4, 2024
@DarkLight1337 DarkLight1337 merged commit ac6b8f1 into vllm-project:main Nov 4, 2024
73 checks passed
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
richardsliu pushed a commit to richardsliu/vllm that referenced this pull request Nov 4, 2024
@chaunceyjiang chaunceyjiang deleted the image_files branch November 5, 2024 01:58
bigPYJ1151 pushed a commit to bigPYJ1151/vllm that referenced this pull request Nov 5, 2024
DarkLight1337 pushed a commit that referenced this pull request Nov 5, 2024
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
KuntaiDu pushed a commit to KuntaiDu/vllm that referenced this pull request Nov 20, 2024
mfournioux pushed a commit to mfournioux/vllm that referenced this pull request Nov 20, 2024
tlrmchlsmth pushed a commit to neuralmagic/vllm that referenced this pull request Nov 23, 2024
sleepwalker2017 pushed a commit to sleepwalker2017/vllm that referenced this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
3 participants