From: Edward Yang Date: Thu, 20 Dec 2018 18:00:09 +0000 (-0800) Subject: Revert D13498974: [pytorch][PR] [jit] Add self to Python printer reserved words X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~2149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5c66662e58c5b87b3f39913bde056d5ecfd4e58e;p=platform%2Fupstream%2Fpytorch.git Revert D13498974: [pytorch][PR] [jit] Add self to Python printer reserved words Differential Revision: D13498974 Original commit changeset: 488efb661476 fbshipit-source-id: 3b991bccf4cf2ffdafe70f145aff0ae2837e31f8 --- diff --git a/test/onnx/expect/TestOperators.test_norm.expect b/test/onnx/expect/TestOperators.test_norm.expect index 56e57e3..ec9a7e6 100644 --- a/test/onnx/expect/TestOperators.test_norm.expect +++ b/test/onnx/expect/TestOperators.test_norm.expect @@ -3,7 +3,7 @@ producer_name: "pytorch" producer_version: "0.4" graph { node { - input: "0" + input: "self" output: "1" op_type: "ReduceL2" attribute { @@ -19,7 +19,7 @@ graph { } name: "torch-jit-export" input { - name: "0" + name: "self" type { tensor_type { elem_type: 1 diff --git a/torch/csrc/jit/passes/python_print.cpp b/torch/csrc/jit/passes/python_print.cpp index cdb8752..27e7594 100644 --- a/torch/csrc/jit/passes/python_print.cpp +++ b/torch/csrc/jit/passes/python_print.cpp @@ -142,22 +142,22 @@ void createTensorToParameterNameMap( // they are keywords or namespaces used in the output const static std::unordered_set reserved_names = { // identifiers in the environment while parsing - "_", // avoid the confusing unnamed _ "aten", - "attribute", + "ops", "CONSTANTS", "fork", + "attribute", "getattr", + "_", // avoid the confusing unnamed _ "inf", "nan", - "ops", - "self", // the python keywords + "False", + "None", + "True", "and", "as", "assert", - "async", - "await", "break", "class", "continue", @@ -166,7 +166,6 @@ void createTensorToParameterNameMap( "elif", "else", "except", - "False", "finally", "for", "from", @@ -176,14 +175,12 @@ void createTensorToParameterNameMap( "in", "is", "lambda", - "None", "nonlocal", "not", "or", "pass", "raise", "return", - "True", "try", "while", "with", diff --git a/torch/jit/__init__.py b/torch/jit/__init__.py index a59c980..fe90ab1 100644 --- a/torch/jit/__init__.py +++ b/torch/jit/__init__.py @@ -223,10 +223,10 @@ def _create_interpreter_name_lookup_fn(frames_up=1): for k, v in f_locals.items(): if isinstance(v, torch.Tensor) and var is v: - return k if k != 'self' else '' + return k for k, v in f_globals.items(): if isinstance(v, torch.Tensor) and var is v: - return k if k != 'self' else '' + return k return '' return _get_interpreter_name_for_var