From be3b77b06d5252faf1926c38ad5e0905871d97be Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 2 Apr 2024 17:32:06 +0200 Subject: [PATCH 1/3] Fix SafeTensorsInfo initialization --- src/huggingface_hub/hf_api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 91f909d15e..4d71d61a23 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -285,6 +285,7 @@ def __post_init__(self): # hack to make TransformersInfo backward compatible class SafeTensorsInfo(dict): parameters: List[Dict[str, int]] total: int + sharded: bool def __post_init__(self): # hack to make SafeTensorsInfo backward compatible self.update(asdict(self)) @@ -707,7 +708,15 @@ def __init__(self, **kwargs): ) self.spaces = kwargs.pop("spaces", None) safetensors = kwargs.pop("safetensors", None) - self.safetensors = SafeTensorsInfo(**safetensors) if safetensors else None + self.safetensors = ( + SafeTensorsInfo( + parameters=safetensors["parameters"], + total=safetensors["total"], + sharded=safetensors["sharded"], + ) + if safetensors + else None + ) # backwards compatibility self.lastModified = self.last_modified From f358cb76db06c86bf4283b8fcaef453b7d24ad65 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 2 Apr 2024 17:55:36 +0200 Subject: [PATCH 2/3] optional --- src/huggingface_hub/hf_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 4d71d61a23..5e1e5640c9 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -285,7 +285,7 @@ def __post_init__(self): # hack to make TransformersInfo backward compatible class SafeTensorsInfo(dict): parameters: List[Dict[str, int]] total: int - sharded: bool + sharded: Optional[bool] = None def __post_init__(self): # hack to make SafeTensorsInfo backward compatible self.update(asdict(self)) @@ -712,7 +712,7 @@ def __init__(self, **kwargs): SafeTensorsInfo( parameters=safetensors["parameters"], total=safetensors["total"], - sharded=safetensors["sharded"], + sharded=safetensors.get("sharded"), ) if safetensors else None From 734c8a0ea67f907b08a436e0ce611de438cdfc9c Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 2 Apr 2024 18:15:57 +0200 Subject: [PATCH 3/3] remove sharded --- src/huggingface_hub/hf_api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 5e1e5640c9..76b35d841c 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -285,7 +285,6 @@ def __post_init__(self): # hack to make TransformersInfo backward compatible class SafeTensorsInfo(dict): parameters: List[Dict[str, int]] total: int - sharded: Optional[bool] = None def __post_init__(self): # hack to make SafeTensorsInfo backward compatible self.update(asdict(self)) @@ -712,7 +711,6 @@ def __init__(self, **kwargs): SafeTensorsInfo( parameters=safetensors["parameters"], total=safetensors["total"], - sharded=safetensors.get("sharded"), ) if safetensors else None