[Bugfix][Quant] Read safetensors headers of checkpoints with other file names (#60411)
Signed-off-by: Stefan Koncarevic <Stefan.Koncarevic@amd.com> Co-authored-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
co-authored by
Andreas Karatzas
parent
ee406adf0c
commit
814301b268
@@ -241,6 +241,7 @@ def test_safetensors_metadata_of_repo_without_safetensors():
|
||||
)
|
||||
api = SimpleNamespace(
|
||||
get_safetensors_metadata=get_safetensors_metadata,
|
||||
list_repo_files=MagicMock(return_value=["pytorch_model.bin"]),
|
||||
snapshot_download=MagicMock(side_effect=LocalEntryNotFoundError("no cache")),
|
||||
)
|
||||
|
||||
@@ -250,6 +251,34 @@ def test_safetensors_metadata_of_repo_without_safetensors():
|
||||
get_safetensors_metadata.assert_called_once()
|
||||
|
||||
|
||||
def test_safetensors_metadata_of_repo_with_a_nonstandard_file_name():
|
||||
"""`get_safetensors_metadata` only knows `model.safetensors` and its index,
|
||||
so older checkpoints are read through the file listing instead."""
|
||||
from huggingface_hub.errors import NotASafetensorsRepoError
|
||||
from huggingface_hub.utils import TensorInfo
|
||||
|
||||
weights = "gptq_model-4bit-128g.safetensors"
|
||||
tensor = TensorInfo(dtype="I32", shape=[5632], data_offsets=(0, 22528))
|
||||
parse_safetensors_file_metadata = MagicMock(
|
||||
return_value=SimpleNamespace(tensors={"layers.0.mlp.down_proj.qweight": tensor})
|
||||
)
|
||||
api = SimpleNamespace(
|
||||
get_safetensors_metadata=MagicMock(
|
||||
side_effect=NotASafetensorsRepoError("not a safetensors repo")
|
||||
),
|
||||
list_repo_files=MagicMock(return_value=["config.json", weights]),
|
||||
parse_safetensors_file_metadata=parse_safetensors_file_metadata,
|
||||
)
|
||||
|
||||
with patch.object(config_module, "hf_api", lambda: api):
|
||||
metadata = get_safetensors_params_metadata("some/old-gptq-model")
|
||||
|
||||
assert metadata["layers.0.mlp.down_proj.qweight"]["dtype"] == "I32"
|
||||
parse_safetensors_file_metadata.assert_called_once_with(
|
||||
"some/old-gptq-model", weights, revision=None
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("section_key", "mrope_section", "expected_num_dims"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user