From: Nicolas Patry Date: Wed, 30 Nov 2022 16:01:55 +0000 (+0100) Subject: Supporting stable-diffusion by default. (#118) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fd18f427c006e346f4b8e4332e8a2f0e4a6b1fa3;p=safetensors.git Supporting stable-diffusion by default. (#118) * New updates. * Force load checkpoint on cpu. --- diff --git a/bindings/python/convert.py b/bindings/python/convert.py index e2965c4..a44593a 100644 --- a/bindings/python/convert.py +++ b/bindings/python/convert.py @@ -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: