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

[Bug]: Pixtral inference not working correctly with LLMEngine/AsyncEngine #8411

Closed
1 task done
larme opened this issue Sep 12, 2024 · 8 comments · Fixed by #8415
Closed
1 task done

[Bug]: Pixtral inference not working correctly with LLMEngine/AsyncEngine #8411

larme opened this issue Sep 12, 2024 · 8 comments · Fixed by #8415
Labels
bug Something isn't working

Comments

@larme
Copy link

larme commented Sep 12, 2024

Your current environment

The output of `python collect_env.py`
Collecting environment information...
PyTorch version: 2.4.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-119-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.2.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA A100 80GB PCIe
Nvidia driver version: 535.183.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.6
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.6
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        46 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               12
On-line CPU(s) list:                  0-11
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Xeon(R) Gold 6342 CPU @ 2.80GHz
CPU family:                           6
Model:                                106
Thread(s) per core:                   1
Core(s) per socket:                   12
Socket(s):                            1
Stepping:                             6
BogoMIPS:                             5600.12
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush acpi mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single intel_ppin ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves umip pku ospke gfni vaes vpclmulqdq rdpid md_clear flush_l1d arch_capabilities
Hypervisor vendor:                    Xen
Virtualization type:                  full
L1d cache:                            576 KiB (12 instances)
L1i cache:                            384 KiB (12 instances)
L2 cache:                             15 MiB (12 instances)
L3 cache:                             432 MiB (12 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-11
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-ml-py==11.525.150
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] nvidia-nvjitlink-cu12==12.6.68
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pyzmq==26.2.0
[pip3] torch==2.4.0
[pip3] torchvision==0.19.0
[pip3] transformers==4.44.2
[pip3] triton==3.0.0
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.6.1@3fd2b0d21cd9ec78de410fdf8aa1de840e9ad77a
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
�[4mGPU0	CPU Affinity	NUMA Affinity	GPU NUMA ID�[0m
GPU0	 X 	0-11	0		N/A

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

Model Input Dumps

No response

🐛 Describe the bug

This code snippets does not work

import PIL.Image
import uuid
from vllm import EngineArgs, LLMEngine
from vllm import SamplingParams, TextPrompt
from vllm.multimodal import MultiModalDataBuiltins

MODEL_ID = "mistral-community/pixtral-12b-240910"
ENGINE_ARGS = EngineArgs(
    model=MODEL_ID,
    tokenizer_mode="mistral",
    enable_prefix_caching=True,
    limit_mm_per_prompt=dict(image=4),
    max_num_batched_tokens=16384,
)
SAMPLING_PARAM = SamplingParams()

engine = LLMEngine.from_engine_args(ENGINE_ARGS)
prompt = "describe the image"

engine_inputs = TextPrompt(prompt=prompt)

image = PIL.Image.open("demo.jpg")
mm_data = MultiModalDataBuiltins(image=[image])
engine_inputs["multi_modal_data"] = mm_data

engine.add_request(uuid.uuid4().hex, engine_inputs, SAMPLING_PARAM)

while True:
    out = engine.step()
    for request_output in request_outputs:
        if request_output.finished:
            print(request_output)
    if not engine.has_unfinished_requests():
        break

This will give an output message like:

 File "/workspace/codes/example/vllm/pixtral-12b/venv/lib/python3.10/site-packages/vllm/model_executor/models/pixtral.py", line 117, in merge_multimodal_embeddings
    assert (seq_len == N_txt +
AssertionError: seq_len 7 should be equal to N_txt + N_img (7, 1200, 0)

It seems that I need to manually padding the input token ids with image_token_ids like this:

tokenizer = engine.get_tokenizer()
token_ids = tokenizer(prompt).input_ids
image_token_id = 10
token_ids = [image_token_id] * image_token_num + token_ids

engine_inputs = TokensPrompt(prompt_token_ids=token_ids)

mm_data = MultiModalDataBuiltins(image=[image])
engine_inputs["multi_modal_data"] = mm_data

To make it work.

AsyncLLMEngine also see the same limitation and I need similar modification to make it works like: https://github.com/bentoml/BentoVLLM/pull/71/files#diff-357f77bce00e63217bb5ec382293bca653276e58af9bdfb6e7c50ca9487e27aeR84-R94

Is this behavior intended or a bug?

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.
@larme larme added the bug Something isn't working label Sep 12, 2024
@DarkLight1337
Copy link
Member

Please see if the solutions in #8382 can solve the issue encountered by you

@patrickvonplaten
Copy link
Contributor

Also currently looking into the problem - also maybe see: #8415

@patrickvonplaten
Copy link
Contributor

patrickvonplaten commented Sep 12, 2024

Hey @larme,

Upon taking a closer look the problem here is actually not related to the initialization of the model, but occurs because images and the prompt are independently passed before being processed by mistral common's tokenizer.

When using the image and prompt have to be processed together by mistral common to ensure that the tokens are in the right format. See post below for code snippet.

@patrickvonplaten
Copy link
Contributor

@DarkLight1337 I'm not sure what the best way is to make sure users always pre-process with the MistralTokenizer. It's done automatically whenever requests are passed in chat format. Should we maybe throw an error if people try to pass a raw prompt to Pixtral so that the above error doesn't happen too much?

@DarkLight1337
Copy link
Member

DarkLight1337 commented Sep 12, 2024

If you have special tokens that are only available via your tokenizer, you may search the text for those tokens inside the input processor and throw an error if none are found.

@patrickvonplaten
Copy link
Contributor

If you have special tokens that are only available via your tokenizer, you may search the text for those tokens inside the input processor and throw an error if none are found.

Great idea - I'll add this to #8415

@patrickvonplaten
Copy link
Contributor

To close the loop - #8415 should fix images with incorrect image init & resizing.

Two things that I noticed:

    1. As @DarkLight1337 already mentioned before we have to disable chunked prefilling for now, so always set enable_chunked_prefill=True. @DarkLight1337 can we maybe set this as a default for pixtral?
    1. Previously, the image processing was done incorrectly - I've accidentally only taken the last image because it worked and because I didn't know about 1.), but this should be fixed now in [Hotfix][Pixtral] Fix multiple images bugs #8415

Here a complete more complex example that should illustrate how to use the model:

import PIL.Image
import uuid
from vllm import EngineArgs, LLMEngine
from vllm import SamplingParams, TokensPrompt
from vllm.multimodal import MultiModalDataBuiltins

from mistral_common.protocol.instruct.messages import (
    UserMessage,
    TextChunk,
    ImageURLChunk,
    ImageChunk,
)
from PIL import Image
from mistral_common.protocol.instruct.request import ChatCompletionRequest
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer

# MODEL_ID = "mistral-community/pixtral-12b-240910"
MODEL_ID = "mistralai/Pixtral-12B-2409"
ENGINE_ARGS = EngineArgs(
    model=MODEL_ID,
    tokenizer_mode="mistral",
    enable_chunked_prefill=False,
    limit_mm_per_prompt=dict(image=4),
    max_num_batched_tokens=16384,
    max_model_len=16384,
)
SAMPLING_PARAM = SamplingParams(temperature=0.0, max_tokens=512)

prompt = "describe the images"
image = PIL.Image.open("demo.jpg").resize((400, 500))
image_2 = PIL.Image.open("demo_2.jpg").resize((560, 800))
image_3 = PIL.Image.open("demo_3.jpg").resize((150, 200))
image_4 = PIL.Image.open("demo_4.jpg").resize((344, 444))

engine = LLMEngine.from_engine_args(ENGINE_ARGS)

tokenizer = engine.tokenizer.tokenizer.mistral

def create_image_input(images, prompt):
# tokenize images and text
    tokenized = tokenizer.encode_chat_completion(
        ChatCompletionRequest(
            messages=[
                UserMessage(
                    content=[
                        TextChunk(text=prompt),
                    ] + [ImageChunk(image=img) for img in images]
                )
            ],
            model="pixtral",
        )
    )

    engine_inputs = TokensPrompt(prompt_token_ids=tokenized.tokens)

    mm_data = MultiModalDataBuiltins(image=images)
    engine_inputs["multi_modal_data"] = mm_data

    return engine_inputs

engine.add_request(uuid.uuid4().hex, create_image_input([image, image_3], prompt), SAMPLING_PARAM)
engine.add_request(uuid.uuid4().hex, create_image_input([image_2], prompt), SAMPLING_PARAM)

count = 0
while True:
    out = engine.step()
    count += 1
    for request_output in out:
        if request_output.finished:
            print(request_output.outputs[0].text)

    if count == 2:
        engine.add_request(uuid.uuid4().hex, create_image_input([image, image_4], prompt), SAMPLING_PARAM)
    if not engine.has_unfinished_requests():
        break

@larme
Copy link
Author

larme commented Sep 13, 2024

thanks @patrickvonplaten ! This also works wonderfully in AsyncLLMEngine. We made an example here: https://github.com/bentoml/BentoVLLM/blob/main/pixtral-12b/service.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants