[Test] Refactor hard coded device string in test files under compile/quantization/models/model_executor folders (#38901)

Signed-off-by: Liao, Wei <wei.liao@intel.com>
This commit is contained in:
wliao2
2026-04-15 11:02:35 +08:00
committed by GitHub
parent f4b42df048
commit 3abf858443
24 changed files with 122 additions and 66 deletions
@@ -7,6 +7,7 @@ from huggingface_hub import snapshot_download
from transformers import AutoConfig, AutoModel, CLIPImageProcessor
from vllm.distributed import cleanup_dist_env_and_memory
from vllm.platforms import current_platform
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE
from ....conftest import ImageTestAssets
@@ -15,6 +16,8 @@ from ....conftest import ImageTestAssets
# dynamic_module and trust_remote_code for hf_runner
DOWNLOAD_PATTERN = ["*.json", "*.py", "*.safetensors", "*.txt", "*.model"]
DEVICE_TYPE = current_platform.device_type
@torch.inference_mode()
def run_intern_vit_test(
@@ -39,9 +42,9 @@ def run_intern_vit_test(
hf_model = AutoModel.from_pretrained(
model, dtype=torch_dtype, trust_remote_code=True
).to("cuda")
).to(DEVICE_TYPE)
hf_outputs_per_image = [
hf_model(pixel_value.to("cuda")).last_hidden_state
hf_model(pixel_value.to(DEVICE_TYPE)).last_hidden_state
for pixel_value in pixel_values
]
@@ -53,9 +56,10 @@ def run_intern_vit_test(
del hf_model
cleanup_dist_env_and_memory()
vllm_model = vllm_model.to("cuda", torch_dtype)
vllm_model = vllm_model.to(DEVICE_TYPE, torch_dtype)
vllm_outputs_per_image = [
vllm_model(pixel_values=pixel_value.to("cuda")) for pixel_value in pixel_values
vllm_model(pixel_values=pixel_value.to(DEVICE_TYPE))
for pixel_value in pixel_values
]
del vllm_model
cleanup_dist_env_and_memory()
@@ -8,6 +8,7 @@ from transformers import AutoConfig, AutoModel, CLIPImageProcessor
from vllm.distributed import cleanup_dist_env_and_memory
from vllm.model_executor.models.radio import RadioModel
from vllm.platforms import current_platform
from vllm.transformers_utils.configs.radio import RadioConfig
from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE
@@ -17,6 +18,8 @@ from ....conftest import ImageTestAssets
# dynamic_module and trust_remote_code for hf_runner
DOWNLOAD_PATTERN = ["*.json", "*.py", "*.safetensors", "*.txt", "*.model"]
DEVICE_TYPE = current_platform.device_type
@torch.inference_mode()
def run_radio_test(
@@ -51,7 +54,7 @@ def run_radio_test(
config=hf_config,
dtype=torch_dtype,
trust_remote_code=True,
).to("cuda")
).to(DEVICE_TYPE)
hf_model.eval()
# A HF model has image normalization as a part of model's forward
@@ -62,7 +65,7 @@ def run_radio_test(
hf_model.make_preprocessor_external()
hf_outputs_per_image = [
hf_model(pixel_value.to("cuda")) for pixel_value in pixel_values
hf_model(pixel_value.to(DEVICE_TYPE)) for pixel_value in pixel_values
]
vllm_config = RadioConfig(
@@ -71,10 +74,11 @@ def run_radio_test(
)
vllm_model = RadioModel(vllm_config)
vllm_model.load_weights(hf_model.state_dict())
vllm_model = vllm_model.to("cuda", torch_dtype)
vllm_model = vllm_model.to(DEVICE_TYPE, torch_dtype)
vllm_outputs_per_image = [
vllm_model(pixel_values=pixel_value.to("cuda")) for pixel_value in pixel_values
vllm_model(pixel_values=pixel_value.to(DEVICE_TYPE))
for pixel_value in pixel_values
]
del vllm_model, hf_model
cleanup_dist_env_and_memory()