Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import huggingface_hub.constants
import torch
from safetensors.torch import save_file

from vllm.model_executor.model_loader.weight_utils import (
download_weights_from_hf,
Expand All @@ -14,6 +15,27 @@
)


def test_runai_safetensors_weights_iterator_clones_reused_buffers(
tmp_path, monkeypatch
):
monkeypatch.setenv("RUNAI_STREAMER_MEMORY_LIMIT", "0")
weights_file = tmp_path / "model.safetensors"
expected_tensors = {
"first": torch.tensor([1.0, 2.0]),
"second": torch.tensor([3.0, 4.0]),
}
save_file(expected_tensors, weights_file)

actual_tensors = dict(
runai_safetensors_weights_iterator([str(weights_file)], False)
)

assert actual_tensors.keys() == expected_tensors.keys()
assert actual_tensors["first"].data_ptr() != actual_tensors["second"].data_ptr()
for name, expected_tensor in expected_tensors.items():
assert torch.equal(actual_tensors[name], expected_tensor)


def test_runai_model_loader():
with tempfile.TemporaryDirectory() as tmpdir:
huggingface_hub.constants.HF_HUB_OFFLINE = False
Expand Down
3 changes: 2 additions & 1 deletion vllm/model_executor/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,8 @@ def runai_safetensors_weights_iterator(
mininterval=2,
)

yield from tensor_iter
for name, tensor in tensor_iter:
yield name, tensor.clone()


def _init_fastsafetensors_loader(
Expand Down
Loading