mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-15 01:45:02 +08:00
- **Add SPDX license headers to python source files**
- **Check for SPDX headers using pre-commit**
commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:18:24 2025 -0500
Add SPDX license headers to python source files
This commit adds SPDX license headers to python source files as
recommended to
the project by the Linux Foundation. These headers provide a concise way
that is
both human and machine readable for communicating license information
for each
source file. It helps avoid any ambiguity about the license of the code
and can
also be easily used by tools to help manage license compliance.
The Linux Foundation runs license scans against the codebase to help
ensure
we are in compliance with the licenses of the code we use, including
dependencies. Having these headers in place helps that tool do its job.
More information can be found on the SPDX site:
- https://spdx.dev/learn/handling-license-info/
Signed-off-by: Russell Bryant <rbryant@redhat.com>
commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:36:32 2025 -0500
Check for SPDX headers using pre-commit
Signed-off-by: Russell Bryant <rbryant@redhat.com>
---------
Signed-off-by: Russell Bryant <rbryant@redhat.com>
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from typing import Optional
|
|
|
|
import pytest
|
|
import torch
|
|
import torch.nn as nn
|
|
from huggingface_hub import snapshot_download
|
|
from transformers import AutoConfig, AutoModel, CLIPImageProcessor
|
|
|
|
from ....conftest import _ImageAssets
|
|
|
|
# we use snapshot_download to prevent conflicts between
|
|
# dynamic_module and trust_remote_code for hf_runner
|
|
DOWNLOAD_PATTERN = ["*.json", "*.py", "*.safetensors", "*.txt", "*.model"]
|
|
|
|
|
|
def run_intern_vit_test(
|
|
image_assets: _ImageAssets,
|
|
model_id: str,
|
|
*,
|
|
dtype: str,
|
|
distributed_executor_backend: Optional[str] = None,
|
|
):
|
|
model = snapshot_download(model_id, allow_patterns=DOWNLOAD_PATTERN)
|
|
|
|
img_processor = CLIPImageProcessor.from_pretrained(model)
|
|
images = [asset.pil_image for asset in image_assets]
|
|
pixel_values = [
|
|
img_processor(images, return_tensors='pt').pixel_values.to(dtype)
|
|
for images in images
|
|
]
|
|
|
|
config = AutoConfig.from_pretrained(model, trust_remote_code=True)
|
|
if not getattr(config, "norm_type", None):
|
|
config.norm_type = "rms_norm"
|
|
|
|
hf_model = AutoModel.from_pretrained(model,
|
|
torch_dtype=dtype,
|
|
trust_remote_code=True).to("cuda")
|
|
hf_outputs_per_image = [
|
|
hf_model(pixel_value.to("cuda")).last_hidden_state
|
|
for pixel_value in pixel_values
|
|
]
|
|
|
|
from vllm.distributed import cleanup_dist_env_and_memory
|
|
from vllm.model_executor.models.intern_vit import InternVisionModel
|
|
vllm_model = InternVisionModel(config)
|
|
vllm_model.load_weights(hf_model.state_dict().items())
|
|
|
|
del hf_model
|
|
cleanup_dist_env_and_memory()
|
|
|
|
vllm_model = vllm_model.to("cuda", dtype)
|
|
vllm_outputs_per_image = [
|
|
vllm_model(pixel_values=pixel_value.to("cuda"))
|
|
for pixel_value in pixel_values
|
|
]
|
|
del vllm_model
|
|
cleanup_dist_env_and_memory()
|
|
|
|
cos_similar = nn.CosineSimilarity(dim=-1)
|
|
for vllm_output, hf_output in zip(vllm_outputs_per_image,
|
|
hf_outputs_per_image):
|
|
assert cos_similar(vllm_output, hf_output).mean() > 0.99
|
|
|
|
|
|
@pytest.mark.parametrize("model_id", [
|
|
"OpenGVLab/InternViT-300M-448px",
|
|
"OpenGVLab/InternViT-6B-448px-V1-5",
|
|
])
|
|
@pytest.mark.parametrize("dtype", [torch.half])
|
|
@torch.inference_mode()
|
|
def test_models(dist_init, image_assets, model_id, dtype: str) -> None:
|
|
run_intern_vit_test(
|
|
image_assets,
|
|
model_id,
|
|
dtype=dtype,
|
|
)
|