|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +import base64 |
| 5 | +import io |
| 6 | + |
| 7 | +import numpy as np |
| 8 | +import pytest |
| 9 | +import requests |
| 10 | +import torch |
| 11 | + |
| 12 | +from ...utils import RemoteOpenAIServer |
| 13 | + |
| 14 | +MODEL_NAME = "christian-pinto/Prithvi-EO-2.0-300M-TL-VLLM" |
| 15 | +DTYPE = "float16" |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(autouse=True) |
| 19 | +def v1(run_with_both_engines): |
| 20 | + # Simple autouse wrapper to run both engines for each test |
| 21 | + # This can be promoted up to conftest.py to run for every |
| 22 | + # test in a package |
| 23 | + pass |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(scope="module") |
| 27 | +def server(): |
| 28 | + args = [ |
| 29 | + "--task", |
| 30 | + "embed", |
| 31 | + # use half precision for speed and memory savings in CI environment |
| 32 | + "--dtype", |
| 33 | + DTYPE, |
| 34 | + "--enforce-eager", |
| 35 | + "--trust-remote-code", |
| 36 | + "--skip-tokenizer-init", |
| 37 | + "--max-num-seqs", |
| 38 | + "32" |
| 39 | + ] |
| 40 | + |
| 41 | + with RemoteOpenAIServer(MODEL_NAME, args) as remote_server: |
| 42 | + yield remote_server |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.asyncio |
| 46 | +@pytest.mark.parametrize("model_name", [MODEL_NAME]) |
| 47 | +async def test_single_request(server: RemoteOpenAIServer, model_name: str): |
| 48 | + |
| 49 | + pixel_values = torch.full((6, 512, 512), 1.0, dtype=torch.float16) |
| 50 | + location_coords = torch.full((1, 2), 1.0, dtype=torch.float16) |
| 51 | + |
| 52 | + buffer_tiff = io.BytesIO() |
| 53 | + torch.save(pixel_values, buffer_tiff) |
| 54 | + buffer_tiff.seek(0) |
| 55 | + binary_data = buffer_tiff.read() |
| 56 | + base64_tensor_embedding = base64.b64encode(binary_data).decode('utf-8') |
| 57 | + |
| 58 | + buffer_coord = io.BytesIO() |
| 59 | + torch.save(location_coords, buffer_coord) |
| 60 | + buffer_coord.seek(0) |
| 61 | + binary_data = buffer_coord.read() |
| 62 | + base64_coord_embedding = base64.b64encode(binary_data).decode('utf-8') |
| 63 | + |
| 64 | + prompt = { |
| 65 | + "model": |
| 66 | + model_name, |
| 67 | + "additional_data": { |
| 68 | + "prompt_token_ids": [1] |
| 69 | + }, |
| 70 | + "encoding_format": |
| 71 | + "base64", |
| 72 | + "messages": [{ |
| 73 | + "role": |
| 74 | + "user", |
| 75 | + "content": [{ |
| 76 | + "type": "image_embeds", |
| 77 | + "image_embeds": { |
| 78 | + "pixel_values": base64_tensor_embedding, |
| 79 | + "location_coords": base64_coord_embedding, |
| 80 | + }, |
| 81 | + }], |
| 82 | + }] |
| 83 | + } |
| 84 | + |
| 85 | + # test single pooling |
| 86 | + response = requests.post(server.url_for("pooling"), json=prompt) |
| 87 | + response.raise_for_status() |
| 88 | + |
| 89 | + output = response.json()["data"][0]['data'] |
| 90 | + |
| 91 | + np_response = np.frombuffer(base64.b64decode(output), dtype=np.float32) |
| 92 | + |
| 93 | + assert len(np_response) == 524288 |
0 commit comments