raise exception if try jit.load non-existent file (#16270)
authornlml <liamsch@gmail.com>
Thu, 24 Jan 2019 00:02:55 +0000 (16:02 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 24 Jan 2019 00:16:18 +0000 (16:16 -0800)
Summary:
addresses https://github.com/pytorch/pytorch/issues/16267
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16270

Differential Revision: D13791773

Pulled By: suo

fbshipit-source-id: 256304a02dbf724a7c0baade48c94b3ee77f53cf

torch/jit/__init__.py

index 317fe7e..71e3f11 100644 (file)
@@ -115,7 +115,9 @@ def load(f, map_location=None):
                 setattr(curr, name, ScriptModule())
             curr = getattr(curr, name)
         return curr
-
+    if isinstance(f, string_classes):
+        if not os.path.exists(f):
+            raise ValueError("The provided filename {} does not exist".format(f))
     if isinstance(map_location, string_classes):
         map_location = torch.device(map_location)
     elif not (map_location is None or