]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Add a safety warning in the convertion script. (#219)
authorNicolas Patry <patry.nicolas@protonmail.com>
Wed, 29 Mar 2023 08:57:32 +0000 (10:57 +0200)
committerGitHub <noreply@github.com>
Wed, 29 Mar 2023 08:57:32 +0000 (10:57 +0200)
* Add a safety warning in the convertion script.

* Fix test temporarily.

bindings/python/convert.py

index 66f89df92891d66516140e5c3fbe29b082c5fead..5903cc96b409459126d95323805c7b045d53beeb 100644 (file)
@@ -300,7 +300,23 @@ if __name__ == "__main__":
         action="store_true",
         help="Create the PR even if it already exists of if the model was already converted.",
     )
+    parser.add_argument(
+        "-y",
+        action="store_true",
+        help="Ignore safety prompt",
+    )
     args = parser.parse_args()
     model_id = args.model_id
     api = HfApi()
-    convert(api, model_id, force=args.force)
+    if args.y:
+        txt = "y"
+    else:
+        txt = input(
+            "This conversion script will unpickle a pickled file, which is inherently unsafe. If you do not trust this file, we invite you to use"
+            " https://huggingface.co/spaces/safetensors/convert or google colab or other hosted solution to avoid potential issues with this file."
+            " Continue [Y/n] ?"
+        )
+    if txt.lower() in {"", "y"}:
+        convert(api, model_id, force=args.force)
+    else:
+        print(f"Answer was `{txt}` aborting.")