]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Supporting stable-diffusion by default. (#118)
authorNicolas Patry <patry.nicolas@protonmail.com>
Wed, 30 Nov 2022 16:01:55 +0000 (17:01 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2022 16:01:55 +0000 (17:01 +0100)
* New updates.

* Force load checkpoint on cpu.

bindings/python/convert.py

index e2965c47cdb69f2fcc9c69c1f1e08bae797c5d03..a44593ae3b677bce360650271f8e883fa4005097 100644 (file)
@@ -71,7 +71,7 @@ def convert_multi(model_id: str, folder: str) -> List["CommitOperationAdd"]:
         newdata = {k: v for k, v in data.items()}
         newmap = {k: rename(v) for k, v in data["weight_map"].items()}
         newdata["weight_map"] = newmap
-        json.dump(newdata, f)
+        json.dump(newdata, f, indent=4)
     local_filenames.append(index)
 
     operations = [
@@ -95,7 +95,7 @@ def convert_file(
     pt_filename: str,
     sf_filename: str,
 ):
-    loaded = torch.load(pt_filename)
+    loaded = torch.load(pt_filename, map_location="cpu")
     if "state_dict" in loaded:
         loaded = loaded["state_dict"]
     shared = shared_pointers(loaded)
@@ -227,13 +227,15 @@ def convert(api: "HfApi", model_id: str, force: bool = False) -> Optional["Commi
         try:
             operations = None
             pr = previous_pr(api, model_id, pr_title)
+
+            library_name = getattr(info, "library_name", None)
             if any(filename.endswith(".safetensors") for filename in filenames) and not force:
                 raise AlreadyExists(f"Model {model_id} is already converted, skipping..")
             elif pr is not None and not force:
                 url = f"https://huggingface.co/{model_id}/discussions/{pr.num}"
                 new_pr = pr
                 raise AlreadyExists(f"Model {model_id} already has an open PR check out {url}")
-            elif info.library_name == "transformers":
+            elif library_name == "transformers":
                 if "pytorch_model.bin" in filenames:
                     operations = convert_single(model_id, folder)
                 elif "pytorch_model.bin.index.json" in filenames: