diff --git a/tests/model_executor/model_loader/instanttensor_loader/test_weight_utils.py b/tests/model_executor/model_loader/instanttensor_loader/test_weight_utils.py index 09e0a19d11..3d15f6f1c5 100644 --- a/tests/model_executor/model_loader/instanttensor_loader/test_weight_utils.py +++ b/tests/model_executor/model_loader/instanttensor_loader/test_weight_utils.py @@ -2,9 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import glob -import tempfile -import huggingface_hub.constants import pytest import torch @@ -21,29 +19,27 @@ from vllm.platforms import current_platform reason="InstantTensor requires NVIDIA GPUs", ) def test_instanttensor_model_loader(): - with tempfile.TemporaryDirectory() as tmpdir: - huggingface_hub.constants.HF_HUB_OFFLINE = False - download_weights_from_hf( - "openai-community/gpt2", allow_patterns=["*.safetensors"], cache_dir=tmpdir - ) - safetensors = glob.glob(f"{tmpdir}/**/*.safetensors", recursive=True) - assert len(safetensors) > 0 + model_dir = download_weights_from_hf( + "openai-community/gpt2", cache_dir=None, allow_patterns=["*.safetensors"] + ) + safetensors = glob.glob(f"{model_dir}/*.safetensors") + assert len(safetensors) > 0 - instanttensor_tensors = {} - hf_safetensors_tensors = {} + instanttensor_tensors = {} + hf_safetensors_tensors = {} - for name, tensor in instanttensor_weights_iterator(safetensors, True): - instanttensor_tensors[name] = tensor.to("cpu") + for name, tensor in instanttensor_weights_iterator(safetensors, True): + instanttensor_tensors[name] = tensor.to("cpu") - for name, tensor in safetensors_weights_iterator(safetensors, True): - hf_safetensors_tensors[name] = tensor + for name, tensor in safetensors_weights_iterator(safetensors, True): + hf_safetensors_tensors[name] = tensor - assert len(instanttensor_tensors) == len(hf_safetensors_tensors) + assert len(instanttensor_tensors) == len(hf_safetensors_tensors) - for name, instanttensor_tensor in instanttensor_tensors.items(): - assert instanttensor_tensor.dtype == hf_safetensors_tensors[name].dtype - assert instanttensor_tensor.shape == hf_safetensors_tensors[name].shape - assert torch.all(instanttensor_tensor.eq(hf_safetensors_tensors[name])) + for name, instanttensor_tensor in instanttensor_tensors.items(): + assert instanttensor_tensor.dtype == hf_safetensors_tensors[name].dtype + assert instanttensor_tensor.shape == hf_safetensors_tensors[name].shape + assert torch.all(instanttensor_tensor.eq(hf_safetensors_tensors[name])) if __name__ == "__main__":