From 4b06c063a5259f50ec4c3cdde621857ea125fa97 Mon Sep 17 00:00:00 2001 From: nlml Date: Wed, 23 Jan 2019 16:02:55 -0800 Subject: [PATCH] raise exception if try jit.load non-existent file (#16270) 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torch/jit/__init__.py b/torch/jit/__init__.py index 317fe7e..71e3f11 100644 --- a/torch/jit/__init__.py +++ b/torch/jit/__init__.py @@ -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 -- 2.7.4